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