-
Notifications
You must be signed in to change notification settings - Fork 10
/
MiniC.cf
188 lines (143 loc) · 3.68 KB
/
MiniC.cf
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
comment "//" ;
comment "/*" "*/" ;
token TIdent {"int"} | {"char"} | {"double"};
PPrg. Prg ::= [Def] ;
Dec. Dec ::= QTyp Ident [Arr] ;
separator Dec "," ;
DDef. Def ::= Dec "(" [Dec] ")" "{" [Stm] "}" ;
DSig. Def ::= Dec "(" [Dec] ")" ";" ;
DDec. Def ::= Dec ";" ;
separator Def "" ;
TName. Typ ::= TIdent ;
TStr. Typ ::= "struct" "{" [Fld] "}" ;
TUni. Typ ::= "union" "{" [Fld] "}" ;
TEnum. Typ ::= "enum" "{" [Enm] "}" ;
TVoid. Typ ::= "void" ;
TPtr. Typ ::= Typ "*" ;
separator Typ "," ;
EEnm. Enm ::= Ident ;
ECst. Enm ::= Ident "=" Exp2 ;
separator Enm "," ;
FFld. Fld ::= Typ Ident [Arr] ;
terminator Fld ";" ;
AArr. Arr ::= "[" Exp "]" ;
separator Arr "" ;
QTyp. QTyp ::= Qual Typ ;
NoQual. Qual ::= ;
QConst. Qual ::= "const" ;
SDec. Stm ::= Dec Init ;
SPut. Stm ::= LVal "=" Exp ;
SFor. Stm ::= "for" "(" Stm ";" Exp ";" Stm ")" "{" [Stm] "}" ;
SSwi. Stm ::= "switch" "(" Exp ")" "{" [Branch] "}" ;
Case. Branch ::= "case" Exp2 ":" [Stm] "break" ";" ;
terminator Branch "" ;
NoInit. Init ::= ;
SoInit. Init ::= "=" Exp ;
terminator Stm ";" ;
LInteger. Literal ::= Integer ;
LDouble. Literal ::= Double ;
LString. Literal ::= String ;
LChar. Literal ::= Char ;
-- primary-expression
EVar. Exp16 ::= Ident ;
ELit. Exp16 ::= Literal ;
EParen. Exp16 ::= "(" Exp ")" ;
-- postfix-expression
EArw. Exp15 ::= Exp15 "->" Ident ;
EFld. Exp15 ::= Exp15 "." Ident ;
EArr. Exp15 ::= Exp15 "[" Exp "]" ;
EApp. Exp15 ::= Exp15 "(" [Exp] ")" ;
_. Exp15 ::= Exp16 ;
-- unary-operator
UAmp. UOp ::= "&" ;
UPtr. UOp ::= "*" ;
UPlus. UOp ::= "+" ;
UMinus. UOp ::= "-" ;
UTilde. UOp ::= "~" ;
UBang. UOp ::= "!" ;
-- unary-expression
_. Exp14 ::= Exp15 ;
-- Incr. Exp14 ::= "++" Exp14 ;
-- Decr. Exp14 ::= "--" Exp14 ;
UOp. Exp14 ::= UOp Exp13 ;
-- Sizeof. Exp14 ::= "sizeof" Exp14 ;
-- SizeofTyp. Exp14 ::= "sizeof" "(" type-name ")" ;
-- cast-expression
_. Exp13 ::= Exp14 ;
-- Cast. Exp13 ::= "(" type-name ")" Exp13 ;
-- multiplicative-expression
_. Exp12 ::= Exp13 ;
Mul. Exp12 ::= Exp12 "*" Exp13 ;
Div. Exp12 ::= Exp12 "/" Exp13 ;
Mod. Exp12 ::= Exp12 "%" Exp13 ;
-- additive-expression
_. Exp11 ::= Exp12 ;
Add. Exp11 ::= Exp11 "+" Exp12 ;
Sub. Exp11 ::= Exp11 "-" Exp12 ;
-- shift-expression
_. Exp10 ::= Exp11 ;
Lsl. Exp10 ::= Exp10 "<<" Exp11 ;
Lsr. Exp10 ::= Exp10 ">>" Exp11 ;
-- relational-expression
_. Exp9 ::= Exp10 ;
Lt. Exp9 ::= Exp9 "<" Exp10 ;
Gt. Exp9 ::= Exp9 ">" Exp10 ;
Le. Exp9 ::= Exp9 "<=" Exp10 ;
Ge. Exp9 ::= Exp9 ">=" Exp10 ;
-- equality-expression
_. Exp8 ::= Exp9 ;
Eq. Exp8 ::= Exp8 "==" Exp9 ;
NEq. Exp8 ::= Exp8 "!=" Exp9 ;
-- AND-expression
_. Exp7 ::= Exp8 ;
And. Exp7 ::= Exp7 "&" Exp8 ;
-- exclusive-OR-expression
_. Exp6 ::= Exp7 ;
Xor. Exp6 ::= Exp6 "^" Exp7 ;
-- inclusive-OR-expression
_. Exp5 ::= Exp6 ;
Ior. Exp5 ::= Exp5 "|" Exp6 ;
-- logical-AND-expression
_. Exp4 ::= Exp5 ;
Land. Exp4 ::= Exp4 "&&" Exp5 ;
-- logical-OR-expression
_. Exp3 ::= Exp4 ;
Lor. Exp3 ::= Exp3 "||" Exp4 ;
-- conditional-expression OR constant-expression
_. Exp2 ::= Exp3 ;
Cond. Exp2 ::= Exp3 "?" Exp ":" Exp2 ;
{-
assignment-expression
conditional-expression
unary-expression assignment-operator assignment-expression
-}
_. Exp1 ::= Exp2 ;
{-
expression
assignment-expression
expression , assignment-expression
-}
_. Exp ::= Exp1 ;
{-
assignment-operator
=
*=
/=
%=
+=
-=
<<=
>>=
&=
^=
|=
-}
separator Exp "," ;
LVar. LVal3 ::= Ident ;
_. LVal3 ::= "(" LVal ")" ;
LArw. LVal2 ::= LVal2 "->" Ident ;
LFld. LVal2 ::= LVal2 "." Ident ;
LArr. LVal2 ::= LVal2 "[" Exp "]" ;
_. LVal2 ::= LVal3 ;
LPtr. LVal ::= "*" LVal2 ;
_. LVal ::= LVal2 ;