Release coccinelle-0.2.3rc2
[bpt/coccinelle.git] / parsing_c / orig.mly
CommitLineData
faf9a90c 1%{
ae4735db
C
2(* src: ocamlyaccified from
3 * http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
faf9a90c
C
4 *)
5open Common
6open AbstractSyntax
7exception Parsing of string
8%}
9
10%token <string * AbstractSyntax.fullType> TString
11%token <string> TIdent
12%token <int * AbstractSyntax.intType> TInt
13%token <float * AbstractSyntax.floatType> TFloat
14
15/*(* conflicts *)*/
16%token <string> TypedefIdent
17
ae4735db
C
18%token TOPar TCPar TOBrace TCBrace TOCro TCCro
19%token TDot TComma TPtrOp
faf9a90c 20%token TInc TDec
ae4735db 21%token <AbstractSyntax.assignOp> TAssign
faf9a90c
C
22%token TEq
23%token TWhy TDotDot TPtVirg TTilde TBang
24%token TEllipsis
25
ae4735db
C
26%token TOrLog TAndLog TOrIncl TOrExcl TAnd TEqEq TNotEq TInf TSup TInfEq TSupEq TShl TShr
27 TPlus TMinus TMul TDiv TMod
faf9a90c
C
28
29%token Tchar Tshort Tint Tdouble Tfloat Tlong Tunsigned Tsigned Tvoid
ae4735db 30 Tauto Tregister Textern Tstatic
faf9a90c
C
31 Tconst Tvolatile
32 Tstruct Tenum Ttypedef Tunion
33 Tbreak Telse Tswitch Tcase Tcontinue Tfor Tdo Tif Twhile Treturn Tgoto Tdefault
ae4735db 34 Tsizeof
faf9a90c
C
35
36%token EOF
37
38
39%left TOrLog
40%left TAndLog
41%left TOrIncl
42%left TOrExcl
ae4735db 43%left TAnd
faf9a90c 44%left TEqEq TNotEq
ae4735db 45%left TInf TSup TInfEq TSupEq
faf9a90c
C
46%left TShl TShr
47%left TPlus TMinus
ae4735db 48%left TMul TDiv TMod
faf9a90c
C
49
50%start main
51%type <int list> main
52%%
53
54main: translation_unit EOF { [] }
55
56/********************************************************************************/
57/*
58 expression
59 statement
60 declaration
61 main
62*/
63
64/********************************************************************************/
65
66expr: assign_expr { }
67 | expr TComma assign_expr { }
68
69assign_expr: cond_expr { }
70 | unary_expr TAssign assign_expr { }
71 | unary_expr TEq assign_expr { }
72
73cond_expr: arith_expr {}
74 | arith_expr TWhy expr TDotDot cond_expr {}
75
76arith_expr: cast_expr {}
77 | arith_expr TMul arith_expr {}
78 | arith_expr TDiv arith_expr {}
79 | arith_expr TMod arith_expr {}
80 | arith_expr TPlus arith_expr {}
81 | arith_expr TMinus arith_expr {}
82 | arith_expr TShl arith_expr {}
83 | arith_expr TShr arith_expr {}
84 | arith_expr TInf arith_expr {}
85 | arith_expr TSup arith_expr {}
86 | arith_expr TInfEq arith_expr {}
87 | arith_expr TSupEq arith_expr {}
88 | arith_expr TEqEq arith_expr {}
89 | arith_expr TNotEq arith_expr {}
90 | arith_expr TAnd arith_expr {}
91 | arith_expr TOrExcl arith_expr {}
92 | arith_expr TOrIncl arith_expr {}
93 | arith_expr TAndLog arith_expr {}
94 | arith_expr TOrLog arith_expr {}
95
96cast_expr: unary_expr {}
97 | TOPar type_name TCPar cast_expr {}
98
99unary_expr: postfix_expr {}
100 | TInc unary_expr {}
101 | TDec unary_expr {}
102 | unary_op cast_expr {}
103 | Tsizeof unary_expr {}
104 | Tsizeof TOPar type_name TCPar {}
105
106unary_op: TAnd {}
107 | TMul {}
108 | TPlus {}
109 | TMinus{}
110 | TTilde{}
111 | TBang {}
112
113postfix_expr: primary_expr {}
114 | postfix_expr TOCro expr TCCro {}
115 | postfix_expr TOPar argument_expr_list TCPar {}
116 | postfix_expr TOPar TCPar {}
117 | postfix_expr TDot TIdent {}
118 | postfix_expr TPtrOp TIdent {}
119 | postfix_expr TInc {}
120 | postfix_expr TDec {}
121
122argument_expr_list: assign_expr { }
123 | argument_expr_list TComma assign_expr {}
124
125primary_expr: TIdent {}
126 | TInt {}
127 | TFloat {}
128 | TString {}
129 | TOPar expr TCPar {}
130
131const_expr: cond_expr {}
132/********************************************************************************/
133
134statement: labeled {}
135 | compound {}
136 | expr_statement {}
137 | selection {}
138 | iteration {}
139 | jump TPtVirg {}
140
141labeled: TIdent TDotDot statement {}
142 | Tcase const_expr TDotDot statement {}
143 | Tdefault TDotDot statement {}
144
145compound: TOBrace TCBrace {}
146 | TOBrace statement_list TCBrace {}
147 | TOBrace decl_list TCBrace {}
148 | TOBrace decl_list statement_list TCBrace {}
149
150decl_list: decl {}
151 | decl decl_list {}
152
153statement_list: statement {}
154 | statement statement_list {}
155
156expr_statement: TPtVirg {}
157 | expr TPtVirg {}
158
159selection: Tif TOPar expr TCPar statement {}
160 | Tif TOPar expr TCPar statement Telse statement {}
161 | Tswitch TOPar expr TCPar statement {}
162
163iteration: Twhile TOPar expr TCPar statement {}
164 | Tdo statement Twhile TOPar expr TCPar TPtVirg {}
165 | Tfor TOPar expr_statement expr_statement TCPar statement {}
166 | Tfor TOPar expr_statement expr_statement expr TCPar statement {}
167
ae4735db 168jump: Tgoto TIdent {}
faf9a90c
C
169 | Tcontinue {}
170 | Tbreak {}
ae4735db 171 | Treturn {}
faf9a90c
C
172 | Treturn expr {}
173
174/********************************************************************************/
175
176/*------------------------------------------------------------------------------*/
177decl: decl_spec TPtVirg {}
178 | decl_spec init_declarator_list TPtVirg {}
179
180/*------------------------------------------------------------------------------*/
181decl_spec: storage_class_spec {}
182 | storage_class_spec decl_spec {}
183 | type_spec {}
184 | type_spec decl_spec {}
185 | type_qualif {}
186 | type_qualif decl_spec {}
187
188storage_class_spec: Tstatic {}
189 | Textern {}
190 | Tauto {}
191 | Tregister {}
192 | Ttypedef {}
193type_spec: Tvoid {}
194 | Tchar {}
195 | Tshort {}
196 | Tint {}
197 | Tlong {}
198 | Tfloat {}
199 | Tdouble {}
200 | Tsigned {}
201 | Tunsigned {}
202 | struct_or_union_spec {}
203 | enum_spec {}
204/*TODO | TIdent {} */
ae4735db 205 | TypedefIdent {}
faf9a90c
C
206
207type_qualif: Tconst {}
208 | Tvolatile {}
209
210/*------------------------------------------------------------------------------*/
211struct_or_union_spec: struct_or_union TIdent TOBrace struct_decl_list TCBrace {}
212 | struct_or_union TOBrace struct_decl_list TCBrace {}
213 | struct_or_union TIdent {}
214
215struct_or_union: Tstruct {}
216 | Tunion {}
217
218struct_decl_list: struct_decl {}
219 | struct_decl_list struct_decl {}
220
221struct_decl: spec_qualif_list struct_declarator_list TPtVirg {}
222
223spec_qualif_list: type_spec {}
224 | type_spec spec_qualif_list {}
225 | type_qualif {}
226 | type_qualif spec_qualif_list {}
227
228struct_declarator_list: struct_declarator {}
229 | struct_declarator_list TComma struct_declarator {}
230struct_declarator: declarator {}
231 | TDotDot const_expr {}
232 | declarator TDotDot const_expr {}
233/*------------------------------------------------------------------------------*/
234enum_spec: Tenum TOBrace enumerator_list TCBrace {}
235 | Tenum TIdent TOBrace enumerator_list TCBrace {}
236 | Tenum TIdent {}
237
238enumerator_list: enumerator {}
239 | enumerator_list TComma enumerator {}
240
241enumerator: TIdent {}
242 | TIdent TEq const_expr {}
243/*------------------------------------------------------------------------------*/
ae4735db 244
faf9a90c
C
245init_declarator_list: init_declarator {}
246 | init_declarator_list TComma init_declarator {}
247
248init_declarator: declarator {}
249 | declarator TEq initialize {}
250
251/*------------------------------------------------------------------------------*/
252declarator: pointer direct_declarator {}
253 | direct_declarator {}
254
255pointer: TMul {}
256 | TMul type_qualif_list {}
257 | TMul pointer {}
258 | TMul type_qualif_list pointer {}
259
260direct_declarator: TIdent {}
261 | TOPar declarator TCPar {}
262 | direct_declarator TOCro const_expr TCCro {}
263 | direct_declarator TOCro TCCro {}
264 | direct_declarator TOPar TCPar {}
265 | direct_declarator TOPar parameter_type_list TCPar {}
266 | direct_declarator TOPar identifier_list TCPar {}
267
268type_qualif_list: type_qualif {}
269 | type_qualif_list type_qualif {}
270
271parameter_type_list: parameter_list {}
272 | parameter_list TComma TEllipsis {}
273
274parameter_list: parameter_decl {}
275 | parameter_list TComma parameter_decl {}
276
277parameter_decl: decl_spec declarator {}
278 | decl_spec abstract_declarator {}
279 | decl_spec {}
280identifier_list: TIdent {}
281 | identifier_list TComma TIdent {}
282/*------------------------------------------------------------------------------*/
283
284type_name: spec_qualif_list {}
285 | spec_qualif_list abstract_declarator {}
286
287abstract_declarator: pointer {}
288 | direct_abstract_declarator {}
289 | pointer direct_abstract_declarator {}
290
291direct_abstract_declarator: TOPar abstract_declarator TCPar {}
292 | TOCro TCCro {}
293 | TOCro const_expr TCCro {}
294 | direct_abstract_declarator TOCro TCCro {}
295 | direct_abstract_declarator TOCro const_expr TCCro {}
296 | TOPar TCPar {}
297 | TOPar parameter_type_list TCPar {}
298 | direct_abstract_declarator TOPar TCPar {}
299 | direct_abstract_declarator TOPar parameter_type_list TCPar {}
ae4735db 300
faf9a90c
C
301/*------------------------------------------------------------------------------*/
302initialize: assign_expr {}
303 | TOBrace initialize_list TCBrace {}
304 | TOBrace initialize_list TComma TCBrace {}
305
306initialize_list: initialize {}
307 | initialize_list TComma initialize {}
308
309/********************************************************************************/
310
311translation_unit: external_declaration {}
312 | translation_unit external_declaration {}
313
314external_declaration: function_definition {}
315 | decl {}
316
317function_definition: decl_spec declarator decl_list compound {}
318 | decl_spec declarator compound {}
319 | declarator decl_list compound {}
320 | declarator compound {}
321
322
323