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