-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.in
58 lines (47 loc) · 2.38 KB
/
grammar.in
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<_> ::= <program>
<assignop> ::= = | *= | /= | += | -=
<relop> ::= < | > | == | != | >= | <=
<sumop> ::= + | -
<mulop> ::= * | / | %
<unaryop> ::= - | *
<program> ::= <declList>
<declList> ::= <declList> <decl> | <decl>
<decl> ::= <varDecl> | <funDecl>
<typeSpec> ::= bool | char | int
<varDecl> ::= <typeSpec> <varDeclList> ;
<scopedVarDecl> ::= <typeSpec> <varDeclList> ;
<varDeclList> ::= <varDeclList> , <varDeclInit> | <varDeclInit>
<varDeclInit> ::= <varDeclId> | <varDeclId> = <simpleExp>
<varDeclId> ::= ID | ID [ NUMCONST ]
<funDecl> ::= <funHead> <compoundStmt>
<funHead> ::= <typeSpec> ID ( <parms> )
<parms> ::= <parmList> | EMPTY
<parmList> ::= <parmList> ; <parmTypeList> | <parmTypeList>
<parmTypeList> ::= <typeSpec> <parmIdList>
<parmIdList> ::= <parmIdList> , <parmId> | <parmId>
<parmId> ::= ID | ID [ ]
<stmtList> ::= <stmtList> <stmt> | EMPTY
<stmt> ::= <expStmt> | <compoundStmt> | <selectStmt> | <iterStmt> | <returnStmt> | <breakStmt>
<expStmt> ::= <exp> ; | ;
<compoundStmt> ::= { <localDecls> <stmtList> }
<localDecls> ::= <localDecls> <scopedVarDecl> | EMPTY
<selectStmt> ::= if ( <simpleExp> ) <stmt> | if ( <simpleExp> ) <stmt> <else> <stmt>
<else> ::= else
<iterStmt> ::= while ( <simpleExp> ) <stmt>
<returnStmt> ::= return ; | return <exp> ;
<breakStmt> ::= break ;
<exp> ::= <mutable> = <exp> | <simpleExp>
<simpleExp> ::= <simpleExp> or <andExp> | <andExp>
<andExp> ::= <andExp> and <unaryRelExp> | <unaryRelExp>
<unaryRelExp> ::= not <unaryRelExp> | <relExp>
<relExp> ::= <sumExp> <relop> <sumExp> | <sumExp>
<sumExp> ::= <sumExp> <sumop> <mulExp> | <mulExp>
<mulExp> ::= <mulExp> <mulop> <unaryExp> | <unaryExp>
<unaryExp> ::= <unaryop> <unaryExp> | <factor>
<factor> ::= <mutable> | <immutable>
<mutable> ::= ID | ID [ <exp> ]
<immutable> ::= ( <exp> ) | <call> | <constant>
<call> ::= ID ( <args> )
<args> ::= <argList> | EMPTY
<argList> ::= <argList> , <exp> | <exp>
<constant> ::= NUMCONST | CHARCONST | STRINGCONST | true | false