-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBNF
18 lines (16 loc) · 802 Bytes
/
BNF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<toplevel> ::= <function>*
<function> ::= <type> ' ' <identifier> '(' (<arg> (',' <arg>)*)? ')' <block>
<arg> ::= <type> ' ' <identifier>
<block> ::= '{' (<stmt> ';')* '}'
<stmt> ::= <declr-stmt> | <assign-stmt> | <call-stmt>
<call-stmt> ::= <identifier> '(' (<expr> (',' <expr>)*)? ')'
<declr-stmt> ::= <type> ' ' <identifier> ('=' <expr>)?
<assign-stmt> ::= <identifier> '=' <expr>
<expr> ::= <arith-expr>
<arith-expr> ::= <arith-elm> (<arith-op> <arith-elm>)*
<arith-elm> ::= <num> | <identifier> | '(' <expr> ')'
<arith-op> ::= '+' | '-' | '*' | '/'
<num> ::= 32-bit int
<identifier> ::= a-z | A-Z
<type> ::= 'int'
One data type and one type of expression isn't too complicated, but will keep figuring out codegen more straight forward.