-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
executable file
·69 lines (42 loc) · 2.07 KB
/
grammar.txt
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
program : sections
sections : (libraries | functions | execution)*
libraries : LBRACKET (empty | include_library*) RBRACKET
include_library : ARROW ID
functions : LBRACKET (empty | function_implementation*) RBRACKET
function_implementation : MONKEY ID COLON LPAREN parameters_list RPAREN ARROW (type_spec | void) LBRACKET function_body RBRACKET return_statement?
function_body : LBRACKET statement_list RBRACKET
parameters_list : empty
| param (COMMA param)*
param : type_spec variable
execution : LBRACKET statement_list RBRACKET
statement_list : var_declaration
| assignment_statement
| function_call
| condition_statement
| loop_statement
| return_statement
| empty
var_declaration : type_spec var
assignment_statement : variable ASSIGN (expr | bool_expr | function_call | STRING)
function_call : MONKEY ID DOT ID LPAREN (variable | INTEGER | STRING)? (COMMA (variable | INTEGER | STRING))* RPAREN
return_statement : RETURN variable
condition_statement : COND COLON LPAREN (bool_expr | function_call) RPAREN ARROW LBRACKET statement_list RBRACKET
loop_statement : LOOP COLON LPAREN bool_expr RPAREN ARROW LBRACKET statement_list RBRACKET
type_spec : INT | FLOAT | STRING | ARRAY
void : VOID
variable : HASH ID
expr : term ((PLUS | MINUS) term)*
bool : expr ((comparison_operator | (unar_operator? logical_operator)) expr))*
bool_expr : unar_operator? bool
comparison_operator : LT | GT | LE | GE | EQ | NEQ
logical_operator : AND | OR
unar_operator : NOT
term : factor ((MUL | NDIV | DIV | MOD) factor)*
factor : PLUS factor
| MINUS factor
| INTEGER
| INT
| FLOAT
| LPAREN expr RPAREN
| variable
| function_call