-
Notifications
You must be signed in to change notification settings - Fork 1
/
syntax.txt
38 lines (34 loc) · 1.45 KB
/
syntax.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
<program> := [ <function_decl> ]
<function_decl> := 'fn (' [<variable_val> ':' <type>,] ') {' <stmts> '}'
<stmts> := <stmt> [ <stmts> ]
<stmt> :
= <or-expr> ';'
| <var_decl>
| <assign>
| <return>
| <if_else>
| <for>
<return> := 'return' <or-expr> ';'
<assign> := <variable_val> '=' <or-expr> ';'
<var_decl> := 'var' ID ':' <type> (= <or-expr>)? ';'
<if_else> := if '(' <or-expr> ')' '{' <stmts> '}' [ else '{' <stmts> '}' ]
<for> := 'for' '(' <var_decl> <or-expr> ';' <assign> ')' '{' <stmts> '}'
https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm
<or-expr> := <and-expr> | <or-expr> '||' <and-expr>
<and-expr> := <equality-expr> | <and-expr> '&&' <equality-expr>
<equality-expr> := <relational-expr> | <equality-expr> ('==' | '!=') <relational-expr>
<relational-expr> := <additive-expr> | <relational-expr> ('>' | '<' | '<=' | '>=') <additive-expr>
<additive-expr> := <multiplicative-expr> | <additive-expr> ('+'|'-') <multiplicative-expr>
<multiplicative-expr> := <factor> | <multiplicative-expr> ('*' | '/' | '%') <factor>
<factor> :
= <const_num_val>
| <paren_expr>
| <call>
| <variable_val>
<paren_expr> := '(' <or-expr> ')'
<const_num_val> := 0 | [1-9][0-9]*
<const_bool_val> := 'true' | 'false'
<call> = ID '(' <expr>* ')'
<variable_val> := ID
<type> := unit | int32 | int64 | uint32 | uint64 | bool | String
ID := [a-zA-Z][a-zA-Z0-9]*