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