-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.txt
More file actions
38 lines (27 loc) · 1.3 KB
/
grammar.txt
File metadata and controls
38 lines (27 loc) · 1.3 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
program := {func_def}
statement := var_dec | while_loop | if_stmt | assignment_stmt | return_stmt | call
NOTE: statement must be FOLLOWED BY '\n' or EOF
func_def := ['pub'] 'fn' IDENTIFIER '(' [parameters] ')' [VARTYPE] body
parameters := {VARTYPE IDENTIFIER ','} VARTYPE IDENTIFIER
var_decl := VARTYPE IDENTIFIER '=' expr
while_loop := 'while' condition body
return_stmt := 'ret' expr
if_stmt := 'if' condition body [else_stmt]
else_stmt := 'else' body | 'else' if_stmt
condition := expr
body := '{' [statement]+ '}'
assigment := IDENTIFIER = expr
expr := logical_or
logical_or := {logical_and or} logical_and
logical_and := {eq_neq_expr and} eq_neq_expr
comparison_expr := {add_sub_expr !=,==} add_sub_expr
add_sub_expr := {mul_div_rem_expr (+-)} mul_div_rem_expr
mul_div_rem_expr := {unary_expr (*/%)} unary_expr
unary_expr := unary_op unary_expr | primary_expr
primary_expr := atom | call | '(' expr ')'
^^^^ will become call_and_index_expr
unary_op := '(' VARTYPE ')' | '-'
// call_and_index_expr := IDENTIFIER { [ '(' [args] ')' ] { '[' [index] ']' } }
call := IDENTIFIER [ '(' [args] ')' ]
args := {atom,} atom
atom := IDENTIFIER | INT_LITERAL | STR_LITERAL | true | false