-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.ebnf
55 lines (43 loc) · 2.07 KB
/
grammar.ebnf
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
50
51
52
53
54
55
string_primitive = STRING ;
null_primitive = 'null' ;
bool_primitive = 'true' | 'false' ;
decimal_primitive = DIGITS ;
floating_point = DIGITS '.' DIGITS ;
identifier = /[a-zA-Z_][a-zA-Z0-9_]* / ;
source_file = type_declaration* ;
type_declaration = ( 'class' | 'extension' | 'cutscene' | 'component' ) identifier type_block ;
type_block = '{' type_member* '}' ;
type_member = assignment | procedure_declaration ;
expression = binary | unary | primary ;
binary = expression ( '!=' | '==' | '>' | '>=' | '<' | '<=' | '-' | '+' | '/' | '*' ) expression;
unary = ( '!' | '-' ) expression ;
primary = string_primitive
| null_primitive
| bool_primitive
| decimal_primitive
| floating_point
| identifier
| field_access
| procedure_call
| 'self'
| paren_expr ;
paren_expr = '(' expression ')' ;
TODO: rework these rules?
field_access = primary '.' identifier ;
procedure_call = ( field_access | identifier ) argument_list ;
argument_list = '(' expression ( ',' expression )* ')' ;
procedure_decl = 'function' identifier procedure_params procedure_block ;
procedure_params = '(' identifier* ')' ;
procedure_block = '{' statement* '}' ;
assignment = ( field_access | identifier ) ( '=' | '+=' | '-=' | '*=' | '/=' ) expression ';' ;
compound_statement = if_statement | while_statement | for_statement ;
if_statement = 'if' paren_expr block elif_clause* else_clause? ;
elif_clause = 'elif' paren_expr ;
else_clause = 'else' block ;
while_statement = 'while' paren_expr block ;
for_statement = 'for' '(' identifier 'in' expression ')' block ;
simple_statement = ( procedure_call | return_statement | wait_statement ) ';' ;
return_statement = 'return' expression ;
wait_statement = 'wait' expression ;
statement = assignment | compount_statement | simple_statement ;
block = '{' statement* '}' ;