-
Notifications
You must be signed in to change notification settings - Fork 1
/
grammar_static.py
37 lines (30 loc) · 1.24 KB
/
grammar_static.py
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
# similar to grammar.py but for a static typed version of nodots
GRAMMAR = r"""
program : fun_stmt*
declaration : fun_stmt | return_stmt | if_stmt | expression_stmt
fun_stmt : "fn" function "nf"
return_stmt : "return" expression_stmt
if_stmt : "if" "(" expression ")" declaration* "fi"
expression_stmt : expression? ";"
expression : type? identifier "=" expression | equality
equality : comparison ( ( "!=" | "==" ) comparison )*
comparison : term ( ( ">" | ">=" | "<" | "<=" ) term )*
term : factor ( ( "-" | "+" ) factor )*
factor : call ( ( "/" | "*" ) call )*
call : primary ( "(" arguments? ")" )*
primary : NUMBER -> number | identifier
function : identifier "(" parameters? ")" "->" type declaration*
parameters : type identifier ( "," type identifier )*
arguments : expression ( "," expression )*
type : "i32" | "f64"
identifier : CNAME
%import common.ESCAPED_STRING
%import common.LETTER
%import common.DIGIT
%import common.NUMBER
%import common.CNAME
%import common.WS
%ignore WS
%import common.SH_COMMENT
%ignore SH_COMMENT
"""