compiler/libec: Added grammar rule for __builtin_offset
[sdk] / compiler / libec / src / type.y
1 %{
2
3 import "ecdefs"
4
5 #define YYSIZE_T size_t
6 #define YYLTYPE Location
7 #include "grammar.h"
8
9 #ifndef YYLLOC_DEFAULT
10 # define YYLLOC_DEFAULT(Current, Rhs, N)         \
11   (Current).start = (Rhs)[1].start;      \
12   (Current).end = (Rhs)[N].end;
13 #endif
14
15 TypeName parsedType;
16
17 #define PRECOMPILER
18
19 #define yyparse type_yyparse
20 #define yylval  type_yylval
21 #define yychar  type_yychar
22 #define yydebug type_yydebug
23 #define yynerrs type_yynerrs
24 #define yylloc  type_yylloc
25
26 extern bool parseTypeError;
27
28 extern File fileInput;
29 extern char * yytext;
30 int yylex();
31 int yyerror();
32
33 #define uint _uint
34 default:
35
36 %}
37
38 %debug
39 %union
40 {
41    int i;
42    SpecifierType specifierType;
43    Identifier id;
44    Expression exp;
45    Specifier specifier;
46    OldList * list;
47    Enumerator enumerator;
48    Declarator declarator;
49    Pointer pointer;
50    Initializer initializer;
51    InitDeclarator initDeclarator;
52    TypeName typeName;
53    Declaration declaration;
54    Statement stmt;
55    FunctionDefinition function;
56    External external;
57    Context context;
58    Attrib attrib;
59    ExtDecl extDecl;
60    Attribute attribute;
61
62    Instantiation instance;
63    MembersInit membersInit;
64    MemberInit memberInit;
65    ClassFunction classFunction;
66    ClassDefinition _class;
67    ClassDef classDef;
68    PropertyDef prop;
69    char * string;
70    Symbol symbol;
71    TemplateParameter templateParameter;
72    TemplateArgument templateArgument;
73    TemplateDatatype templateDatatype;
74 }
75
76 // *** Types ***
77
78 %type <specifierType> struct_or_union
79 %type <i>   unary_operator assignment_operator
80 %type <id>  identifier
81 %type <exp> primary_expression postfix_expression unary_expression cast_expression
82             multiplicative_expression additive_expression shift_expression
83             relational_expression relational_expression_smaller_than equality_expression and_expression
84             exclusive_or_expression inclusive_or_expression logical_and_expression
85             logical_or_expression conditional_expression assignment_expression
86             constant_expression
87             common_unary_expression simple_primary_expression
88             anon_instantiation_expression
89
90 //simple_postfix_expression simple_unary_expression
91
92 %type <list> argument_expression_list expression enumerator_list
93              struct_declarator_list struct_declaration_list
94              declaration_specifiers identifier_list initializer_list init_declarator_list
95              parameter_list parameter_type_list declaration_list statement_list
96              members_initialization_list members_initialization_list_coloned data_member_initialization_list data_member_initialization_list_coloned
97              guess_declaration_specifiers real_guess_declaration_specifiers
98              specifier_qualifier_list guess_specifier_qualifier_list
99              type_qualifier_list property_specifiers
100              renew_specifiers
101              default_property_list
102              template_arguments_list attribs_list
103
104
105 %type <specifier> storage_class_specifier enum_specifier_compound enum_specifier_nocompound type_qualifier type_specifier strict_type_specifier
106                   struct_or_union_specifier_compound struct_or_union_specifier_nocompound guess_type type strict_type
107                   real_guess_type ext_storage base_strict_type
108 %type <enumerator> enumerator
109 %type <declarator> declarator direct_declarator direct_abstract_declarator abstract_declarator
110                    struct_declarator direct_declarator_function direct_declarator_function_start declarator_function direct_declarator_nofunction
111                    direct_abstract_declarator_noarray abstract_declarator_noarray declarator_nofunction
112
113 %type <pointer> pointer
114 %type <initializer> initializer initializer_condition
115 %type <initDeclarator> init_declarator
116 %type <typeName> type_name guess_type_name parameter_declaration
117 %type <stmt> statement labeled_statement compound_statement expression_statement
118              selection_statement iteration_statement jump_statement compound_inside
119
120 %type <declaration> declaration
121 %type <classDef> struct_declaration
122 %type <string> string_literal attribute_word
123 %type <extDecl> ext_decl
124 %type <attrib> attrib
125 %type <attribute> attribute
126
127 %type <instance> instantiation_named instantiation_unnamed guess_instantiation_named instantiation_anon
128 /* %type <membersInit>  members_initialization */
129 %type <memberInit> data_member_initialization default_property
130 %type <classFunction> class_function_definition class_function_definition_start
131                      virtual_class_function_definition_start
132                      constructor_function_definition_start destructor_function_definition_start
133 %type <classFunction> instance_class_function_definition instance_class_function_definition_start
134 %type <prop> property
135
136 %type <templateArgument> template_argument template_type_argument template_expression_argument
137 %type <templateDatatype> template_datatype
138
139 %type <context> compound_start
140
141 %token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF
142 %token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
143 %token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
144 %token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN
145 %token XOR_ASSIGN OR_ASSIGN TYPE_NAME
146
147 %token TYPEDEF EXTERN STATIC AUTO REGISTER
148 %token CHAR SHORT INT UINT INT64 LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID VALIST
149 %token STRUCT UNION ENUM ELLIPSIS
150
151 %token CASE DEFAULT IF SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
152
153 %nonassoc IFX
154 %nonassoc ELSE
155 %token CLASS THISCLASS CLASS_NAME
156 %token PROPERTY SETPROP GETPROP NEWOP RENEW DELETE EXT_DECL EXT_STORAGE IMPORT DEFINE VIRTUAL ATTRIB
157 %token PUBLIC PRIVATE
158 %token TYPED_OBJECT ANY_OBJECT _INCREF EXTENSION ASM TYPEOF
159 %token WATCH STOPWATCHING FIREWATCHERS WATCHABLE CLASS_DESIGNER CLASS_NO_EXPANSION CLASS_FIXED ISPROPSET
160 %token CLASS_DEFAULT_PROPERTY PROPERTY_CATEGORY CLASS_DATA CLASS_PROPERTY SUBCLASS NAMESPACE
161 %token NEW0OP RENEW0 VAARG
162 %token DBTABLE DBFIELD DBINDEX DATABASE_OPEN
163 %token ALIGNOF ATTRIB_DEP __ATTRIB
164 %token BOOL _BOOL _COMPLEX _IMAGINARY RESTRICT THREAD
165 %token WIDE_STRING_LITERAL
166 %token BUILTIN_OFFSETOF
167
168 %destructor { FreeIdentifier($$); } identifier
169 %destructor { FreePointer($$); } pointer
170 %destructor { FreeExpression($$); } primary_expression postfix_expression unary_expression cast_expression
171                                     multiplicative_expression additive_expression shift_expression
172                                     relational_expression equality_expression and_expression
173                                     exclusive_or_expression inclusive_or_expression logical_and_expression
174                                     logical_or_expression conditional_expression assignment_expression
175                                     constant_expression
176 %destructor { FreeSpecifier($$); }  storage_class_specifier enum_specifier_compound enum_specifier_nocompound type_qualifier type_specifier
177                                     struct_or_union_specifier_compound struct_or_union_specifier_nocompound ext_storage type strict_type guess_type strict_type_specifier
178                                     base_strict_type
179 %destructor { FreeEnumerator($$); } enumerator
180 %destructor { FreeDeclarator($$); } declarator direct_declarator direct_abstract_declarator abstract_declarator
181                                     direct_abstract_declarator_noarray abstract_declarator_noarray
182                                     struct_declarator direct_declarator_function direct_declarator_function_start declarator_function direct_declarator_nofunction
183                                     declarator_nofunction
184
185 %destructor { FreeInitializer($$); } initializer initializer_condition
186 %destructor { FreeInitDeclarator($$); } init_declarator
187 %destructor { FreeTypeName($$); } type_name guess_type_name parameter_declaration
188 %destructor { FreeStatement($$); }  statement labeled_statement compound_statement expression_statement
189                                     selection_statement iteration_statement jump_statement compound_inside
190
191 %destructor { FreeDeclaration($$); } declaration
192
193 %destructor { FreeInstance($$); } instantiation_named instantiation_unnamed
194
195 %destructor { FreeMemberInit($$); } data_member_initialization default_property
196
197 %destructor { FreeClassFunction($$); } class_function_definition class_function_definition_start
198                                        virtual_class_function_definition_start
199                                        constructor_function_definition_start destructor_function_definition_start
200                                        instance_class_function_definition instance_class_function_definition_start
201 %destructor { FreeClassDef($$); } struct_declaration
202 %destructor { delete $$; } string_literal attribute_word
203 %destructor { FreeProperty($$); } property
204
205 %destructor { FreeList($$, FreeExpression); }  argument_expression_list expression
206 %destructor { FreeList($$, FreeEnumerator); }  enumerator_list
207 %destructor { FreeList($$, FreeSpecifier); }   type_qualifier_list specifier_qualifier_list declaration_specifiers
208                                                guess_declaration_specifiers guess_specifier_qualifier_list
209 %destructor { FreeList($$, FreeDeclarator); }  struct_declarator_list
210 %destructor { FreeList($$, FreeDeclaration); } declaration_list
211 %destructor { FreeList($$, FreeInitializer); } initializer_list
212 %destructor { FreeList($$, FreeInitDeclarator); } init_declarator_list
213 %destructor { FreeList($$, FreeTypeName); } parameter_list parameter_type_list identifier_list
214 %destructor { FreeList($$, FreeStatement); } statement_list
215 %destructor { FreeList($$, FreeClassDef); } struct_declaration_list
216 %destructor { FreeList($$, FreeMemberInit); } default_property_list data_member_initialization_list data_member_initialization_list_coloned
217 %destructor { FreeList($$, FreeMembersInit); } members_initialization_list members_initialization_list_coloned
218 %destructor { PopContext($$); FreeContext($$); delete $$; } compound_start
219 %destructor { FreeTemplateArgument($$); } template_argument template_type_argument template_expression_argument
220 %destructor { FreeTemplateDataType($$); } template_datatype
221 %destructor { FreeAttrib($$); } attrib
222 %destructor { FreeExtDecl($$); } ext_decl
223 %destructor { FreeAttribute($$); } attribute
224 %destructor { FreeList($$, FreeAttribute); }  attribs_list
225
226 %start type_unit
227
228 %%
229
230 guess_type:
231    identifier '*'
232    {
233       $$ = null;
234       DeclClass($1._class, $1.string);
235       fileInput.Seek(@1.start.pos, start);
236       resetScannerPos(&@1.start);
237       yyclearin;
238
239       FreeIdentifier($1);
240
241       YYPOPSTACK(1);
242       yystate = *yyssp;
243       YY_STACK_PRINT (yyss, yyssp);
244       YYPOPSTACK(1);
245       yystate = *yyssp;
246       YY_STACK_PRINT (yyss, yyssp);
247       goto yysetstate;
248    }
249    | identifier '<'
250    {
251       $$ = null;
252    #ifdef PRECOMPILER
253       _DeclClass($1._class, $1.string);
254
255       FreeIdentifier($1);
256
257       fileInput.Seek(@1.start.pos, start);
258       resetScannerPos(&@1.start);
259       yyclearin;
260
261       YYPOPSTACK(1);
262       yystate = *yyssp;
263       YY_STACK_PRINT (yyss, yyssp);
264       YYPOPSTACK(1);
265       yystate = *yyssp;
266       YY_STACK_PRINT (yyss, yyssp);
267       goto yysetstate;
268    #endif
269    }
270    ;
271
272 real_guess_type:
273    identifier error
274    {
275       DeclClass($1._class, $1.string);
276       fileInput.Seek(@1.start.pos, start);
277       parseTypeError = 0;
278       resetScannerPos(&@1.start);
279       yyclearin;
280       FreeIdentifier($1);
281
282       YYPOPSTACK(1);
283       yystate = *yyssp;
284       YY_STACK_PRINT (yyss, yyssp);
285       YYPOPSTACK(1);
286       yystate = *yyssp;
287       YY_STACK_PRINT (yyss, yyssp);
288       goto yysetstate;
289    }
290 /*   | identifier '<'
291    {
292    #ifdef PRECOMPILER
293       _DeclClass($1._class, $1.string);
294
295       FreeIdentifier($1);
296
297       fileInput.Seek(@1.start.pos, start);
298       resetScannerPos(&@1.start);
299       yyclearin;
300
301       YYPOPSTACK(1);
302       yystate = *yyssp;
303       YY_STACK_PRINT (yyss, yyssp);
304       YYPOPSTACK(1);
305       yystate = *yyssp;
306       YY_STACK_PRINT (yyss, yyssp);
307       goto yysetstate;
308    #endif
309    }
310    ;
311 */
312 type:
313    strict_type       { $$ = $1; }
314    | identifier identifier
315    {
316    #ifdef PRECOMPILER
317       DeclClass($1._class, $1.string);
318       fileInput.Seek(@1.start.pos, start);
319       resetScannerPos(&@1.start);
320       yyclearin;
321
322       FreeIdentifier($1);
323       FreeIdentifier($2);
324
325       YYPOPSTACK(1);
326       yystate = *yyssp;
327       YY_STACK_PRINT (yyss, yyssp);
328       YYPOPSTACK(1);
329       yystate = *yyssp;
330       YY_STACK_PRINT (yyss, yyssp);
331       goto yysetstate;
332    #else
333       Location tmpLoc = yylloc; $$ = $2; yylloc = @1;
334       Compiler_Error($"Not a type: %s\n", $1.string);
335       yylloc = tmpLoc; $2.badID = $1; // FreeIdentifier($1);
336    #endif
337    }
338    ;
339
340 base_strict_type:
341      TYPE_NAME    { $$ = MkSpecifierName(yytext); }
342    ;
343
344 strict_type:
345      base_strict_type
346     | base_strict_type '<' template_arguments_list '>' { $$ = $1; SetClassTemplateArgs($$, $3); $$.loc = @$; }
347     | base_strict_type '<' template_arguments_list RIGHT_OP
348     {
349       $$ = $1;
350       SetClassTemplateArgs($$, $3);
351       $$.loc = @$;
352
353       @4.end.pos--;
354       fileInput.Seek(@4.end.pos, start);
355       resetScannerPos(&@4.end);
356       yyclearin;
357     }
358
359 /*  | identifier '<' template_arguments_list '>'
360       { $$ = MkSpecifierNameArgs($1.string, $3); $$.loc = @$; FreeIdentifier($1); } */
361    ;
362
363 class_function_definition_start:
364      guess_declaration_specifiers declarator_function
365       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
366    | declarator_function
367       { $$ = MkClassFunction(null, null, $1, null); $$.loc = @$; }
368    ;
369
370 constructor_function_definition_start:
371    guess_declaration_specifiers '(' ')'
372       { $$ = MkClassFunction(null, null, null, null); $$.isConstructor = true; $$.loc = @$; FreeList /*FreeSpecifier*/($1, FreeSpecifier); }
373    ;
374
375 destructor_function_definition_start:
376    '~' guess_declaration_specifiers '(' ')'
377       { $$ = MkClassFunction(null, null, null, null); $$.isDestructor = true; $$.loc = @$; FreeList /*FreeSpecifier*/($2, FreeSpecifier); }
378    ;
379
380 virtual_class_function_definition_start:
381      VIRTUAL guess_declaration_specifiers declarator_function
382       { $$ = MkClassFunction($2, null, $3, null); $$.isVirtual = true; $$.loc = @$; }
383    | VIRTUAL declarator_function
384       { $$ = MkClassFunction(null, null, $2, null); $$.isVirtual = true; $$.loc = @$; }
385       ;
386
387 identifier:
388    IDENTIFIER
389       { $$ = MkIdentifier(yytext); $$.loc = @1; }
390    ;
391
392 primary_expression:
393      simple_primary_expression
394         | '(' expression ')'
395       { $$ = MkExpBrackets($2); $$.loc = @$; }
396    ;
397
398 simple_primary_expression:
399           identifier
400       { $$ = MkExpIdentifier($1); $$.loc = @$; }
401    | instantiation_unnamed
402       { $$ = MkExpInstance($1); $$.loc = @$; }
403         | CONSTANT
404       { $$ = MkExpConstant(yytext); $$.loc = @$; }
405    | WIDE_STRING_LITERAL { $$ = MkExpWideString(yytext); $$.loc = @$; }
406         | string_literal
407       { $$ = MkExpString($1); delete $1; $$.loc = @$; }
408    | '$' string_literal     { $$ = MkExpIntlString($2, null); delete $2; $$.loc = @$; }
409    | '$' string_literal '.' string_literal     { $$ = MkExpIntlString($4, $2); delete $2; delete $4; $$.loc = @$; }
410    | '(' ')'
411       { Expression exp = MkExpDummy(); exp.loc.start = @1.end; exp.loc.end = @2.start; $$ = MkExpBrackets(MkListOne(exp)); $$.loc = @$; yyerror(); }
412
413    | NEWOP guess_declaration_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpNew(MkTypeName($2,$3), $5); $$.loc = @$; }
414    | NEWOP guess_declaration_specifiers '[' constant_expression ']' { $$ = MkExpNew(MkTypeName($2,null), $4); $$.loc = @$; }
415    | NEW0OP guess_declaration_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpNew0(MkTypeName($2,$3), $5); $$.loc = @$; }
416    | NEW0OP guess_declaration_specifiers '[' constant_expression ']' { $$ = MkExpNew0(MkTypeName($2,null), $4); $$.loc = @$; }
417    | RENEW constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpRenew($2, MkTypeName($3,$4), $6); $$.loc = @$; }
418    | RENEW constant_expression renew_specifiers '[' constant_expression ']' { $$ = MkExpRenew($2, MkTypeName($3,null), $5); $$.loc = @$; }
419    | RENEW0 constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpRenew0($2, MkTypeName($3,$4), $6); $$.loc = @$; }
420    | RENEW0 constant_expression renew_specifiers '[' constant_expression ']' { $$ = MkExpRenew0($2, MkTypeName($3,null), $5); $$.loc = @$; }
421    | error { $$ = MkExpDummy(); }
422    ;
423
424 postfix_expression:
425           primary_expression
426    | postfix_expression '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
427         | postfix_expression '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
428         | postfix_expression '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; }
429         | postfix_expression '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
430    | postfix_expression identifier
431    {
432       char * constant = $1.type == constantExp ? $1.constant : null;
433       int len = constant ? strlen(constant) : 0;
434       if(constant && constant[len-1] == '.')
435       {
436          constant[len-1] = 0;
437          $$ = MkExpMember($1, $2);
438          $$.loc = @$;
439       }
440       else
441          yyerror();
442    }
443         | postfix_expression PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
444         | postfix_expression INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
445         | postfix_expression DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
446         ;
447
448 anon_instantiation_expression:
449    instantiation_anon            { $$ = MkExpInstance($1); $$.loc = @$; }
450    ;
451
452 /*
453 simple_postfix_expression:
454           simple_primary_expression
455    | simple_postfix_expression '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
456         | simple_postfix_expression '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
457         | simple_postfix_expression '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; }
458         | simple_postfix_expression '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
459    | simple_postfix_expression identifier
460    {
461       char * constant = $1.type == constantExp ? $1.constant : null;
462       int len = constant ? strlen(constant) : 0;
463       if(constant && constant[len-1] == '.')
464       {
465          constant[len-1] = 0;
466          $$ = MkExpMember($1, $2);
467          $$.loc = @$;
468       }
469       else
470          yyerror();
471    }
472         | simple_postfix_expression PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
473         | simple_postfix_expression INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
474         | simple_postfix_expression DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
475         ;
476 */
477 argument_expression_list:
478           assignment_expression          { $$ = MkList(); ListAdd($$, $1); }
479    | anon_instantiation_expression  { $$ = MkList(); ListAdd($$, $1); }
480         | argument_expression_list ',' assignment_expression   { $$ = $1; ListAdd($1, $3);  }
481    | argument_expression_list ',' anon_instantiation_expression   { $$ = $1; ListAdd($1, $3);  }
482         ;
483
484 common_unary_expression:
485           INC_OP unary_expression           { $$ = MkExpOp(null, INC_OP, $2); $$.loc = @$; }
486         | DEC_OP unary_expression           { $$ = MkExpOp(null, DEC_OP, $2); $$.loc = @$; }
487         | unary_operator cast_expression    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
488         //| SIZEOF '(' unary_expression ')'         { $$ = MkExpOp(null, SIZEOF, $3); $$.loc = @$; }
489    | SIZEOF unary_expression          { $$ = MkExpOp(null, SIZEOF, $2); $$.loc = @$; }
490    | SIZEOF '(' guess_type_name ')'          { $$ = MkExpTypeSize($3); $$.loc = @$; }
491         //| ALIGNOF '(' unary_expression ')'         { $$ = MkExpOp(null, ALIGNOF, $3); $$.loc = @$; }
492    | ALIGNOF unary_expression          { $$ = MkExpOp(null, ALIGNOF, $2); $$.loc = @$; }
493    | ALIGNOF '(' guess_type_name ')'          { $$ = MkExpTypeAlign($3); $$.loc = @$; }
494    ;
495
496 unary_expression:
497        common_unary_expression
498           | postfix_expression
499         ;
500 /*
501 simple_unary_expression:
502      common_unary_expression
503         | simple_postfix_expression
504         ;
505 */
506 unary_operator:
507           '&'     { $$ = '&'; }
508         | '*'     { $$ = '*'; }
509         | '+'     { $$ = '+'; }
510         | '-'     { $$ = '-'; }
511         | '~'     { $$ = '~'; }
512         | '!'     { $$ = '!'; }
513    | DELETE  { $$ = DELETE; }
514         ;
515
516 cast_expression:
517      unary_expression
518         | '(' type_name ')' cast_expression    { $$ = MkExpCast($2, $4); $$.loc = @$; }
519         ;
520
521 multiplicative_expression:
522           cast_expression
523         | multiplicative_expression '*' cast_expression { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
524         | multiplicative_expression '/' cast_expression { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
525         | multiplicative_expression '%' cast_expression { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
526         ;
527
528 additive_expression:
529           multiplicative_expression
530         | additive_expression '+' multiplicative_expression  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
531         | additive_expression '-' multiplicative_expression  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
532         ;
533
534 shift_expression:
535           additive_expression
536         | shift_expression LEFT_OP additive_expression  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
537         | shift_expression RIGHT_OP additive_expression { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
538         ;
539
540 relational_expression_smaller_than:
541    relational_expression '<'
542    {
543       $$ = $1;
544       skipErrors = true;
545    }
546    ;
547
548 relational_expression:
549           shift_expression
550         | relational_expression_smaller_than /*relational_expression '<' */ shift_expression    { skipErrors = false; $$ = MkExpOp($1, '<', $2/*$3*/); $$.loc = @$; }
551         | relational_expression '>' shift_expression    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
552         | relational_expression LE_OP shift_expression  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
553         | relational_expression GE_OP shift_expression  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
554         ;
555
556 equality_expression:
557           relational_expression
558         | equality_expression EQ_OP relational_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
559         | equality_expression NE_OP relational_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
560         ;
561
562 and_expression:
563           equality_expression
564         | and_expression '&' equality_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
565         ;
566
567 exclusive_or_expression:
568           and_expression
569         | exclusive_or_expression '^' and_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
570         ;
571
572 inclusive_or_expression:
573           exclusive_or_expression
574         | inclusive_or_expression '|' exclusive_or_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
575         ;
576
577 logical_and_expression:
578           inclusive_or_expression
579         | logical_and_expression AND_OP inclusive_or_expression  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
580         ;
581
582 logical_or_expression:
583           logical_and_expression
584         | logical_or_expression OR_OP logical_and_expression     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
585         ;
586
587 conditional_expression:
588           logical_or_expression
589         | logical_or_expression '?' expression ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
590         ;
591
592 assignment_expression:
593           conditional_expression
594         | unary_expression assignment_operator assignment_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
595         | unary_expression assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
596    ;
597
598 assignment_operator:
599           '='                   { $$ = '='; }
600         | MUL_ASSIGN            { $$ = MUL_ASSIGN; }
601         | DIV_ASSIGN            { $$ = DIV_ASSIGN; }
602         | MOD_ASSIGN            { $$ = MOD_ASSIGN; }
603         | ADD_ASSIGN            { $$ = ADD_ASSIGN; }
604         | SUB_ASSIGN            { $$ = SUB_ASSIGN; }
605         | LEFT_ASSIGN           { $$ = LEFT_ASSIGN; }
606         | RIGHT_ASSIGN          { $$ = RIGHT_ASSIGN; }
607         | AND_ASSIGN            { $$ = AND_ASSIGN; }
608         | XOR_ASSIGN            { $$ = XOR_ASSIGN; }
609         | OR_ASSIGN             { $$ = OR_ASSIGN; }
610         ;
611
612 expression:
613      assignment_expression                 { $$ = MkList(); ListAdd($$, $1); }
614         | expression ',' assignment_expression  { $$ = $1; ListAdd($1, $3); }
615         ;
616
617 constant_expression:
618           conditional_expression
619         ;
620
621 declaration:
622           declaration_specifiers ';'                       { $$ = MkDeclaration($1, null); $$.loc = @$; }
623         | declaration_specifiers init_declarator_list ';'  { $$ = MkDeclaration($1, $2); $$.loc = @$; }
624    | instantiation_named ';'                          { $$ = MkDeclarationInst($1); $$.loc = @$; }
625    | DEFINE identifier '=' constant_expression ';'           { $$ = MkDeclarationDefine($2, $4); $$.loc = @$; }
626         ;
627
628 specifier_qualifier_list:
629      type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
630    | specifier_qualifier_list  type_qualifier            { $$ = $1; ListAdd($1, $2); }
631    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
632    | specifier_qualifier_list  type_specifier            { $$ = $1; ListAdd($1, $2); }
633    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
634         | specifier_qualifier_list enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
635    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
636         | specifier_qualifier_list struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
637    ;
638
639 guess_specifier_qualifier_list:
640      type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
641    | guess_specifier_qualifier_list  type_qualifier            { $$ = $1; ListAdd($1, $2); }
642    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
643    | guess_specifier_qualifier_list  type_specifier            { $$ = $1; ListAdd($1, $2); }
644    | guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
645    | guess_specifier_qualifier_list  guess_type            { $$ = $1; ListAdd($1, $2); }
646    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
647         | guess_specifier_qualifier_list enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
648    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
649         | guess_specifier_qualifier_list struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
650    ;
651
652 declaration_specifiers:
653      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
654    | declaration_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
655    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
656    | declaration_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
657    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
658    | declaration_specifiers  type_specifier            { $$ = $1; ListAdd($1, $2); }
659    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
660         | declaration_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
661    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
662         | declaration_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
663    ;
664
665 guess_declaration_specifiers:
666      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
667    | guess_declaration_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
668    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
669    | guess_declaration_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
670    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
671    | guess_declaration_specifiers  type_specifier            { $$ = $1; ListAdd($1, $2); }
672    | guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
673         | guess_declaration_specifiers guess_type          { $$ = $1; ListAdd($1, $2); }
674    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
675         | guess_declaration_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
676    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
677         | guess_declaration_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
678    ;
679
680 real_guess_declaration_specifiers:
681        guess_declaration_specifiers                          { $$ = $1; }
682      | real_guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
683    ;
684
685 property_specifiers:
686      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
687    | property_specifiers storage_class_specifier     { $$ = $1; ListAdd($1, $2); }
688    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
689    | property_specifiers type_qualifier            { $$ = $1; ListAdd($1, $2); }
690    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
691    | property_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
692    | identifier                        { $$ = MkList(); ListAdd($$, MkSpecifierName($1.string)); FreeIdentifier($1); }
693    | property_specifiers identifier          { ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2); }
694    | identifier '<' template_arguments_list '>'
695       {
696          _DeclClass($1._class, $1.string);
697
698          $$ = MkList();
699          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
700          FreeIdentifier($1);
701       }
702    | property_specifiers identifier '<' template_arguments_list '>'
703       {
704          _DeclClass($2._class, $2.string);
705          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
706          FreeIdentifier($2);
707       }
708    ;
709
710 renew_specifiers:
711      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
712    | renew_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
713    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
714    | renew_specifiers type_qualifier            { $$ = $1; ListAdd($1, $2); }
715    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
716    | renew_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
717    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
718         | renew_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
719    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
720         | renew_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
721    | identifier                        { $$ = MkList(); ListAdd($$, MkSpecifierName($1.string)); FreeIdentifier($1); }
722    | renew_specifiers identifier          { $$ = $1; ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2)}
723    | identifier '<' template_arguments_list '>'
724       {
725          _DeclClass($1._class, $1.string);
726
727          $$ = MkList();
728          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
729          FreeIdentifier($1);
730       }
731    | renew_specifiers identifier '<' template_arguments_list '>'
732       {
733          _DeclClass($2._class, $2.string);
734          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
735          FreeIdentifier($2);
736       }
737    ;
738
739 init_declarator_list:
740           init_declarator                            { $$ = MkList(); ListAdd($$, $1); }
741         | init_declarator_list ',' init_declarator   { $$ = $1; ListAdd($1, $3); }
742         ;
743
744 init_declarator:
745           declarator                        { $$ = MkInitDeclarator($1, null); $$.loc = @$; }
746         | declarator '=' initializer                 { $$ = MkInitDeclarator($1, $3); $$.loc = @$; $$.initializer.loc.start = @2.end; }
747         ;
748
749 storage_class_specifier:
750           TYPEDEF       { $$ = MkSpecifier(TYPEDEF); }
751         | EXTERN        { $$ = MkSpecifier(EXTERN); }
752         | STATIC        { $$ = MkSpecifier(STATIC); }
753         | AUTO          { $$ = MkSpecifier(AUTO); }
754         | REGISTER      { $$ = MkSpecifier(REGISTER); }
755    | THREAD        { $$ = MkSpecifier(THREAD); }
756         ;
757
758 ext_decl:
759      EXT_DECL { $$ = MkExtDeclString(CopyString(yytext)); }
760    | EXT_STORAGE { $$ = MkExtDeclString(CopyString(yytext)); }
761    | attrib { $$ = MkExtDeclAttrib($1); }
762    ;
763
764 _attrib:
765    ATTRIB      { $<i>$ = ATTRIB; }
766  | ATTRIB_DEP  { $<i>$ = ATTRIB_DEP; }
767  | __ATTRIB    { $<i>$ = __ATTRIB; }
768  ;
769
770
771 attribute_word:
772      IDENTIFIER   { $$  = CopyString(yytext); }
773    | TYPE_NAME    { $$  = CopyString(yytext); }
774    | EXT_STORAGE  { $$  = CopyString(yytext); }
775    | EXT_DECL     { $$  = CopyString(yytext); }
776    | CONST        { $$  = CopyString(yytext); }
777    ;
778
779 attribute:
780      attribute_word  { $$ = MkAttribute($1, null); $$.loc = @$; }
781    | attribute_word '(' expression ')'  { $$ = MkAttribute($1, MkExpBrackets($3)); $$.loc = @$; }
782    ;
783
784 attribs_list:
785      attribute { $$ = MkListOne($1); }
786    | attribs_list attribute { ListAdd($1, $2); $$ = $1; }
787    | attribs_list ',' attribute { ListAdd($1, $3); $$ = $1; }
788    ;
789
790 attrib:
791      _attrib '(' '(' attribs_list ')' ')' { $$ = MkAttrib($<i>1, $4); $$.loc = @$; }
792    | _attrib '(' '('              ')' ')'  { $$ = MkAttrib($<i>1, null); $$.loc = @$; }
793    ;
794
795 ext_storage:
796    ext_decl   { $$ = MkSpecifierExtended($1); }
797    ;
798
799 type_qualifier:
800           CONST        { $$ = MkSpecifier(CONST); }
801         | VOLATILE     { $$ = MkSpecifier(VOLATILE); }
802    | ext_storage  { $$ = $1; }
803         ;
804
805
806 type_specifier:
807           VOID            { $$ = MkSpecifier(VOID); }
808         | CHAR            { $$ = MkSpecifier(CHAR); }
809         | SHORT           { $$ = MkSpecifier(SHORT); }
810         | INT             { $$ = MkSpecifier(INT); }
811    | UINT            { $$ = MkSpecifier(UINT); }
812    | INT64           { $$ = MkSpecifier(INT64); }
813    | VALIST          { $$ = MkSpecifier(VALIST); }
814         | LONG            { $$ = MkSpecifier(LONG); }
815         | FLOAT           { $$ = MkSpecifier(FLOAT); }
816         | DOUBLE          { $$ = MkSpecifier(DOUBLE); }
817         | SIGNED          { $$ = MkSpecifier(SIGNED); }
818         | UNSIGNED        { $$ = MkSpecifier(UNSIGNED); }
819    | EXTENSION       { $$ = MkSpecifier(EXTENSION); }
820    | _BOOL           { $$ = MkSpecifier(_BOOL); }
821    | BOOL            { $$ = MkSpecifier(BOOL); }
822         | struct_or_union_specifier_nocompound
823         | enum_specifier_nocompound
824         | type
825    | TYPEOF '(' assignment_expression ')' { $$ = MkSpecifierTypeOf($3); }
826    | SUBCLASS '(' type ')'                { $$ = MkSpecifierSubClass($3); }
827    | SUBCLASS '(' identifier ')'          { _DeclClass($3._class, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
828    | THISCLASS       { $$ = MkSpecifier(THISCLASS); }
829    | TYPED_OBJECT    { $$ = MkSpecifier(TYPED_OBJECT); }
830    | ANY_OBJECT      { $$ = MkSpecifier(ANY_OBJECT); }
831         ;
832
833 strict_type_specifier:
834           VOID            { $$ = MkSpecifier(VOID); }
835         | CHAR            { $$ = MkSpecifier(CHAR); }
836         | SHORT           { $$ = MkSpecifier(SHORT); }
837         | INT             { $$ = MkSpecifier(INT); }
838    | UINT            { $$ = MkSpecifier(UINT); }
839    | INT64           { $$ = MkSpecifier(INT64); }
840    | VALIST          { $$ = MkSpecifier(VALIST); }
841         | LONG            { $$ = MkSpecifier(LONG); }
842         | FLOAT           { $$ = MkSpecifier(FLOAT); }
843         | DOUBLE          { $$ = MkSpecifier(DOUBLE); }
844         | SIGNED          { $$ = MkSpecifier(SIGNED); }
845         | UNSIGNED        { $$ = MkSpecifier(UNSIGNED); }
846    | EXTENSION       { $$ = MkSpecifier(EXTENSION); }
847    | _BOOL           { $$ = MkSpecifier(_BOOL); }
848    | BOOL            { $$ = MkSpecifier(BOOL); }
849         | struct_or_union_specifier_nocompound
850         | enum_specifier_nocompound
851         | strict_type
852    | TYPEOF '(' assignment_expression ')' { $$ = MkSpecifierTypeOf($3); }
853    | SUBCLASS '(' type ')'                { $$ = MkSpecifierSubClass($3); }
854    | SUBCLASS '(' identifier ')'          { _DeclClass($3._class, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
855    | THISCLASS       { $$ = MkSpecifier(THISCLASS); }
856         ;
857
858
859 struct_or_union_specifier_compound:
860           struct_or_union identifier '{' struct_declaration_list '}'   { $$ = MkStructOrUnion($1, $2, $4); if(declMode) DeclClass($2._class, $2.string); }
861         | struct_or_union '{' struct_declaration_list '}'              { $$ = MkStructOrUnion($1, null, $3); }
862    | struct_or_union identifier '{' '}'   { $$ = MkStructOrUnion($1, $2, null); if(declMode) DeclClass($2._class, $2.string); }
863    | struct_or_union '{' '}'              { $$ = MkStructOrUnion($1, null, null); }
864         | struct_or_union base_strict_type '{' struct_declaration_list '}'
865       { $$ = MkStructOrUnion($1, MkIdentifier($2.name), $4); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
866
867         | struct_or_union ext_decl identifier '{' struct_declaration_list '}'   { $$ = MkStructOrUnion($1, $3, $5); $$.extDeclStruct = $2; if(declMode) DeclClass($3._class, $3.string); }
868         | struct_or_union ext_decl '{' struct_declaration_list '}'              { $$ = MkStructOrUnion($1, null, $4); $$.extDeclStruct = $2; }
869    | struct_or_union ext_decl identifier '{' '}'   { $$ = MkStructOrUnion($1, $3, null); $$.extDeclStruct = $2; if(declMode) DeclClass($3._class, $3.string); }
870    | struct_or_union ext_decl '{' '}'              { $$ = MkStructOrUnion($1, null, null); $$.extDeclStruct = $2; }
871         | struct_or_union ext_decl strict_type '{' struct_declaration_list '}'
872       { $$ = MkStructOrUnion($1, MkIdentifier($3.name), $5); $$.extDeclStruct = $2; if(declMode) DeclClass($3.nsSpec, $3.name); FreeSpecifier($3); }
873         ;
874
875 struct_or_union_specifier_nocompound:
876           struct_or_union identifier                                   { $$ = MkStructOrUnion($1, $2, null); if(declMode) DeclClass($2._class, $2.string); }
877         | struct_or_union strict_type
878       { $$ = MkStructOrUnion($1, MkIdentifier($2.name), null); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
879
880         | struct_or_union ext_decl identifier
881       { $$ = MkStructOrUnion($1, $3, null); $$.extDeclStruct = $2;if(declMode) DeclClass($3._class, $3.string); }
882         | struct_or_union ext_decl strict_type
883       { $$ = MkStructOrUnion($1, MkIdentifier($3.name), null); $$.extDeclStruct = $2; if(declMode) DeclClass($3.nsSpec, $3.name); FreeSpecifier($3); }
884         ;
885
886 template_datatype:
887      guess_declaration_specifiers { $$ = MkTemplateDatatype($1, null); }
888    | guess_declaration_specifiers abstract_declarator { $$ = MkTemplateDatatype($1, $2); }
889    /*| identifier { $$ = MkTemplateDatatype(MkListOne(MkSpecifierName($1.string)), null); FreeIdentifier($1); }*/
890    ;
891
892 template_type_argument:
893      guess_declaration_specifiers { $$ = MkTemplateTypeArgument(MkTemplateDatatype($1, null)); }
894    | guess_declaration_specifiers abstract_declarator { $$ = MkTemplateTypeArgument(MkTemplateDatatype($1, $2)); }
895      //template_datatype { $$ = MkTemplateTypeArgument($1); }
896    ;
897
898 /*
899 template_identifier_argument:
900      identifier { $$ = MkTemplateIdentifierArgument($1); }
901    ;
902 */
903
904 template_expression_argument:
905      shift_expression /*constant_expression*/ { $$ = MkTemplateExpressionArgument($1); }
906    ;
907
908 template_argument:
909      template_expression_argument
910    /*| template_identifier_argument*/
911    | template_type_argument
912    | identifier '=' template_expression_argument   { $$ = $3; $$.name = $1; $$.loc = @$; }
913    /*| identifier '=' template_identifier_argument   { $$ = $3; $$.name = $1; $$.loc = @$; }*/
914    | identifier '=' template_type_argument         { $$ = $3; $$.name = $1; $$.loc = @$; }
915    | template_datatype '=' template_expression_argument
916    {
917       $$ = $3;
918       if($1.specifiers && $1.specifiers->first)
919       {
920          Specifier spec = $1.specifiers->first;
921          if(spec.type == nameSpecifier)
922             $$.name = MkIdentifier(spec.name);
923       }
924       FreeTemplateDataType($1);
925       $$.loc = @$;
926    }
927    /*| template_datatype '=' template_identifier_argument
928    {
929       $$ = $3;
930       if($1.specifiers && $1.specifiers->first)
931       {
932          Specifier spec = $1.specifiers->first;
933          if(spec.type == nameSpecifier)
934             $$.name = MkIdentifier(spec.name);
935       }
936       FreeTemplateDataType($1);
937       $$.loc = @$;
938    } */
939    | template_datatype '=' template_type_argument
940    {
941       $$ = $3;
942       if($1.specifiers && $1.specifiers->first)
943       {
944          Specifier spec = $1.specifiers->first;
945          if(spec.type == nameSpecifier)
946             $$.name = MkIdentifier(spec.name);
947       }
948       FreeTemplateDataType($1);
949       $$.loc = @$;
950    }
951    ;
952
953 template_arguments_list:
954      template_argument                                { $$ = MkList(); ListAdd($$, $1); }
955    | template_arguments_list ',' template_argument    { ListAdd($1, $3); }
956    ;
957
958 struct_or_union:
959           STRUCT    { $$ = structSpecifier; }
960         | UNION     { $$ = unionSpecifier; }
961         ;
962
963 struct_declaration_list:
964           struct_declaration                            { $$ = MkList(); ListAdd($$, $1); }
965         | struct_declaration_list struct_declaration    { $$ = $1; ListAdd($1, $2); }
966         ;
967
968 default_property:
969      postfix_expression '=' initializer_condition { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; }
970    ;
971
972 default_property_list:
973      default_property        { $$ = MkList(); ListAdd($$, $1); ((MemberInit)$$->last).loc = @$; }
974    | default_property_list ',' default_property      { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
975    ;
976
977 property:
978    PROPERTY property_specifiers identifier '{' SETPROP compound_statement GETPROP compound_statement '}'
979       { $$ = MkProperty($2, null, $3, $6, $8); $$.loc = @$; }
980    | PROPERTY property_specifiers identifier '{' GETPROP compound_statement SETPROP compound_statement '}'
981       { $$ = MkProperty($2, null, $3, $8, $6); $$.loc = @$; }
982    | PROPERTY property_specifiers identifier '{' SETPROP compound_statement '}'
983       { $$ = MkProperty($2, null, $3, $6, null); $$.loc = @$; }
984    | PROPERTY property_specifiers identifier '{' GETPROP compound_statement '}'
985       { $$ = MkProperty($2, null, $3, null, $6); $$.loc = @$; }
986    | PROPERTY property_specifiers identifier '{' '}'
987       { $$ = MkProperty($2, null, $3, null, null); $$.loc = @$; }
988
989    | PROPERTY property_specifiers abstract_declarator identifier '{' SETPROP compound_statement GETPROP compound_statement '}'
990       { $$ = MkProperty($2, $3, $4, $7, $9); $$.loc = @$; }
991    | PROPERTY property_specifiers abstract_declarator identifier '{' GETPROP compound_statement SETPROP compound_statement '}'
992       { $$ = MkProperty($2, $3, $4, $9, $7); $$.loc = @$; }
993    | PROPERTY property_specifiers abstract_declarator identifier '{' SETPROP compound_statement '}'
994       { $$ = MkProperty($2, $3, $4, $7, null); $$.loc = @$; }
995    | PROPERTY property_specifiers abstract_declarator identifier '{' GETPROP compound_statement '}'
996       { $$ = MkProperty($2, $3, $4, null, $7); $$.loc = @$; }
997    | PROPERTY property_specifiers abstract_declarator identifier '{' '}'
998       { $$ = MkProperty($2, $3, $4, null, null); $$.loc = @$; }
999
1000    | PROPERTY property_specifiers '{' SETPROP compound_statement GETPROP compound_statement '}'
1001       { $$ = MkProperty($2, null, null, $5, $7); $$.loc = @$; }
1002    | PROPERTY property_specifiers '{' GETPROP compound_statement SETPROP compound_statement '}'
1003       { $$ = MkProperty($2, null, null, $7, $5); $$.loc = @$; }
1004    | PROPERTY property_specifiers '{' SETPROP compound_statement '}'
1005       { $$ = MkProperty($2, null, null, $5, null); $$.loc = @$; }
1006    | PROPERTY property_specifiers '{' GETPROP compound_statement '}'
1007       { $$ = MkProperty($2, null, null, null, $5); $$.loc = @$; }
1008    | PROPERTY property_specifiers '{' '}'
1009       { $$ = MkProperty($2, null, null, null, null); $$.loc = @$; }
1010
1011    | PROPERTY property_specifiers abstract_declarator '{' SETPROP compound_statement GETPROP compound_statement '}'
1012       { $$ = MkProperty($2, $3, null, $6, $8); $$.loc = @$; }
1013    | PROPERTY property_specifiers abstract_declarator '{' GETPROP compound_statement SETPROP compound_statement '}'
1014       { $$ = MkProperty($2, $3, null, $8, $6); $$.loc = @$; }
1015    | PROPERTY property_specifiers abstract_declarator '{' SETPROP compound_statement '}'
1016       { $$ = MkProperty($2, $3, null, $6, null); $$.loc = @$; }
1017    | PROPERTY property_specifiers abstract_declarator '{' GETPROP compound_statement '}'
1018       { $$ = MkProperty($2, $3, null, null, $6); $$.loc = @$; }
1019    | PROPERTY property_specifiers abstract_declarator '{' '}'
1020       { $$ = MkProperty($2, $3, null, null, null); $$.loc = @$; }
1021 ;
1022
1023 struct_declaration:
1024           guess_declaration_specifiers struct_declarator_list ';'         { $$ = MkClassDefDeclaration(MkStructDeclaration($1, $2, null)); $$.decl.loc = @$; $$.loc = @$; }
1025    | guess_declaration_specifiers ';'                                { $$ = MkClassDefDeclaration(MkStructDeclaration($1, null, null)); $$.decl.loc = @$; $$.loc = @$; }
1026    | instantiation_unnamed ';'                                       { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = @$; $$.decl.loc = @$; }
1027    | guess_instantiation_named ';'                                   { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = @$; $$.decl.loc = @$; }
1028    | class_function_definition                                       { $$ = MkClassDefFunction($1); $$.loc = @$; }
1029    | default_property_list ';' { $$ = MkClassDefDefaultProperty($1); if($1->last) ((MemberInit)$1->last).loc.end = @2.start; $$.loc = @$; }
1030    | property { $$ = MkClassDefProperty($1); $$.loc = @$; }
1031    | ';' { $$ = null; }
1032         ;
1033
1034 struct_declarator_list:
1035           struct_declarator
1036       { $$ = MkList(); ListAdd($$, $1); }
1037         | struct_declarator_list ',' struct_declarator
1038       { $$ = $1; ListAdd($1, $3); }
1039         ;
1040
1041 struct_declarator:
1042           declarator_nofunction
1043       { $$ = MkStructDeclarator($1, null); $$.loc = @$; }
1044         | declarator_nofunction attrib
1045       { $$ = MkStructDeclarator($1, null); $$.structDecl.attrib = $2; $$.loc = @$; }
1046         | ':' constant_expression
1047       { $$ = MkStructDeclarator(null, $2);  $$.loc = @$; }
1048         | declarator_nofunction ':' constant_expression
1049       { $$ = MkStructDeclarator($1, $3);  $$.loc = @$; }
1050    | declarator_nofunction ':' constant_expression ':' constant_expression
1051       { $$ = MkStructDeclarator($1, $3); $$.structDecl.posExp = $5; $$.loc = @$; }
1052         ;
1053
1054 enum_specifier_nocompound:
1055      ENUM identifier                            { $$ = MkEnum($2, null); if(declMode) DeclClass($2._class, $2.string); }
1056    | ENUM strict_type                           { $$ = MkEnum(MkIdentifier($2.name), null); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
1057    ;
1058
1059 enum_specifier_compound:
1060           ENUM '{' enumerator_list '}'
1061       { $$ = MkEnum(null, $3); }
1062         | ENUM identifier '{' enumerator_list '}'    { $$ = MkEnum($2, $4); if(declMode) DeclClass($2._class, $2.string); }
1063    | ENUM identifier '{' enumerator_list ';' struct_declaration_list '}'    { $$ = MkEnum($2, $4); $$.definitions = $6; if(declMode) DeclClass($2._class, $2.string); }
1064         | ENUM strict_type '{' enumerator_list ';' struct_declaration_list '}'          { $$ = MkEnum(MkIdentifier($2.name), $4); $$.definitions = $6; if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
1065    | ENUM strict_type '{' enumerator_list '}'          { $$ = MkEnum(MkIdentifier($2.name), $4); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
1066         ;
1067
1068 enumerator_list:
1069           enumerator
1070       { $$ = MkList(); ListAdd($$, $1); }
1071         | enumerator_list ',' enumerator
1072       { $$ = $1; ListAdd($1, $3); }
1073         ;
1074
1075 enumerator:
1076           identifier
1077       { $$ = MkEnumerator($1, null); }
1078         | identifier '=' constant_expression
1079       { $$ = MkEnumerator($1, $3); }
1080         ;
1081
1082
1083 direct_abstract_declarator:
1084           '(' abstract_declarator ')'
1085                                  { $$ = MkDeclaratorBrackets($2); }
1086         | '[' ']'
1087                                  { $$ = MkDeclaratorArray(null, null); }
1088    | '[' constant_expression ']'
1089                                  { $$ = MkDeclaratorArray(null, $2); }
1090    | '[' type ']'
1091                                  { $$ = MkDeclaratorEnumArray(null, $2); }
1092         | direct_abstract_declarator '[' ']'
1093                                  { $$ = MkDeclaratorArray($1, null); }
1094         | direct_abstract_declarator '[' constant_expression ']'
1095                                  { $$ = MkDeclaratorArray($1, $3); }
1096         | direct_abstract_declarator '[' type']'
1097                                  { $$ = MkDeclaratorEnumArray($1, $3); }
1098         | '(' ')'
1099                                  { $$ = MkDeclaratorFunction(null, null); }
1100         | '(' parameter_type_list ')'
1101                                  { $$ = MkDeclaratorFunction(null, $2); }
1102         | direct_abstract_declarator '(' ')'
1103                                  { $$ = MkDeclaratorFunction($1, null); }
1104         | direct_abstract_declarator '(' parameter_type_list ')'
1105                                  { $$ = MkDeclaratorFunction($1, $3); }
1106         ;
1107
1108 direct_abstract_declarator_noarray:
1109           '(' abstract_declarator_noarray ')'
1110                                  { $$ = MkDeclaratorBrackets($2); }
1111         | '(' ')'
1112                                  { $$ = MkDeclaratorFunction(null, null); }
1113         | '(' parameter_type_list ')'
1114                                  { $$ = MkDeclaratorFunction(null, $2); }
1115         | direct_abstract_declarator_noarray '(' ')'
1116                                  { $$ = MkDeclaratorFunction($1, null); }
1117         | direct_abstract_declarator_noarray '(' parameter_type_list ')'
1118                                  { $$ = MkDeclaratorFunction($1, $3); }
1119         ;
1120
1121 abstract_declarator:
1122           pointer                              { $$ = MkDeclaratorPointer($1, null); }
1123         | direct_abstract_declarator
1124         | pointer direct_abstract_declarator   { $$ = MkDeclaratorPointer($1, $2); }
1125    | ext_decl pointer                     { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, null)); }
1126    | ext_decl direct_abstract_declarator  { $$ = MkDeclaratorExtended($1, $2); }
1127         | ext_decl pointer direct_abstract_declarator { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1128         ;
1129
1130 abstract_declarator_noarray:
1131           pointer                              { $$ = MkDeclaratorPointer($1, null); }
1132         | direct_abstract_declarator_noarray
1133         | pointer direct_abstract_declarator_noarray   { $$ = MkDeclaratorPointer($1, $2); }
1134    | ext_decl pointer { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, null)); }
1135    | ext_decl direct_abstract_declarator_noarray { $$ = MkDeclaratorExtended($1, $2); }
1136         | ext_decl pointer direct_abstract_declarator_noarray { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1137         ;
1138
1139 /*
1140 abstract_declarator:
1141           pointer
1142       { $$ = MkDeclaratorPointer($1, null); }
1143         | direct_abstract_declarator
1144         | pointer direct_abstract_declarator
1145       { $$ = MkDeclaratorPointer($1, $2); }
1146
1147    | ext_decl pointer
1148       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, null)); }
1149         | ext_decl direct_abstract_declarator
1150       { $$ = MkDeclaratorExtended($1, $2); }
1151         | ext_decl pointer direct_abstract_declarator
1152       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1153
1154         ;
1155
1156 direct_abstract_declarator:
1157           '(' abstract_declarator ')'
1158       { $$ = MkDeclaratorBrackets($2); }
1159         | '[' ']'
1160       { $$ = MkDeclaratorArray(null, null); }
1161         | '[' constant_expression ']'
1162       { $$ = MkDeclaratorArray(null, $2); }
1163    | '[' type ']'
1164       { $$ = MkDeclaratorEnumArray(null, $2); }
1165         | direct_abstract_declarator '[' ']'
1166       { $$ = MkDeclaratorArray($1, null); }
1167         | direct_abstract_declarator '[' constant_expression ']'
1168       { $$ = MkDeclaratorArray($1, $3); }
1169         | direct_abstract_declarator '[' type ']'
1170       { $$ = MkDeclaratorEnumArray($1, $3); }
1171         | '(' ')'
1172       { $$ = MkDeclaratorFunction(null, null); }
1173         | '(' parameter_type_list ')'
1174       { $$ = MkDeclaratorFunction(null, $2); }
1175         | direct_abstract_declarator '(' ')'
1176       { $$ = MkDeclaratorFunction($1, null); }
1177         | direct_abstract_declarator '(' parameter_type_list ')'
1178       { $$ = MkDeclaratorFunction($1, $3); }
1179         ;
1180 */
1181 declarator:
1182           direct_declarator
1183         | pointer direct_declarator
1184       { $$ = MkDeclaratorPointer($1, $2); }
1185    | ext_decl pointer direct_declarator
1186       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1187    | declarator ext_decl
1188       { $$ = MkDeclaratorExtendedEnd($2, $1); }
1189    ;
1190
1191 direct_declarator_nofunction:
1192           identifier
1193       { $$ = MkDeclaratorIdentifier($1); }
1194         | '(' declarator ')'
1195       { $$ = MkDeclaratorBrackets($2); }
1196         | direct_declarator_nofunction '[' constant_expression ']'
1197       { $$ = MkDeclaratorArray($1, $3); }
1198         | direct_declarator_nofunction '[' ']'
1199       { $$ = MkDeclaratorArray($1, null); }
1200    | direct_declarator_nofunction '[' type ']'
1201       { $$ = MkDeclaratorEnumArray($1, $3); }
1202         ;
1203
1204 declarator_function:
1205      direct_declarator_function
1206         | pointer direct_declarator_function
1207       { $$ = MkDeclaratorPointer($1, $2); }
1208
1209    | ext_decl direct_declarator_function
1210       { $$ = MkDeclaratorExtended($1, $2); }
1211         | ext_decl pointer direct_declarator_function
1212       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1213         | pointer ext_decl direct_declarator_function
1214       { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
1215
1216    ;
1217
1218 direct_declarator_function_start:
1219      direct_declarator_nofunction '('
1220    ;
1221
1222 direct_declarator_function:
1223           direct_declarator_function_start parameter_type_list ')'
1224       { $$ = MkDeclaratorFunction($1, $2); }
1225         | direct_declarator_function_start identifier_list ')'
1226       { $$ = MkDeclaratorFunction($1, $2); }
1227         | direct_declarator_function_start ')'
1228       { $$ = MkDeclaratorFunction($1, null); }
1229         ;
1230
1231 direct_declarator:
1232      direct_declarator_function
1233    | direct_declarator_nofunction
1234    | ext_decl direct_declarator_function
1235       { $$ = MkDeclaratorExtended($1, $2); }
1236    | ext_decl direct_declarator_nofunction
1237       { $$ = MkDeclaratorExtended($1, $2); }
1238         ;
1239
1240 declarator_nofunction:
1241           direct_declarator_nofunction
1242         | pointer direct_declarator_nofunction      { $$ = MkDeclaratorPointer($1, $2); }
1243    | ext_decl direct_declarator_nofunction { $$ = MkDeclaratorExtended($1, $2); }
1244         | ext_decl pointer direct_declarator_nofunction { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1245         | pointer ext_decl direct_declarator_nofunction { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
1246 ;
1247
1248 type_qualifier_list:
1249           type_qualifier                          { $$ = MkList(); ListAdd($$, $1); }
1250         | type_qualifier_list type_qualifier      { $$ = $1; ListAdd($1, $2);  }
1251         ;
1252
1253 pointer:
1254           '*'                               { $$ = MkPointer(null, null); }
1255         | '*' type_qualifier_list           { $$ = MkPointer($2, null); }
1256         | '*' pointer                       { $$ = MkPointer(null, $2); }
1257         | '*' type_qualifier_list pointer   { $$ = MkPointer($2, $3); }
1258         ;
1259
1260 parameter_type_list:
1261           parameter_list
1262         | parameter_list ',' ELLIPSIS { $$ = $1; ListAdd($1, MkTypeName(null, null)); }
1263         ;
1264
1265 parameter_list:
1266           parameter_declaration                      { $$ = MkList(); ListAdd($$, $1); }
1267         | parameter_list ',' parameter_declaration   { $$ = $1; ListAdd($1, $3); }
1268         ;
1269
1270 parameter_declaration:
1271           guess_declaration_specifiers declarator          { $$ = MkTypeName($1, $2); }
1272         | guess_declaration_specifiers abstract_declarator { $$ = MkTypeName($1, $2); }
1273    | guess_declaration_specifiers '&'                 { $$ = MkTypeName($1, MkDeclaratorPointer(MkPointer(null,null), null)); }
1274    | guess_declaration_specifiers '&' declarator      { $$ = MkTypeName($1, MkDeclaratorPointer(MkPointer(null,null), $3)); }
1275    | real_guess_declaration_specifiers                { $$ = MkTypeName($1, null); }
1276 /*
1277    | CLASS
1278       { $$ = MkTypeName(MkList(), null); $$.typedObject = true; }                        // Confusion with ellipsis? MkList()?
1279    | CLASS '&'
1280       { $$ = MkTypeName(null, null); $$.typedObject = true; $$.byReference = true; }
1281    | CLASS declarator
1282       { $$ = MkTypeName(MkList(), $2); $$.typedObject = true; }                        // Confusion with ellipsis? MkList()?
1283    | CLASS '&' declarator
1284       { $$ = MkTypeName(null, $3); $$.typedObject = true; $$.byReference = true; }
1285 */
1286    | CLASS
1287       { $$ = MkTypeName(MkListOne(MkSpecifier(CLASS)), null); }
1288 /*
1289    | TYPED_OBJECT
1290       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), null); }
1291    | TYPED_OBJECT '&'
1292       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), MkDeclaratorPointer(MkPointer(null,null), null)); }
1293    | TYPED_OBJECT declarator
1294       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), $2);  }
1295    | TYPED_OBJECT '&' declarator
1296       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), MkDeclaratorPointer(MkPointer(null,null), $3)); }
1297    | ANY_OBJECT
1298       { $$ = MkTypeName(MkListOne(MkSpecifier(ANY_OBJECT)), null); }
1299    | ANY_OBJECT declarator
1300       { $$ = MkTypeName(MkListOne(MkSpecifier(ANY_OBJECT)), $2); }
1301
1302    | error
1303       { $$ = MkTypeName(MkListOne(MkSpecifier(INT)), null); }
1304    | error declarator             { $$ = MkTypeName(MkListOne(MkSpecifier(INT)), $2); }
1305    //| error struct_declarator             { $$ = MkTypeName(MkListOne(MkSpecifier(INT)), $2); }
1306    | error abstract_declarator          { $$ = MkTypeName(MkListOne(MkSpecifier(INT)), $2); }
1307 */
1308         ;
1309
1310 identifier_list:
1311           identifier                        { $$ = MkList(); ListAdd($$, MkTypeName(null, MkDeclaratorIdentifier($1))); }
1312         | identifier_list ',' identifier    { $$ = $1; ListAdd($1, MkTypeName(null, MkDeclaratorIdentifier($3))); }
1313         ;
1314
1315 type_name:
1316           specifier_qualifier_list                      { $$ = MkTypeName($1, null); }
1317         | specifier_qualifier_list abstract_declarator  { $$ = MkTypeName($1, $2); }
1318         ;
1319
1320 guess_type_name:
1321           guess_specifier_qualifier_list                         { $$ = MkTypeName($1, null); }
1322         | guess_specifier_qualifier_list abstract_declarator     { $$ = MkTypeName($1, $2); }
1323         ;
1324
1325 initializer:
1326           assignment_expression
1327       { $$ = MkInitializerAssignment($1); $$.loc = @$; }
1328         | '{' initializer_list '}'
1329       { $$ = MkInitializerList($2); $$.loc = @$; }
1330         | '{' initializer_list ',' '}'
1331       {
1332          $$ = MkInitializerList($2);
1333          $$.loc = @$;
1334
1335          {
1336             Expression exp = MkExpDummy();
1337             Initializer init = MkInitializerAssignment(exp);
1338             init.loc = @3;
1339             exp.loc = @3;
1340             ListAdd($2, init);
1341          }
1342       }
1343         ;
1344
1345 initializer_condition:
1346           conditional_expression
1347       { $$ = MkInitializerAssignment($1); $$.loc = @$; }
1348    | anon_instantiation_expression
1349       { $$ = MkInitializerAssignment($1); $$.loc = @$; }
1350 /*
1351         | '{' initializer_list '}'
1352       { $$ = MkInitializerList($2); $$.loc = @$; }
1353         | '{' initializer_list ',' '}'
1354       {
1355          $$ = MkInitializerList($2);
1356          $$.loc = @$;
1357
1358          {
1359             Expression exp = MkExpDummy();
1360             Initializer init = MkInitializerAssignment(exp);
1361             init.loc = @3;
1362             exp.loc = @3;
1363             ListAdd($2, init);
1364          }
1365       }
1366 */
1367         ;
1368
1369 initializer_list:
1370           initializer
1371       { $$ = MkList(); ListAdd($$, $1); }
1372         | initializer_list ',' initializer
1373       { $$ = $1; ListAdd($1, $3); }
1374         ;
1375
1376 statement:
1377           labeled_statement
1378         | compound_statement
1379         | expression_statement
1380         | selection_statement
1381         | iteration_statement
1382         | jump_statement
1383         ;
1384
1385 labeled_statement:
1386           identifier ':' statement
1387       { $$ = MkLabeledStmt($1, $3); $$.loc = @$; }
1388         | CASE constant_expression ':' statement
1389       { $$ = MkCaseStmt($2, $4); $$.loc = @$; $2.loc.start = @1.end; }
1390         | DEFAULT ':' statement
1391       { $$ = MkCaseStmt(null, $3); $$.loc = @$; }
1392         ;
1393
1394 declaration_list:
1395           declaration                       { $$ = MkList(); ListAdd($$, $1); }
1396         | declaration_list declaration      { $$ = $1; ListAdd($1, $2); }
1397         ;
1398
1399 statement_list:
1400           statement                         { $$ = MkList(); ListAdd($$, $1); }
1401         | statement_list statement          { $$ = $1; ListAdd($1, $2); }
1402
1403    // declaration not allowed after statements
1404    | statement_list declaration              { Statement stmt = MkBadDeclStmt($2); stmt.loc = @2; /*yyerror(); */ ListAdd($1, stmt); $$ = $1; }
1405         ;
1406
1407 compound_inside:
1408           statement_list                      { $$ = MkCompoundStmt(null, $1); }
1409         | declaration_list                  { $$ = MkCompoundStmt($1, null); }
1410         | declaration_list statement_list   { $$ = MkCompoundStmt($1, $2); }
1411    ;
1412
1413 compound_start:
1414     '{' { $<context>$ = PushContext(); }
1415     ;
1416
1417 compound_statement:
1418    '{' '}'
1419    {
1420       $$ = MkCompoundStmt(null, null);
1421       $$.compound.context = PushContext();
1422       PopContext($$.compound.context);
1423       $$.loc = @$;
1424    }
1425
1426         | compound_start compound_inside '}'
1427       { $$ = $2; $$.compound.context = $<context>1; PopContext($<context>1); $$.loc = @$; }
1428         ;
1429
1430 expression_statement:
1431           ';'                         { $$ = MkExpressionStmt(null); $$.loc = @$; }
1432         | expression ';'              { $$ = MkExpressionStmt($1); $$.loc = @$; }
1433         ;
1434
1435 selection_statement:
1436           IF '(' expression ')' statement %prec IFX        { $$ = MkIfStmt($3, $5, null); $$.loc = @$; }
1437         | IF '(' expression ')' statement ELSE statement   { $$ = MkIfStmt($3, $5, $7); $$.loc = @$; }
1438         | SWITCH '(' expression ')' statement              { $$ = MkSwitchStmt($3, $5); $$.loc = @$; }
1439         ;
1440
1441 iteration_statement:
1442           WHILE '(' expression ')' statement           { $$ = MkWhileStmt($3, $5); $$.loc = @$; }
1443         | DO statement WHILE '(' expression ')' ';'     { $$ = MkDoWhileStmt($2, $5); $$.loc = @$; }
1444         | FOR '(' expression_statement expression_statement ')' statement                   { $$ = MkForStmt($3, $4, null, $6); $$.loc = @$; }
1445         | FOR '(' expression_statement expression_statement expression ')' statement        { $$ = MkForStmt($3, $4, $5, $7); $$.loc = @$; }
1446
1447    | WHILE '(' ')' statement     { $$ = MkWhileStmt(null, $4); $$.loc = @$; }
1448    | FOR '(' expression_statement ')' statement                   { $$ = MkForStmt($3, null, null, $5); $$.loc = @$; }
1449    | FOR '(' ')' statement  { $$ = MkForStmt(null, null, null, $4); $$.loc = @$; }
1450         ;
1451
1452 jump_statement:
1453           GOTO identifier ';'   { $$ = MkGotoStmt($2); $$.loc = @$; }
1454         | CONTINUE ';'          { $$ = MkContinueStmt(); $$.loc = @$; }
1455         | BREAK ';'             { $$ = MkBreakStmt(); $$.loc = @$; }
1456         | RETURN ';'            { Expression exp = MkExpDummy(); $$ = MkReturnStmt(MkListOne(exp)); $$.loc = @$; exp.loc = @2; }
1457         | RETURN expression ';' { $$ = MkReturnStmt($2); $$.loc = @$; }
1458         ;
1459
1460 string_literal:
1461    STRING_LITERAL { $$ = CopyString(yytext); }
1462    ;
1463
1464 instantiation_named:
1465      declaration_specifiers identifier '{' members_initialization_list '}'
1466       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
1467    | declaration_specifiers identifier '{' '}'
1468       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), MkList());  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.start;}
1469    ;
1470
1471 guess_instantiation_named:
1472      guess_declaration_specifiers identifier '{' members_initialization_list '}'
1473       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
1474    |  guess_declaration_specifiers identifier '{' '}'
1475       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), MkList());  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.start;}
1476
1477    /*| guess_declaration_specifiers identifier '{' members_initialization_list error
1478       {
1479          int l = 0;
1480          $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;
1481
1482          for(;;)
1483          {
1484             if(yychar == '}')
1485                l--;
1486             else if(yychar == '{')
1487                l++;
1488             if(l<0)
1489                break;
1490             yychar = yylex();
1491             yyerrok;
1492          }
1493          if(yychar == '}')
1494             yychar = yylex();
1495       }*/
1496    ;
1497
1498 instantiation_unnamed:
1499      type '{' members_initialization_list '}'
1500       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; }
1501    | type '{' '}'
1502       { $$ = MkInstantiation($1, null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.start;}
1503    | identifier '{' members_initialization_list '}'
1504       { Location tmpLoc = yylloc; yylloc = @1; yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);$$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; FreeIdentifier($1); }
1505    | identifier '{' '}'
1506       { Location tmpLoc = yylloc; yylloc = @1; yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.start; FreeIdentifier($1); }
1507    ;
1508
1509 instantiation_anon:
1510      '{' members_initialization_list '}'
1511       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @3.start; }
1512    | '{' '}'
1513       { $$ = MkInstantiation(null, null, MkList());  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.start;}
1514    ;
1515 class_function_definition:
1516           class_function_definition_start compound_statement
1517       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
1518         | virtual_class_function_definition_start compound_statement
1519       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
1520    | virtual_class_function_definition_start ';'
1521       { ProcessClassFunctionBody($1, null); $$.loc = @$; }
1522         | constructor_function_definition_start compound_statement
1523       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
1524         | destructor_function_definition_start compound_statement
1525       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
1526         ;
1527
1528 instance_class_function_definition_start:
1529    // Guess here conflicts with an expression...
1530      declaration_specifiers declarator_function
1531       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
1532     | declaration_specifiers declarator_nofunction
1533       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
1534       ;
1535
1536 instance_class_function_definition:
1537           instance_class_function_definition_start compound_statement
1538       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
1539         ;
1540
1541 data_member_initialization:
1542      postfix_expression '=' initializer_condition { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = @2.end;}
1543    | initializer_condition                { $$ = MkMemberInit(null, $1); $$.loc = @$; $$.realLoc = @$;}
1544    ;
1545
1546 data_member_initialization_list:
1547      data_member_initialization
1548       { $$ = MkList(); ListAdd($$, $1); }
1549    | data_member_initialization_list ',' data_member_initialization
1550       { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
1551    ;
1552
1553 data_member_initialization_list_coloned:
1554    data_member_initialization_list ';'
1555       { if($1->last) ((MemberInit)$1->last).loc.end = @2.end; $$ = $1; }
1556    ;
1557
1558 members_initialization_list_coloned:
1559      data_member_initialization_list_coloned                                        { MembersInit members = MkMembersInitList($1); $$ = MkList(); ListAdd($$, members); members.loc = @1; }
1560    | instance_class_function_definition                                             { $$ = MkList(); ListAdd($$, MkMembersInitMethod($1)); ((MembersInit)$$->last).loc = @1; }
1561    | members_initialization_list_coloned  data_member_initialization_list_coloned   { MembersInit members = MkMembersInitList($2); ListAdd($$, members); members.loc = @2; $$ = $1;  }
1562    | members_initialization_list_coloned  instance_class_function_definition        { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2;$$ = $1;  }
1563    | ';'                                                                            { MembersInit members = MkMembersInitList(MkList()); $$ = MkList(); ListAdd($$, members); members.loc = @1;  }
1564    | members_initialization_list_coloned ';'                                        { MembersInit members = MkMembersInitList(MkList()); ListAdd($$, members); members.loc = @2; $$ = $1; }
1565    ;
1566
1567 members_initialization_list:
1568      members_initialization_list_coloned
1569    | data_member_initialization_list                                       { $$ = MkList(); ListAdd($$, MkMembersInitList($1)); ((MembersInit)$$->last).loc = @1; }
1570    | members_initialization_list_coloned data_member_initialization_list   { ListAdd($1, MkMembersInitList($2));   ((MembersInit)$$->last).loc = @2; }
1571    ;
1572
1573 type_unit:
1574      parameter_declaration                            { parsedType = $1; }
1575    | parameter_declaration ':' constant_expression    { parsedType = $1; parsedType.bitCount = $3; }
1576    ;
1577
1578 %%