-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbnf.txt
More file actions
49 lines (40 loc) · 2.16 KB
/
bnf.txt
File metadata and controls
49 lines (40 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<program> ::= (<expression> ";"?)*
<expression> ::= <if_statement>
| <while_statement>
| <for_statement>
| <assignment>
<if_statement> ::= "if" "(" <expression> ")" <expression> ("else" <expression>)?
<while_statement> ::= "while" "(" <expression> ")" <expression>
<for_statement> ::= "for" "(" <identifier> "in" <expression> ")" <expression>
<assignment> ::= <logical_or> ("=" <expression>)?
<logical_or> ::= <logical_and> ("|" <logical_and>)*
<logical_and> ::= <relational> ("&" <relational>)*
<relational> ::= <additive> (( "==" | "!=" | "<" | "<=" | ">" | ">=" ) <additive>)?
<additive> ::= <multiplicative> (( "+" | "-" ) <multiplicative>)*
<multiplicative> ::= <unary> (( "*" | "/" | "%" ) <unary>)*
<unary> ::= ( "!" | "-" ) <unary>
| <postfix>
<postfix> ::= <factor> ( <call_args> | <index_access> | <property_access> )*
<call_args> ::= "(" (<expression> ("," <expression>)* ","?)? ")"
<index_access> ::= "[" <expression> "]"
<property_access> ::= "." <identifier>
<factor> ::= "(" <program> ")"
| "{" <object_literal> "}"
| <list_literal>
| <identifier>
| "return" <expression>?
| "break" <expression>?
| "continue" <expression>?
| <function_definition>
| <number>
| <string>
| <boolean>
| "this"
| "undefined"
<object_literal> ::= (<identifier> ":" <expression> ("," <identifier> ":" <expression>)* ","?)?
<list_literal> ::= "[" (<expression> ("," <expression>)* ","?)? "]"
<function_definition> ::= "function" "(" (<identifier> ("," <identifier>)* ","?)? ")" <expression>
<identifier> ::= [a-zA-Z_][a-zA-Z0-9_]*
<number> ::= [0-9]+
<string> ::= '"' [^"]* '"'
<boolean> ::= "true" | "false"