-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.bnf
29 lines (29 loc) · 1.77 KB
/
grammar.bnf
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
program ::= statements EOF
statements ::= statement statements
statement ::= block_statement | variable_statement | if_statement | expression_statement
block_statement ::= INDENT statements DEDENT
variable_statement ::= LET variable_declaration_list
variable_declaration_list ::= variable_declaration { COMMA variable_declaration }
variable_declaration ::= identifier [ ASSIGN assignment_expression ]
if_statement ::= IF expression THEN statement [ ELSE statement ]
expression_statement ::= expression
expression ::= assignment_expression
grouped_expression ::= LPAREN expression RPAREN
assignment_expression ::= logical_or_expression [ assignment_operator assignment_expression ]
logical_or_expression ::= logical_and_expression { OR logical_and_expression }
logical_and_expression ::= equality_expression { AND equality_expression }
equality_expression ::= relational_expression { (EQ | NOT_EQ) relational_expression }
relational_expression ::= additive_expression { (LT | LT_EQ | GT | GT_EQ) additive_expression }
additive_expression ::= multiplicative_expression { (PLUS | MINUS) multiplicative_expression }
multiplicative_expression ::= primary_expression { (STAR | SLASH | PERCENT) primary_expression }
primary_expression ::= literal | grouped_expression | identifier
literal ::= integer_literal | float_literal | string_literal
integer_literal ::= INT
float_literal ::= FLOAT
string_literal ::= STRING
bool_literal ::= (TRUE | FALSE)
null_literal ::= NIL
identifier ::= IDENT
assignment_operator ::= ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN | STAR_ASSIGN | SLASH_ASSIGN
relational_operator ::= LT | LT_EQ | GT | GT_EQ
equality_operator ::= EQ | NOT_EQ