-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrent_bnf
37 lines (34 loc) · 2.05 KB
/
current_bnf
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
<program> := <func>*
<func> := "int" "*"* <ident> ("(" ("int" "*"* <ident> ("," "int" "*"* <ident>)*)? ")")? <stmt>
<stmt> := <expr> ";"
| "{" <stmt>* "}"
| "if" "(" <expr> ")" <stmt> ("else" <stmt>)?
| "while" "(" <expr> ")" <stmt>
| "for" "(" <expr>? ";" <expr>? ";" <expr>? ")" <stmt>
| "return" <expr> ";"
| <declaration> ";"
<declaration> := <declaration-specifiers> <init-declarator>*
<declaration-specifiers> := <type-specifiers>
<type-specifiers> := "int"
<init-declarator> := <declarator>
<declarator> := <pointer>? <direct-declarator>
<direct-declarator> := <identifier>
| <identifier> "[" <assign> "]"
<pointer> := "*" <pointer>
<expr> := <assign>
<assign> := <equality> ("=" <assign>)?
<equality> := <relational> ("==" <relational> | "!=" <relational>)*
<relational> := <add> ("<" <add> | "<=" <add> | ">" <add> | ">=" <add>)*
<add> := <mul> ("+" <mul> | "-" <mul>)*
<mul> := <unary> ("*" <unary> | "/" <unary> | "%" <unary>)*
<unary> := <postfix>
|"sizeof" <unary>
| "+" <unary>
| "-" <unary>
| "*" <unary>
| "&" <unary>
<postfix> := <primary>
| <primary> "[" <expr> "]"
<primary> := <num>
| <ident> ("(" (<expr> ("," <expr>)*)? ")")?
| "(" <expr> ")"