compiler: (WIP) Fixes for MinGW/GCC 5
[sdk] / compiler / libec / src / grammar.y
1 %{
2 import "ecdefs"
3
4 #define YYSIZE_T size_t
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 #define PRECOMPILER
15 extern File fileInput;
16 extern char * yytext;
17 OldList * ast;
18 int yylex();
19 int yyerror();
20 bool guess;
21 bool deleteWatchable = false;
22
23 #define MAX_STRUCT_LEVELS     256
24 AccessMode memberAccessStack[MAX_STRUCT_LEVELS];
25 int defaultMemberAccess = -1;
26
27 #define POP_DEFAULT_ACCESS    if(defaultMemberAccess > -1) defaultMemberAccess--;
28
29 #define C89_DECL_WARNING            $"eC expects all declarations to precede statements in the block (C89 style)\n"
30 #define CASE_LABELED_STMT_WARNING   $"labeled statement directly within a case statement\n"
31
32 #define uint _uint
33 default:
34
35 %}
36
37 %debug
38 %union
39 {
40    SpecifierType specifierType;
41    int i;
42    AccessMode declMode;
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    AsmField asmField;
59    Attrib attrib;
60    ExtDecl extDecl;
61    Attribute attribute;
62
63    Instantiation instance;
64    MembersInit membersInit;
65    MemberInit memberInit;
66    ClassFunction classFunction;
67    ClassDefinition _class;
68    ClassDef classDef;
69    PropertyDef prop;
70    char * string;
71    Symbol symbol;
72    PropertyWatch propertyWatch;
73    TemplateParameter templateParameter;
74    TemplateArgument templateArgument;
75    TemplateDatatype templateDatatype;
76
77    DBTableEntry dbtableEntry;
78    DBIndexItem dbindexItem;
79    DBTableDef dbtableDef;
80 }
81
82 // *** Types ***
83
84 %type <symbol> class_decl
85 %type <specifierType> struct_or_union
86 %type <i>   unary_operator assignment_operator
87 %type <declMode> member_access declaration_mode
88 %type <id>  identifier enum_decl
89 %type <exp> primary_expression primary_expression_error postfix_expression unary_expression cast_expression
90             multiplicative_expression additive_expression shift_expression
91             relational_expression relational_expression_smaller_than equality_expression and_expression
92             exclusive_or_expression inclusive_or_expression logical_and_expression
93             logical_or_expression conditional_expression assignment_expression
94             constant_expression constant_expression_error
95             anon_instantiation_expression anon_instantiation_expression_error i18n_string
96             postfix_expression_error unary_expression_error cast_expression_error
97             multiplicative_expression_error additive_expression_error shift_expression_error
98             relational_expression_error equality_expression_error and_expression_error
99             exclusive_or_expression_error inclusive_or_expression_error logical_and_expression_error
100             logical_or_expression_error conditional_expression_error assignment_expression_error
101             simple_primary_expression constant
102             common_unary_expression common_unary_expression_error
103             database_open dbfield dbindex dbtable
104
105 //simple_unary_expression simple_unary_expression_error
106 // simple_postfix_expression simple_postfix_expression_error
107
108 %type <list> argument_expression_list expression expression_anon_inst expression_anon_inst_error enumerator_list type_qualifier_list
109              struct_declarator_list struct_declaration_list
110              declaration_specifiers identifier_list identifier_list_error initializer_list init_declarator_list
111              parameter_list parameter_list_error parameter_type_list parameter_type_list_error declaration_list declaration_list_error statement_list statement_list_error
112              translation_unit members_initialization_list members_initialization_list_coloned members_initialization_list_error  data_member_initialization_list data_member_initialization_list_coloned
113              default_property_list data_member_initialization_list_error
114              expression_error init_declarator_list_error argument_expression_list_error default_property_list_error struct_declaration_list_error
115              translation_unit_error
116              guess_declaration_specifiers
117              external_guess_declaration_specifiers external_guess_declaration_specifiers_error
118              specifier_qualifier_list guess_specifier_qualifier_list
119              _inheritance_specifiers inheritance_specifiers property_specifiers
120              new_specifiers renew_specifiers asm_field_list
121              property_watch_list watch_property_list
122              dbindex_item_list dbfield_definition_list
123              template_arguments_list template_parameters_list attribs_list
124
125 %type <asmField> asm_field
126 %type <specifier> storage_class_specifier enum_specifier_compound enum_specifier_nocompound type_qualifier type_specifier class_specifier class_specifier_error
127                   struct_or_union_specifier_compound struct_or_union_specifier_nocompound ext_storage type strict_type guess_type enum_class strict_type_specifier struct_class
128                   struct_or_union_specifier_compound_error struct_class_error struct_decl
129                   enum_specifier_compound_error enum_class_error external_storage_class_specifier
130                   base_strict_type struct_head struct_entry
131 %type <enumerator> enumerator
132 %type <declarator> declarator direct_declarator direct_abstract_declarator abstract_declarator
133                    direct_abstract_declarator_noarray abstract_declarator_noarray
134                    struct_declarator direct_declarator_function direct_declarator_function_start declarator_function_error direct_declarator_function_error declarator_function direct_declarator_nofunction
135                    direct_declarator_function_type_ok declarator_nofunction_type_ok direct_declarator_nofunction_type_ok declarator_function_type_ok direct_declarator_function_error_type_ok
136                    direct_declarator_function_start_type_ok direct_declarator_type_ok declarator_type_ok declarator_function_error_type_ok
137 %type <pointer> pointer
138 %type <initializer> initializer initializer_error initializer_condition initializer_condition_error
139 %type <initDeclarator> init_declarator init_declarator_error
140 %type <typeName> type_name guess_type_name parameter_declaration parameter_declaration_error
141 %type <stmt> statement labeled_statement labeled_statement_error compound_statement compound_statement_error expression_statement
142              selection_statement selection_statement_error iteration_statement jump_statement jump_statement_error compound_inside compound_inside_error
143              iteration_statement_error statement_error asm_statement
144              stopwatching watch_definition firewatchers
145
146 %type <declaration> declaration declaration_error external_guess_declaration external_guess_declaration_error
147 %type <function>  function_definition  function_definition_error
148 %type <external>  external_declaration external_declaration_error
149
150 %type <instance> instantiation_named instantiation_named_error instantiation_unnamed instantiation_unnamed_error guess_instantiation_named guess_instantiation_named_error external_guess_instantiation_named
151                  instantiation_anon instantiation_anon_error
152 %type <memberInit> data_member_initialization data_member_initialization_error default_property default_property_error
153 %type <classFunction> class_function_definition class_function_definition_error class_function_definition_start
154                      class_function_definition_start_error virtual_class_function_definition_start virtual_class_function_definition_start_error
155                      constructor_function_definition_start destructor_function_definition_start
156 %type <classFunction> instance_class_function_definition instance_class_function_definition_error instance_class_function_definition_start instance_class_function_definition_start_error
157 %type <_class> class class_error class_head
158 %type <classDef> struct_declaration struct_declaration_error
159 %type <string> string_literal base_strict_type_name attribute_word
160 %type <extDecl> ext_decl
161 %type <attrib> attrib
162 %type <attribute> attribute
163 %type <prop> property property_start property_body class_property class_property_start class_property_body
164 %type <propertyWatch> property_watch self_watch_definition
165
166 %type <templateParameter> template_parameter template_type_parameter template_identifier_parameter template_expression_parameter
167 %type <templateArgument> template_argument template_type_argument template_identifier_argument template_expression_argument
168 %type <templateDatatype> template_datatype
169
170 %type <dbtableEntry> dbindex_entry dbfield_entry
171 %type <dbindexItem> dbindex_item
172 %type <dbtableDef> dbtable_definition
173 %type <context> compound_start class_entry
174
175 %token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF
176 %token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
177 %token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
178 %token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN
179 %token XOR_ASSIGN OR_ASSIGN TYPE_NAME
180
181 %token TYPEDEF EXTERN STATIC AUTO REGISTER
182 %token CHAR SHORT INT UINT INT64 INT128 LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID VALIST
183 %token STRUCT UNION ENUM ELLIPSIS
184
185 %token CASE DEFAULT IF SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
186
187 %nonassoc IFX
188 %nonassoc ELSE
189 %token CLASS THISCLASS CLASS_NAME
190 %token PROPERTY SETPROP GETPROP NEWOP RENEW DELETE EXT_DECL EXT_STORAGE IMPORT DEFINE VIRTUAL ATTRIB
191 %token PUBLIC PRIVATE
192 %token TYPED_OBJECT ANY_OBJECT _INCREF EXTENSION ASM TYPEOF
193 %token WATCH STOPWATCHING FIREWATCHERS WATCHABLE CLASS_DESIGNER CLASS_NO_EXPANSION CLASS_FIXED ISPROPSET
194 %token CLASS_DEFAULT_PROPERTY PROPERTY_CATEGORY CLASS_DATA CLASS_PROPERTY SUBCLASS NAMESPACE
195 %token NEW0OP RENEW0 VAARG
196 %token DBTABLE DBFIELD DBINDEX DATABASE_OPEN
197 %token ALIGNOF ATTRIB_DEP __ATTRIB
198 %token BOOL _BOOL _COMPLEX _IMAGINARY RESTRICT THREAD
199 %token WIDE_STRING_LITERAL
200 %token BUILTIN_OFFSETOF
201
202 %destructor { FreeIdentifier($$); } identifier
203 %destructor { FreePointer($$); } pointer
204 %destructor { FreeExpression($$); } primary_expression primary_expression_error postfix_expression unary_expression cast_expression
205                                     multiplicative_expression additive_expression shift_expression
206                                     relational_expression equality_expression and_expression
207                                     exclusive_or_expression inclusive_or_expression logical_and_expression
208                                     logical_or_expression conditional_expression assignment_expression
209                                     constant_expression constant_expression_error
210                                     postfix_expression_error unary_expression_error cast_expression_error
211                                     multiplicative_expression_error additive_expression_error shift_expression_error
212                                     relational_expression_error equality_expression_error and_expression_error
213                                     exclusive_or_expression_error inclusive_or_expression_error logical_and_expression_error
214                                     logical_or_expression_error conditional_expression_error assignment_expression_error i18n_string
215 %destructor { FreeSpecifier($$); }  storage_class_specifier enum_specifier_compound enum_specifier_nocompound type_qualifier type_specifier class_specifier class_specifier_error
216                                     struct_or_union_specifier_compound struct_or_union_specifier_nocompound ext_storage type strict_type guess_type enum_class strict_type_specifier struct_class
217                                     struct_or_union_specifier_compound_error struct_class_error struct_decl
218                                     enum_specifier_compound_error enum_class_error external_storage_class_specifier
219                                     base_strict_type struct_head struct_entry
220 %destructor { FreeEnumerator($$); } enumerator
221 %destructor { FreeDeclarator($$); } declarator direct_declarator direct_abstract_declarator abstract_declarator
222                                     direct_abstract_declarator_noarray abstract_declarator_noarray
223                                     struct_declarator direct_declarator_function direct_declarator_function_start declarator_function_error direct_declarator_function_error declarator_function direct_declarator_nofunction
224                                     direct_declarator_function_type_ok declarator_nofunction_type_ok direct_declarator_nofunction_type_ok declarator_function_type_ok direct_declarator_function_error_type_ok
225                                     direct_declarator_function_start_type_ok direct_declarator_type_ok declarator_type_ok declarator_function_error_type_ok
226
227 %destructor { FreeInitializer($$); } initializer initializer_error initializer_condition initializer_condition_error
228 %destructor { FreeInitDeclarator($$); } init_declarator init_declarator_error
229 %destructor { FreeTypeName($$); } type_name guess_type_name parameter_declaration parameter_declaration_error
230 %destructor { FreeStatement($$); }  statement labeled_statement labeled_statement_error compound_statement compound_statement_error expression_statement
231                                     selection_statement selection_statement_error iteration_statement jump_statement jump_statement_error compound_inside compound_inside_error
232                                     iteration_statement_error statement_error
233
234 %destructor { FreeDeclaration($$); } declaration
235 %destructor { FreeFunction($$); } function_definition  function_definition_error
236 %destructor { FreeExternal($$); } external_declaration external_declaration_error
237
238 %destructor { FreeInstance($$); } instantiation_named instantiation_named_error instantiation_unnamed instantiation_unnamed_error
239
240 %destructor { FreeMemberInit($$); } data_member_initialization data_member_initialization_error default_property default_property_error
241
242 %destructor { FreeClassFunction($$); } class_function_definition class_function_definition_error class_function_definition_start
243                                        class_function_definition_start_error virtual_class_function_definition_start virtual_class_function_definition_start_error
244                                        constructor_function_definition_start destructor_function_definition_start
245                                        instance_class_function_definition instance_class_function_definition_error instance_class_function_definition_start instance_class_function_definition_start_error
246 %destructor { Context ctx = curContext; PopContext(ctx); FreeContext(ctx); delete ctx; } class_entry
247 %destructor { Context ctx = curContext; PopContext(ctx); FreeContext(ctx); delete ctx; } class_decl
248 %destructor { FreeClass($$); } class class_error class_head
249 %destructor { FreeClassDef($$); } struct_declaration struct_declaration_error
250 %destructor { delete $$; } string_literal attribute_word base_strict_type_name
251 %destructor { FreeProperty($$); } property
252
253 %destructor { FreeList($$, FreeExpression); }  argument_expression_list expression expression_error argument_expression_list_error
254 %destructor { FreeList($$, FreeEnumerator); }  enumerator_list
255 %destructor { FreeList($$, FreeSpecifier); }   type_qualifier_list specifier_qualifier_list declaration_specifiers inheritance_specifiers _inheritance_specifiers external_guess_declaration_specifiers external_guess_declaration_specifiers_error
256                                                guess_declaration_specifiers guess_specifier_qualifier_list
257 %destructor { FreeList($$, FreeDeclarator); }  struct_declarator_list
258 %destructor { FreeList($$, FreeDeclaration); } declaration_list declaration_list_error
259 %destructor { FreeList($$, FreeInitializer); } initializer_list
260 %destructor { FreeList($$, FreeInitDeclarator); } init_declarator_list init_declarator_list_error
261 %destructor { FreeList($$, FreeTypeName); } parameter_list parameter_list_error parameter_type_list parameter_type_list_error identifier_list identifier_list_error
262 %destructor { FreeList($$, FreeStatement); } statement_list statement_list_error
263 %destructor { if($$ != ast) FreeList($$, FreeExternal); } translation_unit translation_unit_error
264 %destructor { FreeList($$, FreeClassDef); } struct_declaration_list struct_declaration_list_error
265 %destructor { FreeList($$, FreeMemberInit); } default_property_list default_property_list_error data_member_initialization_list data_member_initialization_list_coloned data_member_initialization_list_error
266 %destructor { FreeList($$, FreeMembersInit); } members_initialization_list members_initialization_list_coloned members_initialization_list_error
267 %destructor { PopContext($$); FreeContext($$); delete $$; } compound_start
268 %destructor { FreeTemplateParameter($$); } template_parameter template_type_parameter template_identifier_parameter template_expression_parameter
269 %destructor { FreeTemplateArgument($$); } template_argument template_type_argument template_identifier_argument template_expression_argument
270 %destructor { FreeTemplateDataType($$); } template_datatype
271 %destructor { FreeList($$, FreeTemplateParameter); } template_parameters_list
272 %destructor { FreeList($$, FreeTemplateArgument); } template_arguments_list
273 %destructor { } declaration_mode
274 %destructor { FreeAttrib($$); } attrib
275 %destructor { FreeExtDecl($$); } ext_decl
276 %destructor { FreeAttribute($$); } attribute
277 %destructor { FreeList($$, FreeAttribute); }  attribs_list
278
279 %start thefile
280
281 %%
282
283 guess_type:
284    identifier '*'
285    {
286       $$ = null;
287       _DeclClass($1._class, $1.string);
288
289       FreeIdentifier($1);
290
291       fileInput.Seek(@1.start.pos, start);
292       resetScannerPos(&@1.start);
293       yyclearin;
294
295       YYPOPSTACK(1);
296       yystate = *yyssp;
297       YY_STACK_PRINT (yyss, yyssp);
298       YYPOPSTACK(1);
299       yystate = *yyssp;
300       YY_STACK_PRINT (yyss, yyssp);
301       goto yysetstate;
302    }
303    | identifier '<'
304    {
305       $$ = null;
306    #ifdef PRECOMPILER
307       _DeclClass($1._class, $1.string);
308
309       FreeIdentifier($1);
310
311       fileInput.Seek(@1.start.pos, start);
312       resetScannerPos(&@1.start);
313       yyclearin;
314
315       YYPOPSTACK(1);
316       yystate = *yyssp;
317       YY_STACK_PRINT (yyss, yyssp);
318       YYPOPSTACK(1);
319       yystate = *yyssp;
320       YY_STACK_PRINT (yyss, yyssp);
321       goto yysetstate;
322    #endif
323    }
324 /*   | identifier '*' '<' template_arguments_list '>'
325    {
326       _DeclClass($1._class, $1.string);
327       fileInput.Seek(@1.start.pos, start);
328       resetScannerPos(&@1.start);
329       yyclearin;
330
331       YYPOPSTACK(1);
332       yystate = *yyssp;
333       YY_STACK_PRINT (yyss, yyssp);
334       YYPOPSTACK(1);
335       yystate = *yyssp;
336       YY_STACK_PRINT (yyss, yyssp);
337       goto yysetstate;
338    }*/
339    ;
340
341 type:
342    strict_type       { $$ = $1; }
343    | identifier identifier
344    {
345    #ifdef PRECOMPILER
346       if(!$1.string[0])
347       {
348          $$ = MkSpecifierName($1.string);
349          FreeIdentifier($1);
350          FreeIdentifier($2);
351       }
352       else
353       {
354          _DeclClass($1._class, $1.string);
355
356          FreeIdentifier($1);
357          FreeIdentifier($2);
358
359          fileInput.Seek(@1.start.pos, start);
360          resetScannerPos(&@1.start);
361          yyclearin;
362
363          YYPOPSTACK(1);
364          yystate = *yyssp;
365          YY_STACK_PRINT (yyss, yyssp);
366          YYPOPSTACK(1);
367          yystate = *yyssp;
368          YY_STACK_PRINT (yyss, yyssp);
369          goto yysetstate;
370    #else
371          Location tmpLoc = yylloc; $$ = $2; yylloc = @1;
372          Compiler_Error($"Not a type: %s\n", $1.string);
373          yylloc = tmpLoc; $2.badID = $1;
374    #endif
375       }
376    }
377    /*
378    | identifier '<'
379    {
380    #ifdef PRECOMPILER
381       _DeclClass($1._class, $1.string);
382       fileInput.Seek(@1.start.pos, start);
383       resetScannerPos(&@1.start);
384       yyclearin;
385
386       YYPOPSTACK(1);
387       yystate = *yyssp;
388       YY_STACK_PRINT (yyss, yyssp);
389       YYPOPSTACK(1);
390       yystate = *yyssp;
391       YY_STACK_PRINT (yyss, yyssp);
392       goto yysetstate;
393    #endif
394    }
395 /*   | strict_type '<' template_arguments_list '>'      { $$ = $1; }
396    | identifier identifier '<' template_arguments_list '>'
397    {
398    #ifdef PRECOMPILER
399       _DeclClass($1._class, $1.string);
400       FreeIdentifier($1);
401       FreeIdentifier($2);
402
403       fileInput.Seek(@1.start.pos, start);
404       resetScannerPos(&@1.start);
405       yyclearin;
406
407       YYPOPSTACK(1);
408       yystate = *yyssp;
409       YY_STACK_PRINT (yyss, yyssp);
410       YYPOPSTACK(1);
411       yystate = *yyssp;
412       YY_STACK_PRINT (yyss, yyssp);
413       goto yysetstate;
414    #else
415       Location tmpLoc = yylloc; $$ = $2; yylloc = @1;
416       Compiler_Error($"Not a type: %s\n", $1.string);
417       yylloc = tmpLoc; $2.badID = $1;
418    #endif
419    }*/
420    ;
421
422 base_strict_type:
423      TYPE_NAME    { $$ = MkSpecifierName(yytext); }
424    ;
425
426 base_strict_type_name:
427      TYPE_NAME    { $$ = CopyString(yytext); }
428    ;
429 strict_type:
430      base_strict_type
431     | base_strict_type '<' template_arguments_list '>' { $$ = $1; SetClassTemplateArgs($$, $3); $$.loc = @$; }
432     | base_strict_type '<' template_arguments_list RIGHT_OP
433     {
434       $$ = $1;
435       SetClassTemplateArgs($$, $3);
436       $$.loc = @$;
437
438       @4.end.pos--;
439       fileInput.Seek(@4.end.pos, start);
440       resetScannerPos(&@4.end);
441       yyclearin;
442     }
443
444 /*    | identifier '<' template_arguments_list '>' */
445       /*| identifier '<' error
446       {
447          _DeclClass($1._class, $1.string);
448
449          yyerrok;
450
451          fileInput.Seek(@1.start.pos, start);
452          resetScannerPos(&@1.start);
453          yyclearin;
454
455          YYPOPSTACK(1);
456          yystate = *yyssp;
457          YY_STACK_PRINT (yyss, yyssp);
458          YYPOPSTACK(1);
459          yystate = *yyssp;
460          YY_STACK_PRINT (yyss, yyssp);
461          YYPOPSTACK(1);
462          yystate = *yyssp;
463          YY_STACK_PRINT (yyss, yyssp);
464          goto yysetstate;
465
466          /* $$ = MkSpecifierNameArgs($1.string, $3); $$.loc = @$; FreeIdentifier($1); */
467       /*}*/
468    ;
469
470 class_function_definition_start:
471    guess_declaration_specifiers declarator_function_type_ok
472       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
473    | declarator_function
474       { $$ = MkClassFunction(null, null, $1, null); $$.loc = @$; }
475    ;
476
477 constructor_function_definition_start:
478    guess_declaration_specifiers '(' ')'
479       { $$ = MkClassFunction($1, null, null, null); $$.isConstructor = true; $$.loc = @$; }
480    ;
481
482 destructor_function_definition_start:
483    '~' guess_declaration_specifiers '(' ')'
484       { $$ = MkClassFunction($2, null, null, null); $$.isDestructor = true; $$.loc = @$; }
485    ;
486
487 virtual_class_function_definition_start:
488      VIRTUAL guess_declaration_specifiers declarator_function_type_ok
489       { $$ = MkClassFunction($2, null, $3, null); $$.isVirtual = true; $$.loc = @$; }
490    | VIRTUAL declarator_function
491       { $$ = MkClassFunction(null, null, $2, null); $$.isVirtual = true; $$.loc = @$; }
492       ;
493
494 class_function_definition_start_error:
495      guess_declaration_specifiers declarator_function_error_type_ok
496       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
497    | declarator_function_error
498       { $$ = MkClassFunction(null, null, $1, null); $$.loc = @$; }
499    ;
500
501 virtual_class_function_definition_start_error:
502      VIRTUAL guess_declaration_specifiers declarator_function_error_type_ok
503       { $$ = MkClassFunction($2, null, $3, null); $$.isVirtual = true; $$.loc = @$; }
504    | VIRTUAL declarator_function_error
505       { $$ = MkClassFunction(null, null, $2, null); $$.isVirtual = true; $$.loc = @$; }
506       ;
507
508 class_function_definition:
509         class_function_definition_start compound_statement
510       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
511         | virtual_class_function_definition_start compound_statement
512       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
513    | virtual_class_function_definition_start ';'
514       { ProcessClassFunctionBody($1, null); $$.loc = @$; }
515         | constructor_function_definition_start compound_statement
516       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
517         | destructor_function_definition_start compound_statement
518       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
519
520    // TESTING THIS
521    | class_function_definition_start ';'
522       { ProcessClassFunctionBody($1, null); $$.loc = @$; }
523
524    // Added this to fix attrib not working after function pointer declarations
525    | class_function_definition_start attrib ';'
526       {
527          if($1.declarator)
528          {
529             $1.declarator = MkStructDeclarator($1.declarator, null);
530             $1.declarator.structDecl.attrib = $2;
531          }
532          ProcessClassFunctionBody($1, null);
533          $$.loc = @$;
534       }
535         ;
536
537 class_function_definition_error:
538            class_function_definition_start compound_statement_error
539       { ProcessClassFunctionBody($1, $2); $$.loc = @$; $$.loc.end = $2.loc.end; }
540    |    class_function_definition_start_error
541       { ProcessClassFunctionBody($1, null); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;}
542         |  virtual_class_function_definition_start compound_statement_error
543       { ProcessClassFunctionBody($1, $2); $$.loc = @$; $$.loc.end = $2.loc.end; }
544    |    virtual_class_function_definition_start_error
545       { ProcessClassFunctionBody($1, null); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;}
546    |    virtual_class_function_definition_start_error ';'
547       { ProcessClassFunctionBody($1, null); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;}
548         ;
549
550 // In Instances, return type is required to distinguish from calling the function
551 instance_class_function_definition_start:
552    declaration_specifiers declarator_function_type_ok
553       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
554    |  declaration_specifiers declarator_nofunction_type_ok
555       { $$ = MkClassFunction($1, null, MkDeclaratorFunction($2, null), null); $$.loc = @$; }
556       ;
557
558 instance_class_function_definition_start_error:
559    declaration_specifiers declarator_function_error_type_ok
560       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
561       ;
562
563 instance_class_function_definition:
564         instance_class_function_definition_start compound_statement
565       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
566         ;
567
568 instance_class_function_definition_error:
569         instance_class_function_definition_start compound_statement_error
570       { ProcessClassFunctionBody($1, $2); $$.loc = @$; $$.loc.end = $2.loc.end; $$.loc.end.charPos++; $$.loc.end.pos++;}
571    |    instance_class_function_definition_start_error
572       { ProcessClassFunctionBody($1, null); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;}
573    |    instance_class_function_definition_start
574       { ProcessClassFunctionBody($1, null); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;}
575         ;
576
577 data_member_initialization:
578      postfix_expression '=' initializer_condition { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = @2.end;}
579    | initializer_condition                { $$ = MkMemberInit(null, $1); $$.loc = @$; $$.realLoc = @$;}
580    ;
581
582 data_member_initialization_error:
583      postfix_expression '=' initializer_condition_error { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = @2.end;}
584    | postfix_expression '=' error
585       {
586          $$ = MkMemberInitExp($1, MkInitializerAssignment(MkExpDummy()));
587          $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = $$.initializer.loc.end = @2.end;
588
589          fileInput.Seek(@2.end.pos, start);
590          yyclearin;
591          resetScannerPos(&@2.end);
592          @$.start = @1.start;
593          @$.end = @2.end;
594       }
595    | initializer_condition_error { $$ = MkMemberInit(null, $1); $$.loc = @$; $$.realLoc = @$;}
596    ;
597
598 data_member_initialization_list:
599    data_member_initialization { $$ = MkList(); ListAdd($$, $1); }
600    | data_member_initialization_list ',' data_member_initialization
601       { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
602    | data_member_initialization_list_error ',' data_member_initialization
603       { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
604    ;
605
606 data_member_initialization_list_error:
607    data_member_initialization_error { $$ = MkList(); ListAdd($$, $1); }
608    | data_member_initialization_list ',' data_member_initialization_error
609       { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
610    | data_member_initialization_list_error ',' data_member_initialization_error
611       { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
612
613    | data_member_initialization_list ',' error
614       { ((MemberInit)$1->last).loc.end = @2.end;
615          {
616             Initializer dummy = MkInitializerAssignment(MkExpDummy());
617             MemberInit memberInit = MkMemberInit(null, dummy);
618             memberInit.realLoc.start = memberInit.loc.start = dummy.loc.start = @2.end;
619             memberInit.realLoc.end = memberInit.loc.end = dummy.loc.end = @2.end;
620             ListAdd($1, memberInit);
621           }
622           $$ = $1;
623        }
624    |
625    data_member_initialization_list_error ',' error
626       { ((MemberInit)$1->last).loc.end = @2.end;
627          {
628             Initializer dummy = MkInitializerAssignment(MkExpDummy());
629             MemberInit memberInit = MkMemberInit(null, dummy);
630             memberInit.realLoc.start = memberInit.loc.start = dummy.loc.start = @2.end;
631             memberInit.realLoc.end = memberInit.loc.end = dummy.loc.end = @2.end;
632             ListAdd($1, memberInit);
633           }
634           $$ = $1;
635        }
636        |   ','
637       {
638          Initializer dummy = MkInitializerAssignment(MkExpDummy());
639          MemberInit memberInit = MkMemberInit(null, dummy);
640          memberInit.realLoc.start = memberInit.loc.start = dummy.loc.start = @1.start;
641          memberInit.realLoc.end = memberInit.loc.end = dummy.loc.end = @1.start;
642
643          $$ = MkList();
644          ListAdd($$, memberInit);
645
646          dummy = MkInitializerAssignment(MkExpDummy());
647          memberInit = MkMemberInit(null, dummy);
648          memberInit.realLoc.start = memberInit.loc.start = dummy.loc.start = @1.end;
649          memberInit.realLoc.end = memberInit.loc.end = dummy.loc.end = @1.end;
650          ListAdd($$, memberInit);
651       }
652    ;
653
654 data_member_initialization_list_coloned:
655    data_member_initialization_list ';'
656       { if($1->last) ((MemberInit)$1->last).loc.end = @2.end; $$ = $1; }
657    | data_member_initialization_list_error ';'
658       { if($1->last) ((MemberInit)$1->last).loc.end = @2.end; $$ = $1; }
659    ;
660
661 members_initialization_list_coloned:
662      data_member_initialization_list_coloned                                        { MembersInit members = MkMembersInitList($1); $$ = MkList(); ListAdd($$, members); members.loc = @1; }
663    | instance_class_function_definition                                             { $$ = MkList(); ListAdd($$, MkMembersInitMethod($1)); ((MembersInit)$$->last).loc = @1; }
664    | members_initialization_list_error data_member_initialization_list_coloned      { MembersInit members = MkMembersInitList($2); ListAdd($$, members);  members.loc = @2; $$ = $1; }
665    | members_initialization_list_error    instance_class_function_definition        { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
666    | members_initialization_list_coloned  data_member_initialization_list_coloned   { MembersInit members = MkMembersInitList($2); ListAdd($$, members); members.loc = @2; $$ = $1; }
667    | members_initialization_list_coloned  instance_class_function_definition        { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
668    | members_initialization_list_error ';'
669    | members_initialization_list_coloned ';'
670    {
671       MembersInit members = (MembersInit)$$->last;
672       if(members.type == dataMembersInit)
673          members.loc.end = @$.end;
674       else
675       {
676          MembersInit members = MkMembersInitList(MkList());
677          ListAdd($$, members);
678          members.loc = @2;
679       }
680       $$ = $1;
681    }
682    | ';'                                                                            { MembersInit members = MkMembersInitList(MkList()); $$ = MkList(); ListAdd($$, members); members.loc = @1;  }
683    ;
684
685 members_initialization_list:
686      members_initialization_list_coloned
687    | data_member_initialization_list                                       { $$ = MkList(); ListAdd($$, MkMembersInitList($1)); ((MembersInit)$$->last).loc = @1; }
688    | members_initialization_list_coloned data_member_initialization_list   { ListAdd($1, MkMembersInitList($2));   ((MembersInit)$$->last).loc = @2; }
689    | members_initialization_list_error data_member_initialization_list     { ListAdd($1, MkMembersInitList($2));   ((MembersInit)$$->last).loc = @2; }
690    ;
691
692 members_initialization_list_error:
693      instance_class_function_definition_error                                 { $$ = MkList(); ListAdd($$, MkMembersInitMethod($1)); ((MembersInit)$$->last).loc = @1; }
694      | members_initialization_list instance_class_function_definition_error  { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
695      | members_initialization_list_error instance_class_function_definition_error  { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
696      | members_initialization_list_coloned instance_class_function_definition_error  { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
697      | members_initialization_list_coloned data_member_initialization_list_error  { ListAdd($$, MkMembersInitList($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
698      | data_member_initialization_list_error                                  { $$ = MkList(); ListAdd($$, MkMembersInitList($1)); ((MembersInit)$$->last).loc = @1; }
699      | data_member_initialization_list error                                  { $$ = MkList(); ListAdd($$, MkMembersInitList($1)); ((MembersInit)$$->last).loc = @2; }
700    ;
701
702 instantiation_named:
703      instantiation_named_error '}'
704       { $$.loc = @$; $$.insideLoc.end = @2.start; $$ = $1; }
705     | instantiation_named_error error '}'
706       { $$.loc = @$; $$.insideLoc.end = @2.start; $$ = $1; }
707    ;
708
709 instantiation_named_error:
710     declaration_specifiers identifier '{' members_initialization_list_error
711       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
712 |   declaration_specifiers identifier '{' members_initialization_list error
713       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
714 |   declaration_specifiers identifier '{' members_initialization_list
715       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
716 |   declaration_specifiers identifier '{'
717       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), null); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
718 |   declaration_specifiers identifier '{' error
719       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), null);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
720    ;
721
722 /*
723 instantiation_named:
724      declaration_specifiers identifier '{' members_initialization_list '}'
725       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
726    | declaration_specifiers identifier '{' members_initialization_list_error '}'
727       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
728    | declaration_specifiers identifier '{' '}'
729       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), MkList()); $$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.start;}
730    ;
731
732 instantiation_named_error:
733     declaration_specifiers identifier '{' members_initialization_list_error
734       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
735 |   declaration_specifiers identifier '{' members_initialization_list error
736       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
737 |   declaration_specifiers identifier '{' members_initialization_list
738       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
739 |   declaration_specifiers identifier '{'
740       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), null); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
741 |   declaration_specifiers identifier '{' error
742       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), null);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
743    ;
744 */
745
746
747 guess_instantiation_named:
748      guess_instantiation_named_error '}'
749       { $$.loc = @$; $$.insideLoc.end = @2.start; }
750     | guess_instantiation_named_error error '}'
751       { $$.loc = @$; $$.insideLoc.end = @2.start; }
752    ;
753
754 guess_instantiation_named_error:
755     guess_declaration_specifiers identifier '{' members_initialization_list_error
756       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
757 |   guess_declaration_specifiers identifier '{' members_initialization_list error
758       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
759 |   guess_declaration_specifiers identifier '{' members_initialization_list
760       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
761 |   guess_declaration_specifiers identifier '{'
762       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), null);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
763 |   guess_declaration_specifiers identifier '{' error
764       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), null);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
765    ;
766
767 /*
768 guess_instantiation_named:
769      guess_declaration_specifiers identifier '{' members_initialization_list '}'
770       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
771    | guess_declaration_specifiers identifier '{' members_initialization_list_error '}'
772       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
773    | guess_declaration_specifiers identifier '{' '}'
774       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), MkList());  $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.start;}
775    ;
776
777 guess_instantiation_named_error:
778     guess_declaration_specifiers identifier '{' members_initialization_list_error
779       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
780 |   guess_declaration_specifiers identifier '{' members_initialization_list error
781       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
782 |   guess_declaration_specifiers identifier '{' members_initialization_list
783       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
784 |   guess_declaration_specifiers identifier '{'
785       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), null);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
786 |   guess_declaration_specifiers identifier '{' error
787       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), null);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
788    ;
789 */
790
791 external_guess_instantiation_named:
792      external_guess_declaration_specifiers identifier '{' members_initialization_list '}'
793       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
794    | external_guess_declaration_specifiers identifier '{' members_initialization_list_error '}'
795       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
796    | external_guess_declaration_specifiers identifier '{' '}'
797       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), MkList());  $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.start;}
798    ;
799
800 instantiation_unnamed:
801      instantiation_unnamed_error '}'
802       { $$.loc = @$; $$.insideLoc.end = @2.start; $$ = $1; }
803     | instantiation_unnamed_error error '}'
804       { $$.loc = @$; $$.insideLoc.end = @2.start; $$ = $1; }
805    ;
806
807 instantiation_unnamed_error:
808      strict_type '{' members_initialization_list
809       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
810 |    identifier '{' members_initialization_list
811       { Location tmpLoc = yylloc; yylloc = @1;
812       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end; FreeIdentifier($1); }
813
814 |    strict_type '{' members_initialization_list_error
815       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
816 |    strict_type '{'
817       { $$ = MkInstantiation($1, null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
818 |    strict_type '{' members_initialization_list error
819       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
820 |    strict_type '{' error
821       { $$ = MkInstantiation($1, null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end; $$.loc.end.charPos++; $$.loc.end.pos++;  }
822
823    // Undeclared class
824
825 |    identifier '{' members_initialization_list_error
826       { Location tmpLoc = yylloc; yylloc = @1;
827       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; FreeIdentifier($1); }
828 |    identifier '{'
829       { Location tmpLoc = yylloc; yylloc = @1;
830       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; FreeIdentifier($1); }
831 |    identifier '{' members_initialization_list error
832       { Location tmpLoc = yylloc; yylloc = @1;
833       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; FreeIdentifier($1); }
834 |    identifier '{' error
835       { Location tmpLoc = yylloc; yylloc = @1;
836       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end; $$.loc.end.charPos++; $$.loc.end.pos++; FreeIdentifier($1); }
837    ;
838
839 /*
840 instantiation_unnamed:
841      strict_type '{' members_initialization_list '}'
842       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; }
843    | strict_type '{' members_initialization_list error '}'
844       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @5.start; }
845    | strict_type '{' members_initialization_list_error '}'
846       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; }
847    | strict_type '{' '}'
848       { $$ = MkInstantiation($1, null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.start;}
849    | strict_type '{' error '}'
850       { $$ = MkInstantiation($1, null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start;}
851
852    // Undeclared class
853    | identifier '{' members_initialization_list '}'
854       { Location tmpLoc = yylloc; yylloc = @1;
855       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; FreeIdentifier($1); }
856    | identifier '{' members_initialization_list_error '}'
857       { Location tmpLoc = yylloc; yylloc = @1;
858       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; FreeIdentifier($1); }
859    | identifier '{' members_initialization_list error '}'
860       { yyloc = @1;
861       $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @5.start; FreeIdentifier($1); }
862    | identifier '{' '}'
863       { Location tmpLoc = yylloc; yylloc = @1;
864       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.start; FreeIdentifier($1);}
865    | identifier '{' error '}'
866       { Location tmpLoc = yylloc; yylloc = @1;
867       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; FreeIdentifier($1); }
868    ;
869
870
871 instantiation_unnamed_error:
872      strict_type '{' members_initialization_list_error
873       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
874 |    strict_type '{'
875       { $$ = MkInstantiation($1, null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
876 |    strict_type '{' members_initialization_list error
877       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
878 |    strict_type '{' error
879       { $$ = MkInstantiation($1, null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end; $$.loc.end.charPos++; $$.loc.end.pos++;  }
880
881    // Undeclared class
882
883 |    identifier '{' members_initialization_list_error
884       { Location tmpLoc = yylloc; yylloc = @1;
885       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; FreeIdentifier($1); }
886 |    identifier '{'
887       { Location tmpLoc = yylloc; yylloc = @1;
888       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; FreeIdentifier($1); }
889 |    identifier '{' members_initialization_list error
890       { Location tmpLoc = yylloc; yylloc = @1;
891       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; FreeIdentifier($1); }
892 |    identifier '{' error
893       { Location tmpLoc = yylloc; yylloc = @1;
894       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end; $$.loc.end.charPos++; $$.loc.end.pos++; FreeIdentifier($1); }
895    ;
896 */
897
898 instantiation_anon:
899      instantiation_anon_error '}'
900       { $$.loc = @$; $$.insideLoc.end = @2.start; }
901     | instantiation_anon_error error '}'
902       { $$.loc = @$; $$.insideLoc.end = @2.start; }
903    ;
904
905 instantiation_anon_error:
906      '{' members_initialization_list_error
907       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
908 |    '{' members_initialization_list error
909       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
910 |    '{' error
911       { $$ = MkInstantiation(null, null, null);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @1.end; $$.loc.end.charPos++; $$.loc.end.pos++;  }
912 |    '{'
913       { $$ = MkInstantiation(null, null, null);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @1.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
914 |    '{' members_initialization_list
915       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
916    ;
917
918 /*
919 instantiation_anon:
920      '{' members_initialization_list '}'
921       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @3.start; }
922    | '{' members_initialization_list error '}'
923       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @4.start; }
924    | '{' members_initialization_list_error '}'
925       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @3.start; }
926    | '{' '}'
927       { $$ = MkInstantiation(null, null, MkList());  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.start;}
928    | '{' error '}'
929       { $$ = MkInstantiation(null, null, MkList());  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @3.start;}
930    ;
931
932 instantiation_anon_error:
933      '{' members_initialization_list_error
934       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
935 |    '{'
936       { $$ = MkInstantiation(null, null, null);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @1.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
937 |    '{' members_initialization_list error
938       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
939 |    '{' error
940       { $$ = MkInstantiation(null, null, null);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @1.end; $$.loc.end.charPos++; $$.loc.end.pos++;  }
941    ;
942 */
943
944 default_property:
945      postfix_expression '=' initializer_condition { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; }
946    ;
947
948 default_property_error:
949      postfix_expression '=' initializer_condition_error { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = @2.end; }
950    | postfix_expression '=' error { $$ = MkMemberInitExp($1, MkInitializerAssignment(MkExpDummy())); $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = @2.end; $$.initializer.loc.end = @2.end; }
951    | postfix_expression error { $$ = MkMemberInitExp($1, null); $$.loc = @$; $$.realLoc = @$; }
952    ;
953
954 default_property_list:
955      default_property        { $$ = MkList(); ListAdd($$, $1); ((MemberInit)$$->last).loc = @$; }
956    | default_property_list ',' default_property      { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
957    | default_property_list_error ',' default_property      { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
958    ;
959
960 default_property_list_error:
961       default_property_error      { $$ = MkList(); ListAdd($$, $1); ((MemberInit)$$->last).loc = @$; }
962    | default_property_list ',' default_property_error      { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
963    | default_property_list_error ',' default_property_error      { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
964    | default_property_list error
965    ;
966
967 property_start:
968      PROPERTY property_specifiers identifier '{'
969       { $$ = MkProperty($2, null, $3, null, null); $$.loc = @$; }
970
971    | PROPERTY property_specifiers abstract_declarator identifier '{'
972       { $$ = MkProperty($2, $3, $4, null, null); $$.loc = @$; }
973
974    | PROPERTY property_specifiers '{'
975       { $$ = MkProperty($2, null, null, null, null); $$.loc = @$; }
976
977    | PROPERTY property_specifiers abstract_declarator '{'
978       { $$ = MkProperty($2, $3, null, null, null); $$.loc = @$; }
979
980    | PROPERTY error '{'
981       { $$ = MkProperty(null, null, null, null, null); $$.loc = @$; }
982    ;
983
984 property_body:
985      property_start
986    | property_body SETPROP compound_statement
987       { $1.setStmt = $3; }
988    | property_body GETPROP compound_statement
989       { $1.getStmt = $3; }
990    | property_body ISPROPSET compound_statement
991       { $1.issetStmt = $3; }
992    | property_body WATCHABLE
993       { $1.isWatchable = true; }
994    | property_body PROPERTY_CATEGORY i18n_string
995       { $1.category = $3; }
996         ;
997
998 property:
999    property_body '}' { $1.loc.end = @2.end; $$ = $1; }
1000    ;
1001
1002 class_property_start:
1003      CLASS_PROPERTY property_specifiers identifier '{'
1004       { $$ = MkProperty($2, null, $3, null, null); $$.loc = @$; }
1005
1006    | CLASS_PROPERTY property_specifiers abstract_declarator identifier '{'
1007       { $$ = MkProperty($2, $3, $4, null, null); $$.loc = @$; }
1008
1009    | CLASS_PROPERTY property_specifiers '{'
1010       { $$ = MkProperty($2, null, null, null, null); $$.loc = @$; }
1011
1012    | CLASS_PROPERTY property_specifiers abstract_declarator '{'
1013       { $$ = MkProperty($2, $3, null, null, null); $$.loc = @$; }
1014
1015    | CLASS_PROPERTY error '{'
1016       { $$ = MkProperty(null, null, null, null, null); $$.loc = @$; }
1017    ;
1018
1019 class_property_body:
1020      class_property_start
1021    | class_property_body SETPROP compound_statement
1022       { $1.setStmt = $3; }
1023    | class_property_body GETPROP compound_statement
1024       { $1.getStmt = $3; }
1025         ;
1026
1027 class_property:
1028    class_property_body '}' { $1.loc.end = @2.end; }
1029    ;
1030
1031 watch_property_list:
1032           identifier
1033       { $$ = MkListOne($1); }
1034         | watch_property_list identifier
1035       { ListAdd($1, $2); }
1036         ;
1037
1038 property_watch:
1039           watch_property_list compound_statement
1040       { $$ = MkPropertyWatch($1, $2); }
1041         | DELETE compound_statement
1042       { $$ = MkDeleteWatch($2); }
1043         ;
1044
1045 property_watch_list:
1046           property_watch
1047       { $$ = MkListOne($1); }
1048         | property_watch_list property_watch
1049       { ListAdd($1, $2); }
1050         ;
1051
1052 self_watch_definition:
1053         WATCH '(' watch_property_list ')' compound_statement
1054       { $$ = MkPropertyWatch($3, $5); }
1055         ;
1056
1057 watch_definition:
1058           WATCH '(' assignment_expression ')' '{' property_watch_list '}'
1059         { $$ = MkWatchStmt(null, $3, $6); }
1060         | assignment_expression '.' WATCH '(' assignment_expression ')' '{' property_watch_list '}'
1061         { $$ = MkWatchStmt($1, $5, $8); }
1062         ;
1063
1064 stopwatching:
1065           STOPWATCHING '(' assignment_expression ',' watch_property_list ')'
1066         { $$ = MkStopWatchingStmt(null, $3, $5); }
1067         | assignment_expression '.' STOPWATCHING '(' assignment_expression ',' watch_property_list ')'
1068         { $$ = MkStopWatchingStmt($1, $5, $7); }
1069         | STOPWATCHING '(' assignment_expression ')'
1070         { $$ = MkStopWatchingStmt(null, $3, null); }
1071         | assignment_expression '.' STOPWATCHING '(' assignment_expression ')'
1072         { $$ = MkStopWatchingStmt($1, $5, null); }
1073         ;
1074
1075 firewatchers:
1076           FIREWATCHERS
1077         { $$ = MkFireWatchersStmt(null, null); }
1078         | FIREWATCHERS watch_property_list
1079         { $$ = MkFireWatchersStmt(null, $2); }
1080         | postfix_expression '.' FIREWATCHERS
1081         { $$ = MkFireWatchersStmt($1, null); }
1082         | assignment_expression '.' FIREWATCHERS watch_property_list
1083         { $$ = MkFireWatchersStmt($1, $4); }
1084         ;
1085
1086 struct_declaration:
1087      struct_declaration_error ';' { $$ = $1; $$.loc.end = @2.end; }
1088    | default_property_list ';'     { $$ = MkClassDefDefaultProperty($1); if($1->last) ((MemberInit)$1->last).loc.end = @2.start; $$.loc = @$; }
1089    | class_function_definition                                       { $$ = MkClassDefFunction($1); $$.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1090    | property                       { $$ = MkClassDefProperty($1); $$.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1091    | member_access class_function_definition                                       { $$ = MkClassDefFunction($2); $$.loc = @$; $$.memberAccess = $1; }
1092    | member_access property                       { $$ = MkClassDefProperty($2); $$.loc = @$; $$.memberAccess = $1; }
1093    | class_property                 { $$ = MkClassDefClassProperty($1); $$.loc = @$; }
1094    | WATCHABLE { $$ = null; deleteWatchable = true; }
1095    | CLASS_NO_EXPANSION             { $$ = MkClassDefNoExpansion(); }
1096    | CLASS_FIXED                    { $$ = MkClassDefFixed(); }
1097    | CLASS_PROPERTY '(' identifier ')' '=' initializer_condition ';' { $$ = MkClassDefClassPropertyValue($3, $6); $$.loc = @$; }
1098
1099    | ';' { $$ = null; }
1100    | member_access ':' { memberAccessStack[defaultMemberAccess] = $1; if(defaultMemberAccess == 0) { $$ = MkClassDefMemberAccess(); $$.memberAccess = $1; $$.loc = @$; } else $$ = null; }
1101
1102    | member_access '(' identifier ')'     { $$ = MkClassDefAccessOverride($1, $3); $$.loc = @$; }
1103         ;
1104
1105 struct_declaration_error:
1106      class_function_definition_error { $$ = MkClassDefFunction($1); $$.loc = $1.loc;  $$.loc.end.charPos++; $$.loc.end.pos++; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1107
1108 // Moved all these in here without the ';'
1109    | guess_declaration_specifiers                                { $$ = MkClassDefDeclaration(MkStructDeclaration($1, null, null)); $$.decl.loc = @$; $$.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1110         | guess_declaration_specifiers struct_declarator_list          { $$ = MkClassDefDeclaration(MkStructDeclaration($1, $2, null)); $$.decl.loc = @$; $$.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1111         | member_access guess_declaration_specifiers struct_declarator_list         { $$ = MkClassDefDeclaration(MkStructDeclaration($2, $3, null)); $$.decl.loc = @$; $$.loc = @$; $$.memberAccess = $1; }
1112    | member_access guess_declaration_specifiers                                { $$ = MkClassDefDeclaration(MkStructDeclaration($2, null, null)); $$.decl.loc = @$; $$.loc = @$; $$.memberAccess = $1; }
1113    | member_access instantiation_unnamed                                       { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = @$; $$.memberAccess = $1; }
1114    | member_access guess_instantiation_named                                   { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = @$; $$.memberAccess = $1; }
1115    | CLASS_DATA guess_declaration_specifiers struct_declarator_list { $$ = MkClassDefClassData(MkStructDeclaration($2, $3, null)); $$.decl.loc = @$; $$.loc = @$; }
1116    | self_watch_definition      { $$ = MkClassDefPropertyWatch($1); $$.loc = @$; }
1117    | CLASS_DESIGNER identifier { $$ = MkClassDefDesigner($2.string); FreeIdentifier($2); }
1118    | CLASS_DESIGNER strict_type { $$ = MkClassDefDesigner($2.name); FreeSpecifier($2); }
1119    | CLASS_DEFAULT_PROPERTY identifier { $$ = MkClassDefDesignerDefaultProperty($2); }
1120    | instantiation_unnamed                                       { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = @$; $$.decl.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1121    | guess_instantiation_named                                   { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = @$; $$.decl.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1122    | default_property_list     { $$ = MkClassDefDefaultProperty($1); if($1->last) ((MemberInit)$1->last).loc.end = @1.end; $$.loc = @$; }
1123
1124    | guess_instantiation_named_error error { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = $1.loc; $$.decl.loc = $$.loc;  $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1125    | instantiation_unnamed_error error { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = $1.loc; $$.decl.loc = $$.loc;  $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1126 //   | guess_instantiation_named { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = $1.loc; $$.decl.loc = $$.loc;  $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1127 //   | instantiation_unnamed { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = $1.loc; $$.decl.loc = $$.loc;  $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1128
1129    | member_access class_function_definition_error { $$ = MkClassDefFunction($2); $$.loc = @$;  $$.loc.end.charPos++; $$.loc.end.pos++; $$.memberAccess = $1; }
1130    | member_access guess_instantiation_named_error error { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = $$.loc; $$.memberAccess = $1; }
1131    | member_access instantiation_unnamed_error error { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = $$.loc; $$.memberAccess = $1; }
1132 //   | member_access guess_instantiation_named { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = $$.loc; $$.memberAccess = $1; }
1133 //   | member_access instantiation_unnamed { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = $$.loc; $$.memberAccess = $1; }
1134
1135    | default_property_list_error { $$ = MkClassDefDefaultProperty($1); $$.loc = @$;  $$.loc.end.charPos++; $$.loc.end.pos++; }
1136    ;
1137
1138 struct_declaration_list:
1139           struct_declaration { $$ = MkList(); ListAdd($$, $1); }
1140         | struct_declaration_list struct_declaration   { $$ = $1; ListAdd($1, $2); }
1141    | struct_declaration_list_error struct_declaration   { $$ = $1; ListAdd($1, $2); }
1142         ;
1143
1144 struct_declaration_list_error:
1145      struct_declaration_error { yyerror(); $$ = MkList(); ListAdd($$, $1); }
1146    | struct_declaration_list error
1147    | struct_declaration_list_error error
1148    | struct_declaration_list struct_declaration_error { yyerror(); $$ = $1; ListAdd($$, $2); }
1149    | struct_declaration_list_error struct_declaration_error { $$ = $1; ListAdd($$, $2); }
1150         ;
1151
1152 template_datatype:
1153      guess_declaration_specifiers { $$ = MkTemplateDatatype($1, null); }
1154    | guess_declaration_specifiers abstract_declarator { $$ = MkTemplateDatatype($1, $2); }
1155 //   | identifier { $$ = MkTemplateDatatype(MkListOne(MkSpecifierName($1.string)), null); FreeIdentifier($1); }
1156    ;
1157
1158 template_type_argument:
1159 //     template_datatype { $$ = MkTemplateTypeArgument($1); }
1160
1161 //    Explicitly copied the rules here to handle:
1162 //      ast.ec:  Map<List<Location>> intlStrings { };
1163 //          vs
1164 //      LinkList.ec:   class LinkList<bool circ = false>
1165
1166      guess_declaration_specifiers { $$ = MkTemplateTypeArgument(MkTemplateDatatype($1, null)); }
1167    | guess_declaration_specifiers abstract_declarator { $$ = MkTemplateTypeArgument(MkTemplateDatatype($1, $2)); }
1168    ;
1169
1170 template_type_parameter:
1171      CLASS identifier { $$ = MkTypeTemplateParameter($2, null, null); }
1172    | CLASS identifier '=' template_type_argument { $$ = MkTypeTemplateParameter($2, null, $4); }
1173    | CLASS identifier ':' template_datatype { $$ = MkTypeTemplateParameter($2, $4, null); }
1174    | CLASS identifier ':' template_datatype '=' template_type_argument { $$ = MkTypeTemplateParameter($2, $4, $6); }
1175    | CLASS base_strict_type_name { $$ = MkTypeTemplateParameter(MkIdentifier($2), null, null); delete $2; }
1176    | CLASS base_strict_type_name '=' template_type_argument { $$ = MkTypeTemplateParameter(MkIdentifier($2), null, $4); }
1177    | CLASS base_strict_type_name ':' template_datatype { $$ = MkTypeTemplateParameter(MkIdentifier($2), $4, null); }
1178    | CLASS base_strict_type_name ':' template_datatype '=' template_type_argument { $$ = MkTypeTemplateParameter(MkIdentifier($2), $4, $6); }
1179    ;
1180
1181 template_identifier_argument:
1182      identifier { $$ = MkTemplateIdentifierArgument($1); }
1183    ;
1184
1185 template_identifier_parameter:
1186      identifier                                  { $$ = MkIdentifierTemplateParameter($1, dataMember, null); }
1187    | identifier '=' template_identifier_argument { $$ = MkIdentifierTemplateParameter($1, dataMember, $3); }
1188    ;
1189
1190 template_expression_argument:
1191      shift_expression /*constant_expression*/ { $$ = MkTemplateExpressionArgument($1); }
1192    ;
1193
1194 template_expression_parameter:
1195 /*
1196      template_datatype identifier     { $$ = MkExpressionTemplateParameter($2, $1, null); }
1197    | template_datatype identifier '=' template_expression_argument    { $$ = MkExpressionTemplateParameter($2, $1, $4); }
1198 */
1199      guess_declaration_specifiers identifier '=' template_expression_argument    { $$ = MkExpressionTemplateParameter($2, MkTemplateDatatype($1, null), $4); }
1200    | guess_declaration_specifiers abstract_declarator identifier '=' template_expression_argument    { $$ = MkExpressionTemplateParameter($3, MkTemplateDatatype($1, $2), $5); }
1201    ;
1202
1203 template_parameter:
1204      template_type_parameter
1205    | template_identifier_parameter
1206    | template_expression_parameter
1207    ;
1208
1209 template_parameters_list:
1210      template_parameter                               { $$ = MkList(); ListAdd($$, $1); }
1211    | template_parameters_list ',' template_parameter  { $$ = $1; ListAdd($1, $3); }
1212    ;
1213
1214 template_argument:
1215      template_expression_argument
1216    | template_identifier_argument
1217    | template_type_argument
1218    | identifier '=' template_expression_argument   { $$ = $3; $$.name = $1; $$.loc = @$; }
1219    | identifier '=' template_identifier_argument   { $$ = $3; $$.name = $1; $$.loc = @$; }
1220    | identifier '=' template_type_argument         { $$ = $3; $$.name = $1; $$.loc = @$; }
1221    /*| template_datatype '=' template_expression_argument
1222    {
1223       $$ = $3;
1224       if($1.specifiers && $1.specifiers->first)
1225       {
1226          Specifier spec = $1.specifiers->first;
1227          if(spec.type == nameSpecifier)
1228             $$.name = MkIdentifier(spec.name);
1229       }
1230       FreeTemplateDataType($1);
1231       $$.loc = @$;
1232    }
1233    | template_datatype '=' template_identifier_argument
1234    {
1235       $$ = $3;
1236       if($1.specifiers && $1.specifiers->first)
1237       {
1238          Specifier spec = $1.specifiers->first;
1239          if(spec.type == nameSpecifier)
1240             $$.name = MkIdentifier(spec.name);
1241       }
1242       FreeTemplateDataType($1);
1243       $$.loc = @$;
1244    }
1245    | template_datatype '=' template_type_argument
1246    {
1247       $$ = $3;
1248       if($1.specifiers && $1.specifiers->first)
1249       {
1250          Specifier spec = $1.specifiers->first;
1251          if(spec.type == nameSpecifier)
1252             $$.name = MkIdentifier(spec.name);
1253       }
1254       FreeTemplateDataType($1);
1255       $$.loc = @$;
1256    }*/
1257    ;
1258
1259 template_arguments_list:
1260      template_argument                                { $$ = MkList(); ListAdd($$, $1); }
1261    | template_arguments_list ',' template_argument    { $$ = $1; ListAdd($1, $3); }
1262    ;
1263
1264 class_entry:
1265    CLASS
1266    {
1267       if(curContext != globalContext)
1268          PopContext(curContext);
1269       $$ = PushContext();
1270    };
1271
1272 class_decl:
1273      class_entry identifier { (void)$1; $$ = DeclClassAddNameSpace($2._class, $2.string); FreeIdentifier($2); $$.nameLoc = @2; memberAccessStack[++defaultMemberAccess] = privateAccess; }
1274    | class_entry base_strict_type
1275    {
1276       (void)$1; $$ = DeclClass($2.nsSpec, $2.name);
1277       $$.nameLoc = @2;
1278       FreeSpecifier($2);
1279       ++defaultMemberAccess;
1280       memberAccessStack[defaultMemberAccess] = privateAccess;
1281    }
1282    | identifier class_entry identifier { (void)$2; $$ = DeclClassAddNameSpace($3._class, $3.string); FreeIdentifier($1); FreeIdentifier($3); $$.nameLoc = @3; $$.isRemote = true; memberAccessStack[++defaultMemberAccess] = privateAccess; }
1283    | identifier class_entry base_strict_type { (void)$2; $$ = DeclClass($3.nsSpec, $3.name); FreeIdentifier($1); $$.nameLoc = @3; $$.isRemote = true; FreeSpecifier($3); memberAccessStack[++defaultMemberAccess] = privateAccess; }
1284
1285    | class_entry identifier '<' template_parameters_list '>' { (void)$1; $$ = DeclClassAddNameSpace($2._class, $2.string); $$.templateParams = $4; FreeIdentifier($2); $$.nameLoc = @2; memberAccessStack[++defaultMemberAccess] = privateAccess; }
1286    | class_entry base_strict_type '<' template_parameters_list '>'
1287    {
1288       (void)$1; $$ = DeclClass($2.nsSpec, $2.name);
1289       $$.templateParams = $4;
1290       $$.nameLoc = @2;
1291       FreeSpecifier($2);
1292       ++defaultMemberAccess;
1293       memberAccessStack[defaultMemberAccess] = privateAccess;
1294    }
1295    | identifier class_entry identifier '<' template_parameters_list '>' { (void)$2; $$ = DeclClassAddNameSpace($3._class, $3.string); $$.templateParams = $5; FreeIdentifier($1); FreeIdentifier($3); $$.nameLoc = @3; $$.isRemote = true; memberAccessStack[++defaultMemberAccess] = privateAccess; }
1296    | identifier class_entry base_strict_type '<' template_parameters_list '>' { (void)$2; $$ = DeclClass($3.nsSpec, $3.name); $$.templateParams = $5; FreeIdentifier($1); $$.nameLoc = @3; $$.isRemote = true; FreeSpecifier($3); memberAccessStack[++defaultMemberAccess] = privateAccess; }
1297    ;
1298
1299 class:
1300      class_error '}'
1301       {
1302          $$.loc = @$;
1303          $$ = $1;
1304       }
1305
1306    // Added this for unit classes...
1307         | class_head ';'
1308       {
1309          $$ = $1; $$.definitions = MkList(); $$.blockStart = @2;  $$.loc = @$;
1310          POP_DEFAULT_ACCESS
1311          PopContext(curContext);
1312       }
1313
1314         | class_decl '{' '}'
1315       {
1316          $$ = MkClass($1, null, MkList()); $$.blockStart = @2;  $$.loc = @$;
1317          POP_DEFAULT_ACCESS
1318          PopContext(curContext);
1319       }
1320         | class_head '{' '}'
1321       {
1322          $$ = $1; $$.definitions = MkList(); $$.blockStart = @2;  $$.loc = @$;
1323          POP_DEFAULT_ACCESS
1324          PopContext(curContext);
1325       }
1326
1327         | class_entry identifier ';'
1328       {
1329          (void)$1; $$ = MkClass(DeclClassAddNameSpace($2._class, $2.string), null, null); FreeIdentifier($2);
1330          POP_DEFAULT_ACCESS
1331          PopContext(curContext);
1332       }
1333         | class_entry type ';'
1334       {
1335          (void)$1; $$ = MkClass(DeclClass($2.nsSpec, $2.name), null, null); FreeSpecifier($2);
1336          POP_DEFAULT_ACCESS
1337          PopContext(curContext);
1338       }
1339    ;
1340
1341 class_head:
1342         class_decl ':' inheritance_specifiers
1343       {
1344          $$ = MkClass($1, $3, null);
1345       }
1346    ;
1347
1348 class_error:
1349          class_decl '{' struct_declaration_list_error
1350       {
1351          $$ = MkClass($1, null, $3); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2; $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;
1352          POP_DEFAULT_ACCESS
1353          PopContext(curContext);
1354       }
1355         | class_head '{' struct_declaration_list_error
1356       {
1357          $$ = $1; $$.definitions = $3; $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;
1358          POP_DEFAULT_ACCESS
1359          PopContext(curContext);
1360       }
1361         | class_decl '{' struct_declaration_list
1362       {
1363          $$ = MkClass($1, null, $3); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2; $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;
1364          POP_DEFAULT_ACCESS
1365          PopContext(curContext);
1366       }
1367         | class_head '{' struct_declaration_list
1368       {
1369          $$ = $1; $$.definitions = $3; $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;
1370          POP_DEFAULT_ACCESS
1371          PopContext(curContext);
1372       }
1373         | class_decl '{' error
1374       {
1375          $$ = MkClass($1, null, MkList()); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;
1376          POP_DEFAULT_ACCESS
1377          PopContext(curContext);
1378       }
1379         | class_head '{' error
1380       {
1381          $$ = $1; $$.definitions = MkList(); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;
1382          POP_DEFAULT_ACCESS
1383          PopContext(curContext);
1384       }
1385    ;
1386
1387 /**** EXPRESSIONS ********************************************************************/
1388
1389 identifier:
1390    IDENTIFIER
1391       { $$ = MkIdentifier(yytext); $$.loc = @1; }
1392    ;
1393
1394 primary_expression:
1395      simple_primary_expression
1396         | '(' expression ')'
1397       { $$ = MkExpBrackets($2); $$.loc = @$; }
1398    ;
1399
1400 i18n_string:
1401           string_literal     { $$ = MkExpString($1); delete $1; $$.loc = @$; }
1402    | '$' string_literal     { $$ = MkExpIntlString($2, null); delete $2; $$.loc = @$; }
1403    | '$' string_literal '.' string_literal     { $$ = MkExpIntlString($4, $2); delete $2; delete $4; $$.loc = @$; }
1404    ;
1405
1406 constant:
1407    CONSTANT { $$ = MkExpConstant(yytext); $$.loc = @$; }
1408    ;
1409
1410 simple_primary_expression:
1411           identifier         { $$ = MkExpIdentifier($1); $$.loc = @$; }
1412    | instantiation_unnamed      { $$ = MkExpInstance($1); $$.loc = @$; }
1413    | EXTENSION '(' compound_statement ')'    { $$ = MkExpExtensionCompound($3); $$.loc = @$; }
1414    | EXTENSION '(' expression ')'    { $$ = MkExpExtensionExpression($3); $$.loc = @$; }
1415    | EXTENSION '(' type_name ')' initializer     { $$ = MkExpExtensionInitializer($3, $5); $$.loc = @$; }
1416    | EXTENSION '(' type_name ')' '(' type_name ')' initializer     { $$ = MkExpExtensionInitializer($3, MkInitializerAssignment(MkExpExtensionInitializer($6, $8))); $$.loc = @$; }
1417    | constant identifier
1418    {
1419       char * constant = $1.constant;
1420       int len = strlen(constant);
1421       if(constant[len-1] == '.')
1422       {
1423          constant[len-1] = 0;
1424          $$ = MkExpMember($1, $2);
1425          $$.loc = @$;
1426       }
1427       else
1428          yyerror();
1429    }
1430         | constant { $$ = $1; }
1431    | i18n_string
1432    | WIDE_STRING_LITERAL { $$ = MkExpWideString(yytext); $$.loc = @$; }
1433    | '(' ')' { Expression exp = MkExpDummy(); exp.loc.start = @1.end; exp.loc.end = @2.start; $$ = MkExpBrackets(MkListOne(exp)); $$.loc = @$; yyerror(); }
1434    | NEWOP new_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpNew(MkTypeName($2,$3), $5); $$.loc = @$; }
1435    | NEWOP new_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpNew(MkTypeName($2,$3), $5); $$.loc = @$; }
1436    | NEWOP new_specifiers '[' constant_expression ']' { $$ = MkExpNew(MkTypeName($2,null), $4); $$.loc = @$; }
1437    | NEWOP new_specifiers '[' constant_expression_error ']' { $$ = MkExpNew(MkTypeName($2,null), $4); $$.loc = @$; }
1438    | NEW0OP new_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpNew0(MkTypeName($2,$3), $5); $$.loc = @$; }
1439    | NEW0OP new_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpNew0(MkTypeName($2,$3), $5); $$.loc = @$; }
1440    | NEW0OP new_specifiers '[' constant_expression ']' { $$ = MkExpNew0(MkTypeName($2,null), $4); $$.loc = @$; }
1441    | NEW0OP new_specifiers '[' constant_expression_error ']' { $$ = MkExpNew0(MkTypeName($2,null), $4); $$.loc = @$; }
1442    | RENEW constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpRenew($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1443    | RENEW constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpRenew($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1444    | RENEW constant_expression renew_specifiers '[' constant_expression ']' { $$ = MkExpRenew($2, MkTypeName($3,null), $5); $$.loc = @$; }
1445    | RENEW constant_expression renew_specifiers '[' constant_expression_error ']' { $$ = MkExpRenew($2, MkTypeName($3,null), $5); $$.loc = @$; }
1446    | RENEW0 constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpRenew0($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1447    | RENEW0 constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpRenew0($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1448    | RENEW0 constant_expression renew_specifiers '[' constant_expression ']' { $$ = MkExpRenew0($2, MkTypeName($3,null), $5); $$.loc = @$; }
1449    | RENEW0 constant_expression renew_specifiers '[' constant_expression_error ']' { $$ = MkExpRenew0($2, MkTypeName($3,null), $5); $$.loc = @$; }
1450    | CLASS '(' declaration_specifiers ')' { $$ = MkExpClass($3, null); $$.loc = @$; }
1451    | CLASS '(' declaration_specifiers abstract_declarator ')' { $$ = MkExpClass($3, $4); $$.loc = @$; }
1452    | CLASS '(' identifier ')' { $$ = MkExpClass(MkListOne(MkSpecifierName($3.string)), null); FreeIdentifier($3); $$.loc = @$; }
1453    | VAARG '(' assignment_expression ',' type_name ')' { $$ = MkExpVaArg($3, $5); $$.loc = @$; }
1454
1455    | CLASS_DATA '(' identifier ')' { $$ = MkExpClassData($3); $$.loc = @$; }
1456    | database_open
1457    | dbfield
1458    | dbindex
1459    | dbtable
1460
1461    | '[' argument_expression_list /*expression*/ ']' { $$ = MkExpArray($2); $$.loc = @$; }
1462    | '[' ']' { $$ = MkExpArray(null); $$.loc = @$; }
1463    ;
1464
1465 anon_instantiation_expression:
1466    instantiation_anon            { $$ = MkExpInstance($1); $$.loc = @$; }
1467    ;
1468
1469 anon_instantiation_expression_error:
1470    instantiation_anon_error error           { $$ = MkExpInstance($1); $$.loc = @$; }
1471    ;
1472
1473 primary_expression_error:
1474           '(' expression  { yyerror(); $$ = MkExpBrackets($2); $$.loc = @$; }
1475    | '(' expression_error { $$ = MkExpBrackets($2); $$.loc = @$; }
1476    ;
1477
1478 postfix_expression:
1479           primary_expression
1480
1481    | postfix_expression '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1482    | postfix_expression '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1483         | postfix_expression '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1484         | postfix_expression '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; }
1485    | postfix_expression '(' argument_expression_list_error ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; if($3->last) ((Expression)$3->last).loc.end = @4.start; }
1486         | postfix_expression '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1487         | postfix_expression PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1488         | postfix_expression INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1489         | postfix_expression DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1490
1491    | postfix_expression_error '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1492    | postfix_expression_error '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1493         | postfix_expression_error '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1494         | postfix_expression_error '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end;$$.loc = @$; }
1495         | postfix_expression_error '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1496         | postfix_expression_error PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1497         | postfix_expression_error INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1498         | postfix_expression_error DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1499 ;
1500
1501 /*simple_postfix_expression:
1502           simple_primary_expression
1503
1504    | simple_postfix_expression '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1505    | simple_postfix_expression '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1506         | simple_postfix_expression '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1507         | simple_postfix_expression '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; }
1508    | simple_postfix_expression '(' argument_expression_list_error ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; if($3->last) ((Expression)$3->last).loc.end = @4.start; }
1509         | simple_postfix_expression '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1510         | simple_postfix_expression PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1511         | simple_postfix_expression INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1512         | simple_postfix_expression DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1513
1514    | simple_postfix_expression_error '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1515    | simple_postfix_expression_error '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1516         | simple_postfix_expression_error '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1517         | simple_postfix_expression_error '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end;$$.loc = @$; }
1518         | simple_postfix_expression_error '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1519         | simple_postfix_expression_error PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1520         | simple_postfix_expression_error INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1521         | simple_postfix_expression_error DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1522 ;*/
1523
1524 argument_expression_list:
1525           assignment_expression          { $$ = MkList(); ListAdd($$, $1); }
1526    | anon_instantiation_expression  { $$ = MkList(); ListAdd($$, $1); }
1527         | argument_expression_list ',' assignment_expression   { $$ = $1; ListAdd($1, $3);  }
1528    | argument_expression_list ',' anon_instantiation_expression   { $$ = $1; ListAdd($1, $3);  }
1529         ;
1530
1531 argument_expression_list_error:
1532      assignment_expression_error    { $$ = MkList(); ListAdd($$, $1); }
1533    | anon_instantiation_expression_error    { $$ = MkList(); ListAdd($$, $1); }
1534    | argument_expression_list ',' assignment_expression_error  { $$ = $1; ListAdd($1, $3);  }
1535    | argument_expression_list ',' anon_instantiation_expression_error  { $$ = $1; ListAdd($1, $3);  }
1536    | argument_expression_list ',' { Expression exp = MkExpDummy(); yyerror(); exp.loc.start = @2.end; exp.loc.end = @2.end; $$ = $1; ListAdd($1, exp); }
1537         ;
1538
1539 common_unary_expression:
1540           INC_OP unary_expression           { $$ = MkExpOp(null, INC_OP, $2); $$.loc = @$; }
1541         | DEC_OP unary_expression           { $$ = MkExpOp(null, DEC_OP, $2); $$.loc = @$; }
1542         | unary_operator cast_expression    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1543    | unary_operator anon_instantiation_expression    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1544         //| SIZEOF '(' unary_expression ')'         { $$ = MkExpOp(null, SIZEOF, $3); $$.loc = @$; }
1545    | SIZEOF unary_expression           { $$ = MkExpOp(null, SIZEOF, $2); $$.loc = @$; }
1546    | SIZEOF '(' guess_type_name ')'          { $$ = MkExpTypeSize($3); $$.loc = @$; }
1547    | SIZEOF '(' CLASS type ')'          { $$ = MkExpClassSize($4); $$.loc = @$; }
1548    | SIZEOF '(' CLASS guess_type ')'          { $$ = MkExpClassSize($4); $$.loc = @$; }
1549
1550         //| ALIGNOF '(' unary_expression ')'         { $$ = MkExpOp(null, ALIGNOF, $3); $$.loc = @$; }
1551    | ALIGNOF unary_expression           { $$ = MkExpOp(null, ALIGNOF, $2); $$.loc = @$; }
1552    | ALIGNOF '(' guess_type_name ')'          { $$ = MkExpTypeAlign($3); $$.loc = @$; }
1553
1554    | BUILTIN_OFFSETOF '(' guess_type_name ',' identifier ')'      { $$ = MkExpOffsetOf($3, $5); $$.loc = @$; }
1555         ;
1556
1557 unary_expression:
1558        common_unary_expression
1559           | postfix_expression
1560         ;
1561 /*
1562 ?:
1563      common_unary_expression
1564         | simple_postfix_expression
1565         ;
1566 */
1567 unary_operator:
1568           '&'     { $$ = '&'; }
1569         | '*'     { $$ = '*'; }
1570         | '+'     { $$ = '+'; }
1571         | '-'     { $$ = '-'; }
1572         | '~'     { $$ = '~'; }
1573         | '!'     { $$ = '!'; }
1574    | DELETE  { $$ = DELETE; }
1575    | _INCREF  { $$ = _INCREF; }
1576         ;
1577
1578 cast_expression:
1579        unary_expression
1580         | '(' type_name ')' cast_expression    { $$ = MkExpCast($2, $4); $$.loc = @$; }
1581         ;
1582
1583 multiplicative_expression:
1584           cast_expression
1585         | multiplicative_expression '*' cast_expression { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
1586         | multiplicative_expression '/' cast_expression { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
1587         | multiplicative_expression '%' cast_expression { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
1588         | multiplicative_expression_error '*' cast_expression { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
1589         | multiplicative_expression_error '/' cast_expression { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
1590         | multiplicative_expression_error '%' cast_expression { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
1591         ;
1592
1593 additive_expression:
1594           multiplicative_expression
1595         | additive_expression '+' multiplicative_expression  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
1596         | additive_expression '-' multiplicative_expression  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
1597         | additive_expression_error '+' multiplicative_expression  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
1598         | additive_expression_error '-' multiplicative_expression  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
1599         ;
1600
1601 shift_expression:
1602           additive_expression
1603         | shift_expression LEFT_OP additive_expression  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
1604         | shift_expression RIGHT_OP additive_expression { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
1605         | shift_expression_error LEFT_OP additive_expression  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
1606         | shift_expression_error RIGHT_OP additive_expression { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
1607         ;
1608
1609 relational_expression_smaller_than:
1610    relational_expression '<'
1611    {
1612       $$ = $1;
1613       skipErrors = true;
1614    }
1615    ;
1616
1617 relational_expression:
1618           shift_expression
1619         | relational_expression_smaller_than /*relational_expression '<' */ shift_expression    { skipErrors = false; $$ = MkExpOp($1, '<', $2/*$3*/); $$.loc = @$; }
1620         | relational_expression '>' shift_expression    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
1621         | relational_expression LE_OP shift_expression  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
1622         | relational_expression GE_OP shift_expression  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
1623         | relational_expression_error '<' shift_expression    { $$ = MkExpOp($1, '<', $3); $$.loc = @$; }
1624         | relational_expression_error '>' shift_expression    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
1625         | relational_expression_error LE_OP shift_expression  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
1626         | relational_expression_error GE_OP shift_expression  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
1627         ;
1628
1629 equality_expression
1630         : relational_expression
1631         | equality_expression EQ_OP relational_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1632         | equality_expression NE_OP relational_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1633         | equality_expression_error EQ_OP relational_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1634         | equality_expression_error NE_OP relational_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1635
1636         | equality_expression EQ_OP anon_instantiation_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1637         | equality_expression NE_OP anon_instantiation_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1638         | equality_expression_error EQ_OP anon_instantiation_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1639         | equality_expression_error NE_OP anon_instantiation_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1640         ;
1641
1642 and_expression
1643         : equality_expression
1644         | and_expression '&' equality_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1645         | and_expression_error '&' equality_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1646
1647         | and_expression '&' anon_instantiation_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1648         | and_expression_error '&' anon_instantiation_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1649         ;
1650
1651 exclusive_or_expression
1652         : and_expression
1653         | exclusive_or_expression '^' and_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1654         | exclusive_or_expression_error '^' and_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1655
1656         | exclusive_or_expression '^' anon_instantiation_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1657         | exclusive_or_expression_error '^' anon_instantiation_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1658         ;
1659
1660 inclusive_or_expression
1661         : exclusive_or_expression
1662         | inclusive_or_expression '|' exclusive_or_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1663         | inclusive_or_expression_error '|' exclusive_or_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1664
1665         | inclusive_or_expression '|' anon_instantiation_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1666         | inclusive_or_expression_error '|' anon_instantiation_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1667         ;
1668
1669 logical_and_expression
1670         : inclusive_or_expression
1671         | logical_and_expression AND_OP inclusive_or_expression  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
1672         | logical_and_expression_error AND_OP inclusive_or_expression  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
1673         ;
1674
1675 logical_or_expression
1676         : logical_and_expression
1677         | logical_or_expression OR_OP logical_and_expression     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
1678         | logical_or_expression_error OR_OP logical_and_expression     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
1679         ;
1680
1681 conditional_expression
1682         : logical_or_expression
1683         | logical_or_expression '?' expression ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1684    | logical_or_expression '?' expression_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1685         | logical_or_expression_error '?' expression ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1686    | logical_or_expression_error '?' expression_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1687
1688         | logical_or_expression '?' expression_anon_inst ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1689    | logical_or_expression '?' expression_anon_inst_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1690         | logical_or_expression_error '?' expression_anon_inst ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1691    | logical_or_expression_error '?' expression_anon_inst_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1692
1693         | logical_or_expression '?' expression ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1694    | logical_or_expression '?' expression_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1695         | logical_or_expression_error '?' expression ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1696    | logical_or_expression_error '?' expression_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1697
1698         | logical_or_expression '?' expression_anon_inst ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1699    | logical_or_expression '?' expression_anon_inst_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1700         | logical_or_expression_error '?' expression_anon_inst ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1701    | logical_or_expression_error '?' expression_anon_inst_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1702         ;
1703
1704 assignment_expression:
1705           conditional_expression
1706         | unary_expression assignment_operator assignment_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1707    | unary_expression_error assignment_operator assignment_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1708         | conditional_expression assignment_operator assignment_expression   { Compiler_Error($"l-value expected\n"); $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1709    | conditional_expression_error assignment_operator assignment_expression   { Compiler_Error($"l-value expected\n"); $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1710
1711         | unary_expression assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1712    | unary_expression_error assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1713         | conditional_expression assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1714    | conditional_expression_error assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1715         ;
1716
1717 assignment_operator:
1718           '='                   { $$ = '='; }
1719         | MUL_ASSIGN            { $$ = MUL_ASSIGN; }
1720         | DIV_ASSIGN            { $$ = DIV_ASSIGN; }
1721         | MOD_ASSIGN            { $$ = MOD_ASSIGN; }
1722         | ADD_ASSIGN            { $$ = ADD_ASSIGN; }
1723         | SUB_ASSIGN            { $$ = SUB_ASSIGN; }
1724         | LEFT_ASSIGN           { $$ = LEFT_ASSIGN; }
1725         | RIGHT_ASSIGN          { $$ = RIGHT_ASSIGN; }
1726         | AND_ASSIGN            { $$ = AND_ASSIGN; }
1727         | XOR_ASSIGN            { $$ = XOR_ASSIGN; }
1728         | OR_ASSIGN             { $$ = OR_ASSIGN; }
1729         ;
1730
1731 expression:
1732    assignment_expression                 { $$ = MkList(); ListAdd($$, $1); }
1733         | expression ',' assignment_expression  { $$ = $1; ListAdd($1, $3); }
1734    | expression_error ',' assignment_expression  { $$ = $1; ListAdd($1, $3); }
1735    | expression_error  ')'
1736         ;
1737
1738 expression_anon_inst:
1739      anon_instantiation_expression                 { $$ = MkList(); ListAdd($$, $1); }
1740    | expression ',' anon_instantiation_expression  { $$ = $1; ListAdd($1, $3); }
1741         | expression_error ',' anon_instantiation_expression  { $$ = $1; ListAdd($1, $3); }
1742    ;
1743
1744 postfix_expression_error:
1745    primary_expression_error
1746    | error { $$ = MkExpDummy(); $$.loc = @$; /*printf("Sorry, didn't mean that syntax error\n");*/ }
1747    | postfix_expression error
1748    | instantiation_unnamed_error error { $$ = MkExpInstance($1); $$.loc = @$; }
1749
1750    | postfix_expression PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1751    | postfix_expression_error PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1752
1753    | postfix_expression '(' argument_expression_list { yyerror(); $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; $$.call.argLoc.end.charPos++;}
1754         | postfix_expression '(' argument_expression_list_error { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; $$.call.argLoc.end.charPos++;}
1755    /* Useless rules due to conflicts
1756    | postfix_expression '(' argument_expression_list ',' error { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end;$$.loc = @$; $$.call.argLoc.end.charPos++;}
1757    | postfix_expression '(' error { $$ = MkExpCall($1, MkList() ); @$.end = yylloc.start; $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = yylloc.start; }
1758    */
1759    | postfix_expression '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1760
1761         | postfix_expression_error '(' argument_expression_list_error { $$ = MkExpCall($1, $3); $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.call.argLoc.end.charPos++;}
1762    /* Useless rules due to conflicts
1763    | postfix_expression_error '(' argument_expression_list ',' error { $$ = MkExpCall($1, $3); $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.call.argLoc.end.charPos++;}
1764    | postfix_expression_error '(' error { $$ = MkExpCall($1, MkList() ); $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @2.end; $$.call.argLoc.end.charPos++;}
1765    */
1766    | postfix_expression_error '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1767         ;
1768
1769 /*simple_postfix_expression_error:
1770       error { $$ = MkExpDummy(); $$.loc = @$; }
1771    | simple_postfix_expression error
1772    | instantiation_unnamed_error error { $$ = MkExpInstance($1); $$.loc = @$; }
1773
1774    | simple_postfix_expression PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1775    | simple_postfix_expression_error PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1776
1777    | simple_postfix_expression '(' argument_expression_list { yyerror(); $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; $$.call.argLoc.end.charPos++;}
1778         | simple_postfix_expression '(' argument_expression_list_error { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; $$.call.argLoc.end.charPos++;}
1779    // Useless rules due to conflicts
1780    //| simple_postfix_expression '(' argument_expression_list ',' error { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end;$$.loc = @$; $$.call.argLoc.end.charPos++;}
1781    //| simple_postfix_expression '(' error { $$ = MkExpCall($1, MkList() ); @$.end = yylloc.start; $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = yylloc.start; }
1782
1783    | simple_postfix_expression '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1784
1785         | simple_postfix_expression_error '(' argument_expression_list_error { $$ = MkExpCall($1, $3); $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.call.argLoc.end.charPos++;}
1786    // Useless rules due to conflicts
1787    //| simple_postfix_expression_error '(' argument_expression_list ',' error { $$ = MkExpCall($1, $3); $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.call.argLoc.end.charPos++;}
1788    //| simple_postfix_expression_error '(' error { $$ = MkExpCall($1, MkList() ); $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @2.end; $$.call.argLoc.end.charPos++;}
1789    | simple_postfix_expression_error '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1790         ;
1791 */
1792
1793 common_unary_expression_error:
1794            INC_OP unary_expression_error           { $$ = MkExpOp(null, INC_OP, $2); $$.loc = @$; }
1795          | DEC_OP unary_expression_error           { $$ = MkExpOp(null, DEC_OP, $2); $$.loc = @$; }
1796          | unary_operator cast_expression_error    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1797     | unary_operator anon_instantiation_expression_error    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1798     //| SIZEOF '(' unary_expression_error           { $$ = MkExpOp(null, SIZEOF, $3); $$.loc = @$; }
1799          | SIZEOF unary_expression_error           { $$ = MkExpOp(null, SIZEOF, $2); $$.loc = @$; }
1800          | SIZEOF '(' guess_type_name ')' error          { $$ = MkExpTypeSize($3); $$.loc = @$; }
1801     | SIZEOF '(' CLASS type ')' error   { $$ = MkExpClassSize($4); $$.loc = @$; }
1802     | SIZEOF '(' CLASS guess_type ')' error   { $$ = MkExpClassSize($4); $$.loc = @$; }
1803     //| ALIGNOF '(' unary_expression_error           { $$ = MkExpOp(null, ALIGNOF, $3); $$.loc = @$; }
1804          | ALIGNOF unary_expression_error           { $$ = MkExpOp(null, ALIGNOF, $2); $$.loc = @$; }
1805          | ALIGNOF '(' guess_type_name ')' error          { $$ = MkExpTypeAlign($3); $$.loc = @$; }
1806         ;
1807
1808 unary_expression_error:
1809      common_unary_expression_error
1810         | postfix_expression_error
1811    ;
1812
1813 /*simple_unary_expression_error:
1814      common_unary_expression_error
1815         | simple_postfix_expression_error
1816    ;*/
1817
1818 cast_expression_error:
1819      unary_expression_error
1820         | '(' type_name ')' cast_expression_error    { $$ = MkExpCast($2, $4); $$.loc = @$; }
1821         ;
1822
1823 multiplicative_expression_error:
1824      cast_expression_error
1825         | multiplicative_expression '*' cast_expression_error { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
1826         | multiplicative_expression '/' cast_expression_error { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
1827         | multiplicative_expression '%' cast_expression_error { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
1828         | multiplicative_expression_error '*' cast_expression_error { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
1829         | multiplicative_expression_error '/' cast_expression_error { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
1830         | multiplicative_expression_error '%' cast_expression_error { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
1831         ;
1832
1833 additive_expression_error:
1834     multiplicative_expression_error
1835         | additive_expression '+' multiplicative_expression_error  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
1836    /* Useless rules due to conflicts
1837         | additive_expression '+' error { $$ = MkExpOp($1, '+', null); $$.loc = @$; }
1838    */
1839         | additive_expression '-' multiplicative_expression_error  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
1840    /* Useless rules due to conflicts
1841    | additive_expression '-' error { $$ = MkExpOp($1, '-', null); $$.loc = @$; }
1842    */
1843         | additive_expression_error '+' multiplicative_expression_error  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
1844    /* Useless rules due to conflicts
1845         | additive_expression_error '+' error { $$ = MkExpOp($1, '+', null); $$.loc = @$; }
1846    */
1847         | additive_expression_error '-' multiplicative_expression_error  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
1848    /* Useless rules due to conflicts
1849    | additive_expression_error '-' error { $$ = MkExpOp($1, '-', null); $$.loc = @$; }
1850    */
1851         ;
1852
1853 shift_expression_error:
1854      additive_expression_error
1855         | shift_expression LEFT_OP additive_expression_error  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
1856         | shift_expression RIGHT_OP additive_expression_error { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
1857         | shift_expression_error LEFT_OP additive_expression_error  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
1858         | shift_expression_error RIGHT_OP additive_expression_error { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
1859         ;
1860
1861 relational_expression_error:
1862      shift_expression_error
1863         | relational_expression_smaller_than /*relational_expression '<' */ shift_expression_error
1864    {
1865       if($1.type == identifierExp)
1866       {
1867          _DeclClass($1.identifier._class, $1.identifier.string);
1868
1869          // printf("Declaring Class %s\n", $1.identifier.string);
1870          skipErrors = false;
1871
1872          FreeExpression($1);
1873          FreeExpression($2);
1874
1875          fileInput.Seek(@1.start.pos, start);
1876          resetScannerPos(&@1.start);
1877          yyclearin;
1878
1879          YYPOPSTACK(1);
1880          yystate = *yyssp;
1881          YY_STACK_PRINT (yyss, yyssp);
1882
1883          YYPOPSTACK(1);
1884          yystate = *yyssp;
1885          YY_STACK_PRINT (yyss, yyssp);
1886 /*
1887          YYPOPSTACK(1);
1888          yystate = *yyssp;
1889          YY_STACK_PRINT (yyss, yyssp);
1890
1891          YYPOPSTACK(1);
1892          yystate = *yyssp;
1893          YY_STACK_PRINT (yyss, yyssp);
1894 */
1895          yyerrok;
1896
1897          goto yysetstate;
1898       }
1899       else
1900       {
1901          $$ = MkExpOp($1, '<', $2);
1902          $$.loc = @$;
1903       }
1904       skipErrors = false;
1905    }
1906         | relational_expression '>' shift_expression_error    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
1907         | relational_expression LE_OP shift_expression_error  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
1908         | relational_expression GE_OP shift_expression_error  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
1909         | relational_expression_error '<' shift_expression_error    { $$ = MkExpOp($1, '<', $3); $$.loc = @$; }
1910         | relational_expression_error '>' shift_expression_error    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
1911         | relational_expression_error LE_OP shift_expression_error  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
1912         | relational_expression_error GE_OP shift_expression_error  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
1913         ;
1914
1915 equality_expression_error:
1916        relational_expression_error
1917      | equality_expression EQ_OP relational_expression_error  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1918           | equality_expression NE_OP relational_expression_error  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1919      | equality_expression_error EQ_OP relational_expression_error  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1920           | equality_expression_error NE_OP relational_expression_error  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1921      /* Useless rules due to conflicts
1922      | equality_expression EQ_OP error        { $$ = MkExpOp($1, EQ_OP, MkExpDummy()); $$.loc = @$; }
1923           | equality_expression NE_OP error        { $$ = MkExpOp($1, NE_OP, MkExpDummy()); $$.loc = @$; }
1924      | equality_expression_error EQ_OP error  { $$ = MkExpOp($1, EQ_OP, MkExpDummy()); $$.loc = @$; }
1925           | equality_expression_error NE_OP error  { $$ = MkExpOp($1, NE_OP, MkExpDummy()); $$.loc = @$; }
1926      */
1927      | equality_expression EQ_OP anon_instantiation_expression_error  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1928           | equality_expression NE_OP anon_instantiation_expression_error  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1929      | equality_expression_error EQ_OP anon_instantiation_expression_error  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1930           | equality_expression_error NE_OP anon_instantiation_expression_error  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1931         ;
1932
1933 and_expression_error:
1934    equality_expression_error
1935         | and_expression '&' equality_expression_error  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1936    | and_expression_error '&' equality_expression_error  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1937
1938         | and_expression '&' anon_instantiation_expression_error  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1939    | and_expression_error '&' anon_instantiation_expression_error  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1940         ;
1941
1942 exclusive_or_expression_error:
1943    and_expression_error
1944         | exclusive_or_expression '^' and_expression_error { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1945    | exclusive_or_expression_error '^' and_expression_error { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1946
1947         | exclusive_or_expression '^' anon_instantiation_expression_error { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1948    | exclusive_or_expression_error '^' anon_instantiation_expression_error { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1949         ;
1950
1951 inclusive_or_expression_error:
1952      exclusive_or_expression_error
1953         | inclusive_or_expression '|' exclusive_or_expression_error { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1954    | inclusive_or_expression_error '|' exclusive_or_expression_error { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1955
1956         | inclusive_or_expression '|' anon_instantiation_expression_error { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1957    | inclusive_or_expression_error '|' anon_instantiation_expression_error { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1958         ;
1959
1960 logical_and_expression_error:
1961    inclusive_or_expression_error
1962         | logical_and_expression AND_OP inclusive_or_expression_error  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
1963    | logical_and_expression_error AND_OP inclusive_or_expression_error  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
1964         ;
1965
1966 logical_or_expression_error:
1967      logical_and_expression_error
1968    | logical_or_expression OR_OP logical_and_expression_error     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
1969         | logical_or_expression_error OR_OP logical_and_expression_error     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
1970         ;
1971
1972 conditional_expression_error:
1973     logical_or_expression_error
1974         | logical_or_expression '?' expression ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1975    | logical_or_expression '?' expression_error ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1976         | logical_or_expression_error '?' expression ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1977    | logical_or_expression_error '?' expression_error ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1978         | logical_or_expression '?' expression ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
1979    | logical_or_expression '?' expression_error ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
1980         | logical_or_expression_error '?' expression ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
1981    | logical_or_expression_error '?' expression_error ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
1982
1983         | logical_or_expression '?' expression_anon_inst ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1984    | logical_or_expression '?' expression_anon_inst_error ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1985         | logical_or_expression_error '?' expression_anon_inst ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1986    | logical_or_expression_error '?' expression_anon_inst_error ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1987         | logical_or_expression '?' expression_anon_inst ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
1988    | logical_or_expression '?' expression_anon_inst_error ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
1989         | logical_or_expression_error '?' expression_anon_inst ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
1990    | logical_or_expression_error '?' expression_anon_inst_error ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
1991
1992         | logical_or_expression '?' expression ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1993    | logical_or_expression '?' expression_error ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1994         | logical_or_expression_error '?' expression ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1995    | logical_or_expression_error '?' expression_error ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1996
1997         | logical_or_expression '?' expression_anon_inst ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1998    | logical_or_expression '?' expression_anon_inst_error ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1999         | logical_or_expression_error '?' expression_anon_inst ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2000    | logical_or_expression_error '?' expression_anon_inst_error ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2001
2002         | logical_or_expression '?' ':'
2003       {
2004          yyerror();
2005          $$ = MkExpCondition($1, MkListOne(MkExpDummy()), MkExpDummy());
2006          $$.loc = @$;
2007          ((Expression)$$.cond.exp->last).loc = @2;
2008          $$.cond.elseExp.loc = @3;
2009       }
2010    | logical_or_expression_error '?' ':'
2011       {
2012          $$ = MkExpCondition($1, MkListOne(MkExpDummy()), MkExpDummy()); $$.loc = @$; ((Expression)$$.cond.exp->last).loc = @2; $$.cond.elseExp.loc = @3;
2013       }
2014    | logical_or_expression '?'
2015       {
2016          yyerror();
2017          $$ = MkExpCondition($1, MkListOne(MkExpDummy()), MkExpDummy()); $$.loc = @$; ((Expression)$$.cond.exp->last).loc = @2; $$.cond.elseExp.loc = @2;
2018       }
2019    | logical_or_expression_error '?'
2020       {
2021          $$ = MkExpCondition($1, MkListOne(MkExpDummy()), MkExpDummy()); $$.loc = @$; ((Expression)$$.cond.exp->last).loc = @2; $$.cond.elseExp.loc = @2;
2022       }
2023    ;
2024
2025 assignment_expression_error:
2026      conditional_expression_error
2027    | unary_expression assignment_operator assignment_expression_error   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
2028    /* Useless rules due to conflicts
2029    | unary_expression assignment_operator error   { $$ = MkExpOp($1, $2, MkExpDummy()); $$.loc = @$; $$.op.exp2.loc = @2; }
2030    */
2031    | unary_expression_error assignment_operator assignment_expression_error   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
2032    /* Useless rules due to conflicts
2033    | unary_expression_error assignment_operator error   { $$ = MkExpOp($1, $2, MkExpDummy()); $$.loc = @$; $$.op.exp2.loc = @2; }
2034    */
2035
2036    | unary_expression assignment_operator anon_instantiation_expression_error   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
2037    | unary_expression_error assignment_operator anon_instantiation_expression_error   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
2038         ;
2039
2040 expression_error:
2041      assignment_expression_error                 { $$ = MkList(); ListAdd($$, $1); }
2042    | assignment_expression error                 { $$ = MkList(); ListAdd($$, $1); }
2043    | expression ',' assignment_expression_error  { $$ = $1; ListAdd($1, $3); }
2044         | expression_error ',' assignment_expression_error  { $$ = $1; ListAdd($1, $3); }
2045    /* Useless rules due to conflicts
2046    | expression ',' error
2047    | expression_error ',' error
2048    | expression error
2049    */
2050    | expression expression                      { yyerror(); $$ = $1; FreeList($2, FreeExpression); }
2051    | expression_error expression                { $$ = $1; FreeList($2, FreeExpression); }
2052    | expression expression_error                { $$ = $1; FreeList($2, FreeExpression); }
2053    ;
2054
2055 expression_anon_inst_error:
2056      anon_instantiation_expression_error                 { $$ = MkList(); ListAdd($$, $1); }
2057    | anon_instantiation_expression error                 { $$ = MkList(); ListAdd($$, $1); }
2058    | expression ',' anon_instantiation_expression_error  { $$ = $1; ListAdd($1, $3); }
2059         | expression_error ',' anon_instantiation_expression_error  { $$ = $1; ListAdd($1, $3); }
2060    ;
2061
2062
2063 constant_expression: conditional_expression;
2064
2065 constant_expression_error: conditional_expression_error;
2066
2067 /**** TYPES **************************************************************************/
2068 storage_class_specifier:
2069           TYPEDEF       { $$ = MkSpecifier(TYPEDEF); }
2070         | EXTERN        { $$ = MkSpecifier(EXTERN); }
2071         | STATIC        { $$ = MkSpecifier(STATIC); }
2072         | THREAD        { $$ = MkSpecifier(THREAD); }
2073         | AUTO          { $$ = MkSpecifier(AUTO); }
2074         | REGISTER      { $$ = MkSpecifier(REGISTER); }
2075    | RESTRICT      { $$ = MkSpecifier(RESTRICT); }
2076         ;
2077
2078 external_storage_class_specifier:
2079           TYPEDEF       { $$ = MkSpecifier(TYPEDEF); structDeclMode = declMode = defaultAccess; }
2080         | EXTERN        { $$ = MkSpecifier(EXTERN); }
2081         | STATIC        { $$ = MkSpecifier(STATIC); structDeclMode = declMode = staticAccess; }
2082    | THREAD        { $$ = MkSpecifier(THREAD); }
2083         | AUTO          { $$ = MkSpecifier(AUTO); }
2084         | REGISTER      { $$ = MkSpecifier(REGISTER); }
2085    | RESTRICT      { $$ = MkSpecifier(RESTRICT); }
2086         ;
2087
2088 enumerator:
2089           identifier                           { $$ = MkEnumerator($1, null); }
2090         | identifier '=' constant_expression   { $$ = MkEnumerator($1, $3); }
2091    | identifier '=' constant_expression_error   { $$ = MkEnumerator($1, $3); }
2092         ;
2093
2094 enumerator_list:
2095           enumerator                        { $$ = MkList(); ListAdd($$, $1); }
2096         | enumerator_list ',' enumerator    { $$ = $1; ListAdd($1, $3); }
2097    | enumerator_list ','
2098         ;
2099
2100 enum_specifier:
2101      ENUM  { memberAccessStack[++defaultMemberAccess] = publicAccess; }
2102    ;
2103
2104 enum_specifier_nocompound:
2105      enum_specifier identifier                            { $$ = MkEnum($2, null); POP_DEFAULT_ACCESS }
2106    | enum_specifier strict_type                           { $$ = MkEnum(MkIdentifier($2.name), null); POP_DEFAULT_ACCESS }
2107    ;
2108
2109 enum_specifier_compound:
2110           enum_specifier_compound_error '}' { $$.loc = @$; POP_DEFAULT_ACCESS $$ = $1; }
2111         | enum_specifier identifier '{' '}'    { $$ = MkEnum($2, null); $$.loc = @$; POP_DEFAULT_ACCESS }
2112    | enum_specifier strict_type '{' '}'          { $$ = MkEnum(MkIdentifier($2.name), null); FreeSpecifier($2); $$.loc = @$; POP_DEFAULT_ACCESS }
2113         ;
2114
2115 enum_specifier_compound_error:
2116           enum_specifier '{' enumerator_list       { $$ = MkEnum(null, $3); $$.loc = @$; POP_DEFAULT_ACCESS }
2117    | enum_specifier '{' error                 { $$ = MkEnum(null, null); $$.loc = @$; POP_DEFAULT_ACCESS }
2118
2119         | enum_specifier identifier '{' enumerator_list          { $$ = MkEnum($2, $4); $$.loc = @$; POP_DEFAULT_ACCESS }
2120    | enum_specifier identifier '{' enumerator_list error    { $$ = MkEnum($2, $4);  $$.loc = @$; POP_DEFAULT_ACCESS }
2121    | enum_specifier identifier '{' error    { $$ = MkEnum($2, null);  $$.loc = @$; POP_DEFAULT_ACCESS }
2122    | enum_specifier identifier '{' enumerator_list ';' struct_declaration_list     { $$ = MkEnum($2, $4); $$.loc = @$; $$.definitions = $6;  POP_DEFAULT_ACCESS }
2123    | enum_specifier identifier '{' enumerator_list ';' struct_declaration_list_error     { $$ = MkEnum($2, $4); $$.loc = @$; $$.definitions = $6;  POP_DEFAULT_ACCESS }
2124
2125    | enum_specifier strict_type '{' enumerator_list           { $$ = MkEnum(MkIdentifier($2.name), $4); $$.loc = @$; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2126    | enum_specifier strict_type '{' enumerator_list error          { $$ = MkEnum(MkIdentifier($2.name), $4); $$.loc = @$; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2127    | enum_specifier strict_type '{' error                          { $$ = MkEnum(MkIdentifier($2.name), null); $$.loc = @$; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2128         | enum_specifier strict_type '{' enumerator_list ';' struct_declaration_list           { $$ = MkEnum(MkIdentifier($2.name), $4); $$.loc = @$; $$.definitions = $6; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2129         | enum_specifier strict_type '{' enumerator_list ';' struct_declaration_list_error           { $$ = MkEnum(MkIdentifier($2.name), $4); $$.loc = @$; $$.definitions = $6; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2130
2131    | enum_specifier identifier '{' enumerator_list ';'      { $$ = MkEnum($2, $4); $$.loc = @$; POP_DEFAULT_ACCESS }
2132         | enum_specifier strict_type '{' enumerator_list ';'            { $$ = MkEnum(MkIdentifier($2.name), $4); $$.loc = @$; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2133         ;
2134
2135 enum_decl:
2136      enum_specifier identifier  { $$ = $2; if(declMode) DeclClassAddNameSpace($2._class, $2.string); }
2137    | enum_specifier strict_type { $$ = MkIdentifier($2.name); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
2138    ;
2139
2140 enum_class:
2141      enum_class_error '}'  { $$ = $1; $$.loc = @$; }
2142    | enum_decl ':' inheritance_specifiers '{' '}' { $$ = MkEnum($1, null); $$.baseSpecs = $3; $$.loc = @$; POP_DEFAULT_ACCESS }
2143    | enum_decl '{' '}'    { $$ = MkEnum($1, null); POP_DEFAULT_ACCESS }
2144    ;
2145
2146 enum_class_error:
2147      enum_decl ':' inheritance_specifiers '{' enumerator_list           { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.loc = @$; POP_DEFAULT_ACCESS }
2148    | enum_decl ':' inheritance_specifiers '{' enumerator_list error          { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.loc = @$; POP_DEFAULT_ACCESS }
2149    | enum_decl ':' inheritance_specifiers '{' error          { $$ = MkEnum($1, null); $$.baseSpecs = $3; $$.loc = @$; POP_DEFAULT_ACCESS }
2150    | enum_decl ':' inheritance_specifiers '{' enumerator_list ';' struct_declaration_list           { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.definitions = $7; $$.loc = @$; POP_DEFAULT_ACCESS }
2151    | enum_decl ':' inheritance_specifiers '{' enumerator_list ';' struct_declaration_list_error           { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.definitions = $7; $$.loc = @$; POP_DEFAULT_ACCESS }
2152    | enum_decl ':' inheritance_specifiers '{' enumerator_list error ';' struct_declaration_list           { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.definitions = $8; $$.loc = @$; POP_DEFAULT_ACCESS }
2153    | enum_decl ':' inheritance_specifiers '{' enumerator_list error ';' struct_declaration_list_error           { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.definitions = $8; $$.loc = @$; POP_DEFAULT_ACCESS }
2154    | enum_decl ':' inheritance_specifiers '{' error ';' struct_declaration_list           { $$ = MkEnum($1, null); $$.baseSpecs = $3; $$.definitions = $7; $$.loc = @$; POP_DEFAULT_ACCESS }
2155    | enum_decl ':' inheritance_specifiers '{' error ';' struct_declaration_list_error           { $$ = MkEnum($1, null); $$.baseSpecs = $3; $$.definitions = $7; $$.loc = @$; POP_DEFAULT_ACCESS }
2156
2157         | enum_specifier '{' enumerator_list       { $$ = MkEnum(null, $3); $$.loc = @$; POP_DEFAULT_ACCESS }
2158    | enum_specifier '{' error                 { $$ = MkEnum(null, null); $$.loc = @$; POP_DEFAULT_ACCESS }
2159
2160         | enum_decl '{' enumerator_list          { $$ = MkEnum($1, $3); $$.loc = @$; POP_DEFAULT_ACCESS }
2161    | enum_decl '{' enumerator_list error    { $$ = MkEnum($1, $3); $$.loc = @$; POP_DEFAULT_ACCESS }
2162    | enum_decl '{' error    { $$ = MkEnum($1, null); $$.loc = @$; POP_DEFAULT_ACCESS }
2163    | enum_decl '{' enumerator_list ';' struct_declaration_list     { $$ = MkEnum($1, $3); $$.definitions = $5; $$.loc = @$; POP_DEFAULT_ACCESS }
2164    | enum_decl '{' enumerator_list ';' struct_declaration_list_error     { $$ = MkEnum($1, $3); $$.definitions = $5; $$.loc = @$; POP_DEFAULT_ACCESS }
2165
2166    | enum_decl ':' inheritance_specifiers '{' enumerator_list ';'            { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.loc = @$; POP_DEFAULT_ACCESS }
2167    | enum_decl ':' inheritance_specifiers '{' enumerator_list error ';'            { $$ = MkEnum($1, $5); $$.baseSpecs = $3;  $$.loc = @$; POP_DEFAULT_ACCESS }
2168    | enum_decl ':' inheritance_specifiers '{' error ';'            { $$ = MkEnum($1, null); $$.baseSpecs = $3; $$.loc = @$; POP_DEFAULT_ACCESS }
2169    | enum_decl '{' enumerator_list ';'      { $$ = MkEnum($1, $3);  $$.loc = @$; POP_DEFAULT_ACCESS }
2170    ;
2171
2172 class_specifier:
2173      enum_class
2174    | struct_class
2175    ;
2176
2177 class_specifier_error:
2178      enum_class_error
2179    | struct_class_error
2180    ;
2181
2182 ext_storage:
2183    ext_decl   { $$ = MkSpecifierExtended($1); }
2184    ;
2185
2186 type_qualifier:
2187           CONST        { $$ = MkSpecifier(CONST); }
2188         | VOLATILE     { $$ = MkSpecifier(VOLATILE); }
2189    | ext_storage  { $$ = $1; }
2190         ;
2191
2192
2193 type_qualifier_list:
2194           type_qualifier                          { $$ = MkList(); ListAdd($$, $1); }
2195         | type_qualifier_list type_qualifier      { $$ = $1; ListAdd($1, $2);  }
2196         ;
2197
2198 type_specifier:
2199           VOID            { $$ = MkSpecifier(VOID); }
2200         | CHAR            { $$ = MkSpecifier(CHAR); }
2201         | SHORT           { $$ = MkSpecifier(SHORT); }
2202         | INT             { $$ = MkSpecifier(INT); }
2203    | UINT            { $$ = MkSpecifier(UINT); }
2204    | INT64           { $$ = MkSpecifier(INT64); }
2205    | INT128          { $$ = MkSpecifier(INT128); }
2206    | VALIST          { $$ = MkSpecifier(VALIST); }
2207         | LONG            { $$ = MkSpecifier(LONG); }
2208         | FLOAT           { $$ = MkSpecifier(FLOAT); }
2209         | DOUBLE          { $$ = MkSpecifier(DOUBLE); }
2210         | SIGNED          { $$ = MkSpecifier(SIGNED); }
2211         | UNSIGNED        { $$ = MkSpecifier(UNSIGNED); }
2212    | EXTENSION       { $$ = MkSpecifier(EXTENSION); }
2213         | struct_or_union_specifier_nocompound
2214         | enum_specifier_nocompound
2215         | type
2216    | TYPEOF '(' assignment_expression ')' { $$ = MkSpecifierTypeOf($3); }
2217    | SUBCLASS '(' type ')'                { $$ = MkSpecifierSubClass($3); }
2218    | SUBCLASS '(' identifier ')'          { _DeclClass($3._class, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
2219    | THISCLASS       { $$ = MkSpecifier(THISCLASS); }
2220    | TYPED_OBJECT    { $$ = MkSpecifier(TYPED_OBJECT); }
2221    | ANY_OBJECT      { $$ = MkSpecifier(ANY_OBJECT); }
2222    | _BOOL           { $$ = MkSpecifier(_BOOL); }
2223    | BOOL            { $$ = MkSpecifier(BOOL); }
2224    | _COMPLEX        { $$ = MkSpecifier(_COMPLEX); }
2225    | _IMAGINARY      { $$ = MkSpecifier(_IMAGINARY); }
2226         ;
2227
2228 strict_type_specifier:
2229           VOID            { $$ = MkSpecifier(VOID); }
2230         | CHAR            { $$ = MkSpecifier(CHAR); }
2231         | SHORT           { $$ = MkSpecifier(SHORT); }
2232         | INT             { $$ = MkSpecifier(INT); }
2233    | UINT            { $$ = MkSpecifier(UINT); }
2234    | INT64           { $$ = MkSpecifier(INT64); }
2235    | INT128          { $$ = MkSpecifier(INT128); }
2236    | VALIST          { $$ = MkSpecifier(VALIST); }
2237         | LONG            { $$ = MkSpecifier(LONG); }
2238         | FLOAT           { $$ = MkSpecifier(FLOAT); }
2239         | DOUBLE          { $$ = MkSpecifier(DOUBLE); }
2240         | SIGNED          { $$ = MkSpecifier(SIGNED); }
2241         | UNSIGNED        { $$ = MkSpecifier(UNSIGNED); }
2242    | EXTENSION       { $$ = MkSpecifier(EXTENSION); }
2243         | struct_or_union_specifier_nocompound
2244         | enum_specifier_nocompound
2245         | strict_type
2246    | _BOOL           { $$ = MkSpecifier(_BOOL); }
2247    | BOOL            { $$ = MkSpecifier(BOOL); }
2248    | _COMPLEX        { $$ = MkSpecifier(_COMPLEX); }
2249    | _IMAGINARY      { $$ = MkSpecifier(_IMAGINARY); }
2250    | TYPEOF '(' assignment_expression ')' { $$ = MkSpecifierTypeOf($3); }
2251    | SUBCLASS '(' type ')'                { $$ = MkSpecifierSubClass($3); }
2252    | SUBCLASS '(' identifier ')'          { _DeclClass($3._class, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
2253    | THISCLASS       { $$ = MkSpecifier(THISCLASS); }
2254         ;
2255
2256 // TESTING declarator_nofunction here... For function declarations
2257
2258 struct_declarator:
2259           declarator_nofunction_type_ok
2260       { $$ = MkStructDeclarator($1, null); $$.loc = @$; }
2261         | declarator_nofunction_type_ok attrib
2262       { $$ = MkStructDeclarator($1, null); $$.structDecl.attrib = $2; $$.loc = @$; }
2263         | ':' constant_expression
2264       { $$ = MkStructDeclarator(null, $2);  $$.loc = @$; }
2265         | declarator_nofunction_type_ok ':' constant_expression
2266       { $$ = MkStructDeclarator($1, $3);  $$.loc = @$; }
2267    | declarator_nofunction_type_ok ':' constant_expression ':' constant_expression
2268       { $$ = MkStructDeclarator($1, $3); $$.structDecl.posExp = $5; $$.loc = @$; }
2269         | ':' constant_expression_error
2270       { $$ = MkStructDeclarator(null, $2);  $$.loc = @$; }
2271         | declarator_nofunction_type_ok ':' constant_expression_error
2272       { $$ = MkStructDeclarator($1, $3);  $$.loc = @$; }
2273    | declarator_nofunction_type_ok ':' constant_expression ':' constant_expression_error
2274       { $$ = MkStructDeclarator($1, $3); $$.structDecl.posExp = $5; $$.loc = @$; }
2275    | declarator_nofunction_type_ok ':' constant_expression_error ':' constant_expression_error
2276       { $$ = MkStructDeclarator($1, $3); $$.structDecl.posExp = $5; $$.loc = @$; }
2277    | declarator_nofunction_type_ok ':' constant_expression_error ':' constant_expression
2278       { $$ = MkStructDeclarator($1, $3); $$.structDecl.posExp = $5; $$.loc = @$; }
2279    ;
2280
2281 struct_declarator_list:
2282           struct_declarator                                { $$ = MkList(); ListAdd($$, $1); }
2283         | struct_declarator_list ',' struct_declarator     { $$ = $1; ListAdd($1, $3); }
2284         ;
2285
2286 struct_entry:
2287      struct_or_union identifier
2288       {
2289          $$ = MkStructOrUnion($1, $2, null);
2290          $$.addNameSpace = true;
2291          $$.ctx = PushContext();
2292       }
2293    | struct_or_union base_strict_type
2294       {
2295          $$ = MkStructOrUnion($1, MkIdentifier($2.name), null);
2296          $$.ctx = PushContext();
2297          FreeSpecifier($2);
2298       }
2299    | struct_or_union ext_decl identifier
2300       {
2301          $$ = MkStructOrUnion($1, $3, null);
2302          $$.extDeclStruct = $2;
2303          $$.addNameSpace = true;
2304          $$.ctx = PushContext();
2305       }
2306    | struct_or_union ext_decl base_strict_type
2307       {
2308          $$ = MkStructOrUnion($1, MkIdentifier($3.name), null);
2309          $$.extDeclStruct = $2;
2310          $$.ctx = PushContext();
2311          FreeSpecifier($3);
2312       }
2313    ;
2314
2315 struct_or_union_specifier_compound:
2316      struct_or_union_specifier_compound_error '}' { $$ = $1; $$.loc = @$; }
2317    | struct_entry '{' '}'                 { $$ = $1; $$.loc = @$; POP_DEFAULT_ACCESS PopContext(curContext); }
2318    | struct_or_union '{' '}'              { $$ = MkStructOrUnion($1, null, null); $$.loc = @$; POP_DEFAULT_ACCESS }
2319    | struct_or_union ext_decl '{' '}'              { $$ = MkStructOrUnion($1, null, null); $$.extDeclStruct = $2; $$.loc = @$; POP_DEFAULT_ACCESS }
2320         ;
2321
2322 struct_or_union_specifier_compound_error:
2323      struct_entry '{' struct_declaration_list        { $$ = $1; AddStructDefinitions($1, $3);  POP_DEFAULT_ACCESS PopContext(curContext); }
2324    | struct_entry '{' struct_declaration_list_error   { $$ = $1; AddStructDefinitions($1, $3);  POP_DEFAULT_ACCESS PopContext(curContext); }
2325    | struct_entry '{' error   { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext); }
2326
2327         | struct_or_union '{' struct_declaration_list               { $$ = MkStructOrUnion($1, null, $3); POP_DEFAULT_ACCESS }
2328    | struct_or_union '{' struct_declaration_list_error               { $$ = MkStructOrUnion($1, null, $3); POP_DEFAULT_ACCESS }
2329    | struct_or_union '{' error              { $$ = MkStructOrUnion($1, null, null); POP_DEFAULT_ACCESS }
2330
2331         | struct_or_union ext_decl '{' struct_declaration_list               { $$ = MkStructOrUnion($1, null, $4); $$.extDeclStruct = $2; POP_DEFAULT_ACCESS }
2332    | struct_or_union ext_decl '{' struct_declaration_list_error               { $$ = MkStructOrUnion($1, null, $4); $$.extDeclStruct = $2; POP_DEFAULT_ACCESS }
2333    | struct_or_union ext_decl '{' error              { $$ = MkStructOrUnion($1, null, null); $$.extDeclStruct = $2; POP_DEFAULT_ACCESS }
2334         ;
2335
2336 struct_or_union_specifier_nocompound:
2337           struct_entry { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext); }
2338         ;
2339
2340 struct_decl:
2341      struct_entry
2342      {
2343         $$ = $1;
2344         if(declMode)
2345         {
2346            ($1.addNameSpace ? DeclClassAddNameSpace : DeclClass)($1.id._class, $1.id.string);
2347         }
2348      }
2349    | struct_entry '<' template_parameters_list '>'
2350    {
2351       Symbol symbol = ($1.addNameSpace ? DeclClassAddNameSpace : DeclClass)($1.id._class, $1.id.string);
2352       $$ = $1;
2353       symbol.templateParams = $3;
2354    }
2355    ;
2356
2357 struct_head:
2358    struct_decl ':' inheritance_specifiers
2359    {
2360       $$ = $1;
2361       $$.baseSpecs = $3;
2362       SetupBaseSpecs(null, $3);
2363    }
2364    ;
2365
2366 struct_class:
2367      struct_class_error '}' { $$ = $1; $$.loc = @$; }
2368    | struct_head '{' '}'
2369       { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext); }
2370    | struct_decl '{' '}'   { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext); }
2371    | struct_or_union '{' '}' { $$ = MkStructOrUnion($1, null, null); POP_DEFAULT_ACCESS }
2372    ;
2373
2374 struct_class_error:
2375         struct_head '{' struct_declaration_list
2376    {
2377       $$ = $1;
2378       $$.definitions = $3;
2379       POP_DEFAULT_ACCESS
2380       PopContext(curContext);
2381    }
2382         | struct_head '{' struct_declaration_list_error
2383    {
2384       $$ = $1;
2385       $$.definitions = $3;
2386       POP_DEFAULT_ACCESS
2387       PopContext(curContext);
2388    }
2389         | struct_head '{' error
2390    { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext);}
2391
2392         | struct_decl '{' struct_declaration_list
2393      {
2394         PopContext(curContext);
2395         if(!declMode)
2396         {
2397            $$ = MkStructOrUnion($1.type, $1.id, $3);
2398            $1.id = null;
2399            FreeSpecifier($1);
2400         }
2401         else
2402            $$.definitions = $3;
2403         POP_DEFAULT_ACCESS
2404      }
2405         | struct_decl '{' struct_declaration_list_error
2406      {
2407         PopContext(curContext);
2408
2409         if(!declMode)
2410         {
2411            $$ = MkStructOrUnion($1.type, $1.id, $3);
2412            $1.id = null;
2413            FreeSpecifier($1);
2414         }
2415         else
2416            $$.definitions = $3;
2417         POP_DEFAULT_ACCESS
2418      }
2419    | struct_decl '{' error
2420       { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext); }
2421
2422         | struct_or_union '{' struct_declaration_list
2423       { $$ = MkStructOrUnion($1, null, $3); POP_DEFAULT_ACCESS  }
2424    | struct_or_union '{' struct_declaration_list_error
2425       { $$ = MkStructOrUnion($1, null, $3); POP_DEFAULT_ACCESS }
2426    | struct_or_union '{' error
2427       { $$ = MkStructOrUnion($1, null, null); POP_DEFAULT_ACCESS }
2428    ;
2429
2430 struct_or_union:
2431           STRUCT    { $$ = structSpecifier; memberAccessStack[++defaultMemberAccess] = publicAccess; }
2432         | UNION     { $$ = unionSpecifier; memberAccessStack[++defaultMemberAccess] = publicAccess; }
2433         ;
2434
2435 specifier_qualifier_list:
2436      type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2437    | specifier_qualifier_list  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2438    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2439    | specifier_qualifier_list  type_specifier            { $$ = $1; ListAdd($1, $2); }
2440    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2441         | specifier_qualifier_list enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2442    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2443         | specifier_qualifier_list struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2444    ;
2445
2446 guess_specifier_qualifier_list:
2447      type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2448    | guess_specifier_qualifier_list  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2449    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2450    | guess_specifier_qualifier_list  type_specifier            { $$ = $1; ListAdd($1, $2); }
2451    | guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
2452    | guess_specifier_qualifier_list  guess_type            { $$ = $1; ListAdd($1, $2); }
2453    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2454         | guess_specifier_qualifier_list enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2455    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2456         | guess_specifier_qualifier_list struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2457    ;
2458
2459 declaration_specifiers:
2460      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2461    | declaration_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
2462    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2463    | declaration_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2464    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2465    | declaration_specifiers  strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
2466    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2467         | declaration_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2468    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2469         | declaration_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2470    ;
2471
2472 guess_declaration_specifiers:
2473      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2474    | guess_declaration_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
2475    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2476    | guess_declaration_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2477    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2478    | guess_declaration_specifiers  type_specifier            { $$ = $1; ListAdd($1, $2); }
2479    | guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
2480         | guess_declaration_specifiers guess_type          { $$ = $1; ListAdd($1, $2); }
2481    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2482         | guess_declaration_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2483    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2484         | guess_declaration_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2485    ;
2486
2487 external_guess_declaration_specifiers:
2488      external_storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2489    | external_guess_declaration_specifiers external_storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
2490    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2491    | external_guess_declaration_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2492    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2493    | external_guess_declaration_specifiers  type_specifier            { $$ = $1; ListAdd($1, $2); }
2494    | guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
2495         | external_guess_declaration_specifiers guess_type          { $$ = $1; ListAdd($1, $2); }
2496    | class_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2497    | external_guess_declaration_specifiers class_specifier            { $$ = $1; ListAdd($1, $2); }
2498    ;
2499
2500 external_guess_declaration_specifiers_error:
2501      class_specifier_error                             { $$ = MkList(); ListAdd($$, $1); }
2502    | external_guess_declaration_specifiers class_specifier_error      { $$ = $1; ListAdd($1, $2); }
2503    ;
2504
2505 _inheritance_specifiers:
2506      PRIVATE                                          { $$ = MkList(); ListAdd($$, MkSpecifier(PRIVATE)); }
2507    | PUBLIC                                           { $$ = MkList(); ListAdd($$, MkSpecifier(PUBLIC)); }
2508    | storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2509    | _inheritance_specifiers storage_class_specifier   { $$ = $1; ListAdd($1, $2); }
2510    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2511    | _inheritance_specifiers type_qualifier            { $$ = $1; ListAdd($1, $2); }
2512    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2513    | _inheritance_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
2514    | identifier
2515       { _DeclClass($1._class, $1.string); $$ = MkListOne(MkSpecifierName($1.string)); FreeIdentifier($1); }
2516         | _inheritance_specifiers identifier                { $$ = $1; _DeclClass($2._class, $2.string); ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2); }
2517
2518    | identifier '<' template_arguments_list '>'
2519       {
2520          _DeclClass($1._class, $1.string);
2521
2522          $$ = MkList();
2523          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
2524          FreeIdentifier($1);
2525       }
2526    | _inheritance_specifiers identifier '<' template_arguments_list '>'
2527       {
2528          $$ = $1;
2529          _DeclClass($2._class, $2.string);
2530          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
2531          FreeIdentifier($2);
2532       }
2533    ;
2534
2535 inheritance_specifiers:
2536      _inheritance_specifiers
2537    | struct_or_union    { $$ = MkListOne(MkStructOrUnion($1, null, null)); POP_DEFAULT_ACCESS }
2538    ;
2539
2540 property_specifiers:
2541      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2542    | property_specifiers storage_class_specifier     { $$ = $1; ListAdd($1, $2); }
2543    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2544    | property_specifiers type_qualifier            { $$ = $1; ListAdd($1, $2); }
2545    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2546    | property_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
2547    | identifier                        { $$ = MkList(); ListAdd($$, MkSpecifierName($1.string)); FreeIdentifier($1)}
2548    | property_specifiers identifier          { $$ = $1; ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2)}
2549    | identifier '<' template_arguments_list '>'
2550       {
2551          _DeclClass($1._class, $1.string);
2552
2553          $$ = MkList();
2554          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
2555          FreeIdentifier($1);
2556       }
2557    | property_specifiers identifier '<' template_arguments_list '>'
2558       {
2559          _DeclClass($2._class, $2.string);
2560          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
2561          FreeIdentifier($2);
2562       }
2563    ;
2564
2565 renew_specifiers:
2566      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2567    | renew_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
2568    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2569    | renew_specifiers type_qualifier            { $$ = $1; ListAdd($1, $2); }
2570    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2571    | renew_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
2572    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2573         | renew_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2574    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2575         | renew_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2576    | identifier                        { $$ = MkList(); ListAdd($$, MkSpecifierName($1.string)); FreeIdentifier($1)}
2577    | renew_specifiers identifier          { $$ = $1; ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2)}
2578    | identifier '<' template_arguments_list '>'
2579       {
2580          _DeclClass($1._class, $1.string);
2581
2582          $$ = MkList();
2583          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
2584          FreeIdentifier($1);
2585       }
2586    | renew_specifiers identifier '<' template_arguments_list '>'
2587       {
2588          _DeclClass($2._class, $2.string);
2589          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
2590          FreeIdentifier($2);
2591       }
2592    ;
2593
2594 new_specifiers:
2595      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2596    | new_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
2597    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2598    | new_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2599    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2600    | new_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
2601    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2602         | new_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2603    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2604         | new_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2605    | identifier                        { $$ = MkList(); ListAdd($$, MkSpecifierName($1.string)); FreeIdentifier($1)}
2606    | new_specifiers identifier          { $$ = $1; ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2)}
2607    | identifier '<' template_arguments_list '>'
2608       {
2609          _DeclClass($1._class, $1.string);
2610
2611          $$ = MkList();
2612          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
2613          FreeIdentifier($1);
2614       }
2615    | new_specifiers identifier '<' template_arguments_list '>'
2616       {
2617          _DeclClass($2._class, $2.string);
2618          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
2619          FreeIdentifier($2);
2620       }
2621    ;
2622
2623 identifier_list_error:
2624      identifier_list ',' error         { $$ = $1; ListAdd($1, null); }
2625    | identifier_list_error ',' error         { $$ = $1; ListAdd($1, null); }
2626    ;
2627
2628 identifier_list:
2629           identifier                        { $$ = MkList(); ListAdd($$, MkTypeName(null, MkDeclaratorIdentifier($1))); }
2630         | identifier_list ',' identifier    { $$ = $1; ListAdd($1, MkTypeName(null, MkDeclaratorIdentifier($3))); }
2631    | identifier_list_error ',' identifier    { $$ = $1; ListAdd($1, MkTypeName(null, MkDeclaratorIdentifier($3))); }
2632         | parameter_list ',' identifier    { $$ = $1; ListAdd($1, MkTypeName(null, MkDeclaratorIdentifier($3))); }
2633    | parameter_list_error ',' identifier    { $$ = $1; ListAdd($1, MkTypeName(null, MkDeclaratorIdentifier($3))); }
2634         ;
2635
2636 direct_declarator_nofunction_type_ok:
2637      direct_declarator_nofunction
2638    | base_strict_type
2639    {
2640       char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
2641       String s = colon ? colon + 2 : $1.name;
2642       $$ = MkDeclaratorIdentifier(MkIdentifier(s));
2643       FreeSpecifier($1);
2644    }
2645    | UINT { $$ = MkDeclaratorIdentifier(MkIdentifier("uint")); }
2646    // These rules need to be reviewed in lights of prototypes with types only...
2647         | base_strict_type '[' constant_expression ']'
2648       {
2649          Declarator decl;
2650          char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
2651          String s = colon ? colon + 2 : $1.name;
2652          decl = MkDeclaratorIdentifier(MkIdentifier(s));
2653          FreeSpecifier($1);
2654          $$ = MkDeclaratorArray(decl, $3);
2655       }
2656    | base_strict_type '[' constant_expression_error ']'
2657       {
2658          Declarator decl;
2659          char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
2660          String s = colon ? colon + 2 : $1.name;
2661          decl = MkDeclaratorIdentifier(MkIdentifier(s));
2662          FreeSpecifier($1);
2663          $$ = MkDeclaratorArray(decl, $3);
2664       }
2665         | base_strict_type '[' type ']'
2666       {
2667          Declarator decl;
2668          char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
2669          String s = colon ? colon + 2 : $1.name;
2670          decl = MkDeclaratorIdentifier(MkIdentifier(s));
2671          FreeSpecifier($1);
2672          $$ = MkDeclaratorEnumArray(decl, $3);
2673       }
2674         | base_strict_type '[' ']'
2675       {
2676          Declarator decl;
2677          char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
2678          String s = colon ? colon + 2 : $1.name;
2679          decl = MkDeclaratorIdentifier(MkIdentifier(s));
2680          FreeSpecifier($1);
2681          $$ = MkDeclaratorEnumArray(decl, null);
2682       }
2683         | direct_declarator_nofunction_type_ok '[' constant_expression ']' { $$ = MkDeclaratorArray($1, $3); }
2684    | direct_declarator_nofunction_type_ok '[' constant_expression_error ']' { $$ = MkDeclaratorArray($1, $3); }
2685         | direct_declarator_nofunction_type_ok '[' type ']' { $$ = MkDeclaratorEnumArray($1, $3); }
2686         | direct_declarator_nofunction_type_ok '[' ']'                     { $$ = MkDeclaratorArray($1, null); }
2687         ;
2688
2689 direct_declarator_nofunction:
2690           identifier                                                   { $$ = MkDeclaratorIdentifier($1); }
2691         | '(' declarator ')'                            { $$ = MkDeclaratorBrackets($2); }
2692    | '(' ext_decl declarator ')'                            { $$ = MkDeclaratorBrackets(MkDeclaratorExtended($2, $3)); }
2693         | '(' declarator_type_ok ')'                            { $$ = MkDeclaratorBrackets($2); }
2694    | '(' ext_decl declarator_type_ok ')'                            { $$ = MkDeclaratorBrackets(MkDeclaratorExtended($2, $3)); }
2695         | direct_declarator_nofunction '[' constant_expression ']' { $$ = MkDeclaratorArray($1, $3); }
2696    | direct_declarator_nofunction '[' constant_expression_error ']' { $$ = MkDeclaratorArray($1, $3); }
2697         | direct_declarator_nofunction '[' type ']' { $$ = MkDeclaratorEnumArray($1, $3); }
2698         | direct_declarator_nofunction '[' ']'                     { $$ = MkDeclaratorArray($1, null); }
2699         ;
2700
2701 direct_declarator_function_start:
2702      direct_declarator_nofunction '('
2703    ;
2704
2705 direct_declarator_function:
2706           direct_declarator_function_start parameter_type_list ')' { $$ = MkDeclaratorFunction($1, $2); }
2707    | direct_declarator_function_start parameter_type_list_error ')' { $$ = MkDeclaratorFunction($1, $2); }
2708         | direct_declarator_function_start identifier_list ')'     { $$ = MkDeclaratorFunction($1, $2); }
2709    | direct_declarator_function_start identifier_list_error ')'     { $$ = MkDeclaratorFunction($1, $2); }
2710         | direct_declarator_function_start ')'                     { $$ = MkDeclaratorFunction($1, null); }
2711         ;
2712
2713 // Tricky stuff here for overriding...
2714 direct_declarator_function_error:
2715    direct_declarator_function_start identifier_list_error
2716       {
2717          $$ = MkDeclaratorFunction($1, $2);
2718          fileInput.Seek(@1.end.pos, start);
2719          yyclearin;
2720          resetScannerPos(&@1.end);
2721          @$.start = @1.start;
2722          @$.end = @1.end;
2723       }
2724    | direct_declarator_function_start error
2725       {
2726          $$ = MkDeclaratorFunction($1, null);
2727          fileInput.Seek(@1.end.pos, start);
2728          yyclearin;
2729          resetScannerPos(&@1.end);
2730          @$.start = @1.start;
2731          @$.end = @1.end;
2732       }
2733    | direct_declarator_function_start parameter_list '('
2734       {
2735          $$ = MkDeclaratorFunction($1, $2);
2736          fileInput.Seek(@1.end.pos, start);
2737          yyclearin;
2738          resetScannerPos(&@1.end);
2739          @$.start = @1.start;
2740          @$.end = @1.end;
2741       }
2742    | direct_declarator_function_start guess_declaration_specifiers identifier '('
2743       {
2744          $$ = MkDeclaratorFunction($1, null);
2745          fileInput.Seek(@1.end.pos, start);
2746          yyclearin;
2747          resetScannerPos(&@1.end);
2748          @$.start = @1.start;
2749          @$.end = @1.end;
2750          FreeList($2, FreeSpecifier);
2751          FreeIdentifier($3);
2752       }
2753         ;
2754
2755 direct_declarator:
2756      direct_declarator_function
2757    | direct_declarator_nofunction
2758    ;
2759
2760
2761 direct_declarator_function_start_type_ok:
2762      direct_declarator_nofunction_type_ok '('
2763    ;
2764
2765 direct_declarator_function_type_ok:
2766           direct_declarator_function_start_type_ok parameter_type_list ')' { $$ = MkDeclaratorFunction($1, $2); }
2767    | direct_declarator_function_start_type_ok parameter_type_list_error ')' { $$ = MkDeclaratorFunction($1, $2); }
2768         | direct_declarator_function_start_type_ok identifier_list ')'     { $$ = MkDeclaratorFunction($1, $2); }
2769    | direct_declarator_function_start_type_ok identifier_list_error ')'     { $$ = MkDeclaratorFunction($1, $2); }
2770         | direct_declarator_function_start_type_ok ')'                     { $$ = MkDeclaratorFunction($1, null); }
2771         ;
2772
2773 // Tricky stuff here for overriding...
2774 direct_declarator_function_error_type_ok:
2775    direct_declarator_function_start_type_ok identifier_list_error
2776       {
2777          $$ = MkDeclaratorFunction($1, $2);
2778          fileInput.Seek(@1.end.pos, start);
2779          yyclearin;
2780          resetScannerPos(&@1.end);
2781          @$.start = @1.start;
2782          @$.end = @1.end;
2783       }
2784    | direct_declarator_function_start_type_ok error
2785       {
2786          $$ = MkDeclaratorFunction($1, null);
2787          fileInput.Seek(@1.end.pos, start);
2788          yyclearin;
2789          resetScannerPos(&@1.end);
2790          @$.start = @1.start;
2791          @$.end = @1.end;
2792       }
2793    | direct_declarator_function_start_type_ok parameter_list '('
2794       {
2795          $$ = MkDeclaratorFunction($1, $2);
2796          fileInput.Seek(@1.end.pos, start);
2797          yyclearin;
2798          resetScannerPos(&@1.end);
2799          @$.start = @1.start;
2800          @$.end = @1.end;
2801       }
2802    | direct_declarator_function_start_type_ok guess_declaration_specifiers identifier '('
2803       {
2804          $$ = MkDeclaratorFunction($1, null);
2805          fileInput.Seek(@1.end.pos, start);
2806          yyclearin;
2807          resetScannerPos(&@1.end);
2808          @$.start = @1.start;
2809          @$.end = @1.end;
2810          FreeList($2, FreeSpecifier);
2811          FreeIdentifier($3);
2812       }
2813         ;
2814
2815 direct_declarator_type_ok:
2816      direct_declarator_function_type_ok
2817    | direct_declarator_nofunction_type_ok
2818 /*
2819    | ext_decl direct_declarator_function_type_ok
2820       { $$ = MkDeclaratorExtended($1, $2); }
2821    | ext_decl direct_declarator_nofunction_type_ok
2822       { $$ = MkDeclaratorExtended($1, $2); }
2823 */
2824    ;
2825 /*
2826 asm_start:
2827     ASM '(' STRING_LITERAL { $<string>$ = CopyString(yytext); } STRING_LITERAL { $<string>$ = CopyString(yytext); }
2828       {
2829          char temp[1024];
2830          strcpy(temp, "__asm__(");
2831          strcat(temp, $<string>4);
2832          strcat(temp, " ");
2833          strcat(temp, $<string>6);
2834          delete $<string>4;
2835          delete $<string>6;
2836          $<string>$ = CopyString(temp);
2837       }
2838    ;
2839
2840 ext_decl:
2841      EXT_DECL { $$ = MkExtDeclString(CopyString(yytext)); }
2842    | attrib { $$ = MkExtDeclAttrib($1);
2843    | asm_start ')'
2844       {
2845          char temp[1024];
2846          strcpy(temp, $<string>1);
2847          strcat(temp, ")");
2848          delete $<string>1;
2849          $$ = MkExtDeclString(CopyString(temp));
2850       }
2851    | asm_start STRING_LITERAL { $$ = CopyString(yytext); } ')'
2852       {
2853          char temp[1024];
2854          strcpy(temp, $<string>1);
2855          strcat(temp, " ");
2856          strcat(temp, $<string>3);
2857          strcat(temp, ")");
2858          delete $<string>1;
2859          delete $<string>3;
2860          $$ = MkExtDeclString(CopyString(temp));
2861       }
2862    ;
2863 */
2864
2865 ext_decl:
2866      EXT_DECL { $$ = MkExtDeclString(CopyString(yytext)); }
2867    | EXT_STORAGE  { $$ = MkExtDeclString(CopyString(yytext)); }
2868    | attrib { $$ = MkExtDeclAttrib($1); }
2869    | ASM '(' string_literal ')'
2870       {
2871          char temp[1024];
2872          strcpy(temp, "__asm__(");
2873          strcat(temp, $3);
2874          strcat(temp, ")");
2875          $$ = MkExtDeclString(CopyString(temp));
2876          delete $3;
2877       }
2878    ;
2879
2880 _attrib:
2881    ATTRIB      { $<i>$ = ATTRIB; }
2882  | ATTRIB_DEP  { $<i>$ = ATTRIB_DEP; }
2883  | __ATTRIB    { $<i>$ = __ATTRIB; }
2884  ;
2885
2886
2887 attribute_word:
2888      IDENTIFIER   { $$  = CopyString(yytext); }
2889    | TYPE_NAME    { $$  = CopyString(yytext); }
2890    | EXT_STORAGE  { $$  = CopyString(yytext); }
2891    | EXT_DECL     { $$  = CopyString(yytext); }
2892    | CONST        { $$  = CopyString(yytext); }
2893    ;
2894
2895 attribute:
2896      attribute_word  { $$ = MkAttribute($1, null); $$.loc = @$; }
2897    | attribute_word '(' expression ')'  { $$ = MkAttribute($1, MkExpBrackets($3)); $$.loc = @$; }
2898    ;
2899
2900 attribs_list:
2901      attribute { $$ = MkListOne($1); }
2902    | attribs_list attribute { ListAdd($1, $2); $$ = $1; }
2903    | attribs_list ',' attribute { ListAdd($1, $3); $$ = $1; }
2904    ;
2905
2906 attrib:
2907      _attrib '(' '(' attribs_list ')' ')' { $$ = MkAttrib($<i>1, $4); $$.loc = @$; }
2908    | _attrib '(' '('              ')' ')'  { $$ = MkAttrib($<i>1, null); $$.loc = @$; }
2909    ;
2910
2911 direct_abstract_declarator:
2912           '(' abstract_declarator ')'               { $$ = MkDeclaratorBrackets($2); }
2913         | '(' ext_decl abstract_declarator ')'               { $$ = MkDeclaratorBrackets(MkDeclaratorExtended($2, $3)); }
2914         | '[' ']'                                   { $$ = MkDeclaratorArray(null, null); }
2915    | '[' constant_expression ']'               { $$ = MkDeclaratorArray(null, $2); }
2916         | '[' constant_expression_error ']'         { $$ = MkDeclaratorArray(null, $2); }
2917    | '[' type ']'                              { $$ = MkDeclaratorEnumArray(null, $2); }
2918         | direct_abstract_declarator '[' ']'        { $$ = MkDeclaratorArray($1, null); }
2919         | direct_abstract_declarator '[' constant_expression ']'        { $$ = MkDeclaratorArray($1, $3); }
2920         | direct_abstract_declarator '[' type']'                        { $$ = MkDeclaratorEnumArray($1, $3); }
2921         | direct_abstract_declarator '[' constant_expression_error ']'  { $$ = MkDeclaratorArray($1, $3); }
2922         | '(' ')'                                   { $$ = MkDeclaratorFunction(null, null); }
2923         | '(' parameter_type_list ')'               { $$ = MkDeclaratorFunction(null, $2); }
2924         | '(' parameter_type_list_error ')'         { $$ = MkDeclaratorFunction(null, $2); }
2925         | direct_abstract_declarator '(' ')'        { $$ = MkDeclaratorFunction($1, null); }
2926         | direct_abstract_declarator '(' parameter_type_list ')'         { $$ = MkDeclaratorFunction($1, $3); }
2927         | direct_abstract_declarator '(' parameter_type_list_error ')'   { $$ = MkDeclaratorFunction($1, $3); }
2928         ;
2929
2930 direct_abstract_declarator_noarray:
2931           '(' abstract_declarator_noarray ')'          { $$ = MkDeclaratorBrackets($2); }
2932         | '(' ext_decl abstract_declarator_noarray ')' { $$ = MkDeclaratorBrackets(MkDeclaratorExtended($2, $3)); }
2933         | '(' ')'                                      { $$ = MkDeclaratorFunction(null, null); }
2934         | '(' parameter_type_list ')'                  { $$ = MkDeclaratorFunction(null, $2); }
2935         | '(' parameter_type_list_error ')'         { $$ = MkDeclaratorFunction(null, $2); }
2936         | direct_abstract_declarator_noarray '(' ')'   { $$ = MkDeclaratorFunction($1, null); }
2937         | direct_abstract_declarator_noarray '(' parameter_type_list ')'       { $$ = MkDeclaratorFunction($1, $3); }
2938         | direct_abstract_declarator_noarray '(' parameter_type_list_error ')' { $$ = MkDeclaratorFunction($1, $3); }
2939         ;
2940
2941 pointer:
2942           '*'                               { $$ = MkPointer(null, null); }
2943         | '*' type_qualifier_list           { $$ = MkPointer($2, null); }
2944         | '*' pointer                       { $$ = MkPointer(null, $2); }
2945         | '*' type_qualifier_list pointer   { $$ = MkPointer($2, $3); }
2946         ;
2947
2948 abstract_declarator:
2949           pointer                              { $$ = MkDeclaratorPointer($1, null); }
2950         | direct_abstract_declarator
2951         | pointer direct_abstract_declarator   { $$ = MkDeclaratorPointer($1, $2); }
2952    | ext_decl pointer { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, null)); }
2953         | ext_decl pointer direct_abstract_declarator { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
2954         ;
2955
2956 abstract_declarator_noarray:
2957           pointer                              { $$ = MkDeclaratorPointer($1, null); }
2958         | direct_abstract_declarator_noarray
2959         | pointer direct_abstract_declarator_noarray   { $$ = MkDeclaratorPointer($1, $2); }
2960    | ext_decl pointer { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, null)); }
2961    | ext_decl pointer direct_abstract_declarator_noarray { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
2962         ;
2963
2964 declarator:
2965           direct_declarator
2966         | pointer direct_declarator
2967       { $$ = MkDeclaratorPointer($1, $2); }
2968    | ext_decl pointer direct_declarator
2969       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
2970    | declarator ext_decl
2971       { $$ = MkDeclaratorExtendedEnd($2, $1); }
2972    | declarator_nofunction_type_ok ext_decl
2973       { $$ = MkDeclaratorExtendedEnd($2, $1); }
2974    ;
2975
2976 declarator_type_ok:
2977           direct_declarator_type_ok
2978         | pointer direct_declarator_type_ok
2979       { $$ = MkDeclaratorPointer($1, $2); }
2980   | ext_decl pointer direct_declarator_type_ok
2981       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
2982    | declarator_type_ok ext_decl
2983       { $$ = MkDeclaratorExtendedEnd($2, $1); }
2984    ;
2985
2986 declarator_function:
2987      direct_declarator_function
2988         | pointer direct_declarator_function      { $$ = MkDeclaratorPointer($1, $2); }
2989         | ext_decl pointer direct_declarator_function { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
2990         | pointer ext_decl direct_declarator_function { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
2991    ;
2992
2993 declarator_function_error:
2994           direct_declarator_function_error
2995         | pointer direct_declarator_function_error      { $$ = MkDeclaratorPointer($1, $2); }
2996         | ext_decl pointer direct_declarator_function_error { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
2997         | pointer ext_decl direct_declarator_function_error { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
2998    ;
2999
3000 declarator_function_type_ok:
3001      direct_declarator_function_type_ok
3002         | pointer direct_declarator_function_type_ok      { $$ = MkDeclaratorPointer($1, $2); }
3003         | ext_decl pointer direct_declarator_function_type_ok { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3004         | pointer ext_decl direct_declarator_function_type_ok { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
3005    ;
3006
3007 declarator_function_error_type_ok:
3008           direct_declarator_function_error_type_ok
3009         | pointer direct_declarator_function_error_type_ok      { $$ = MkDeclaratorPointer($1, $2); }
3010         | ext_decl pointer direct_declarator_function_error_type_ok { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3011         | pointer ext_decl direct_declarator_function_error_type_ok { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
3012    ;
3013
3014 declarator_nofunction_type_ok:
3015           direct_declarator_nofunction_type_ok
3016         | pointer direct_declarator_nofunction_type_ok      { $$ = MkDeclaratorPointer($1, $2); }
3017         | ext_decl pointer direct_declarator_nofunction_type_ok { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3018         | pointer ext_decl direct_declarator_nofunction_type_ok { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
3019    ;
3020
3021 initializer:
3022           assignment_expression          { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3023         | '{' initializer_list '}'       { $$ = MkInitializerList($2); $$.loc = @$; }
3024         | '{' initializer_list ',' '}'
3025       {
3026          Compiler_Warning($"extra comma\n");
3027          $$ = MkInitializerList($2);
3028          $$.loc = @$;
3029
3030          {
3031             Expression exp = MkExpDummy();
3032             Initializer init = MkInitializerAssignment(exp);
3033             init.loc = @3;
3034             exp.loc = @3;
3035             ListAdd($2, init);
3036          }
3037       }
3038         ;
3039
3040 initializer_error:
3041      assignment_expression_error    { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3042         | '{' initializer_list '}' error      { $$ = MkInitializerList($2); $$.loc = @$; }
3043    | '{' initializer_list                 { yyerror(); $$ = MkInitializerList($2); $$.loc = @$; }
3044         | '{' initializer_list ',' '}' error
3045       {
3046          $$ = MkInitializerList($2);
3047          $$.loc = @$;
3048
3049          {
3050             Expression exp = MkExpDummy();
3051             Initializer init = MkInitializerAssignment(exp);
3052             init.loc = @3;
3053             exp.loc = @3;
3054             ListAdd($2, init);
3055          }
3056       }
3057         | '{' initializer_list ','
3058       {
3059          yyerror();
3060          $$ = MkInitializerList($2);
3061          $$.loc = @$;
3062
3063          {
3064             Expression exp = MkExpDummy();
3065             Initializer init = MkInitializerAssignment(exp);
3066             init.loc = @3;
3067             exp.loc = @3;
3068             ListAdd($2, init);
3069          }
3070       }
3071         ;
3072
3073 initializer_condition:
3074           conditional_expression          { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3075    | anon_instantiation_expression
3076       { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3077         ;
3078
3079 initializer_condition_error:
3080      conditional_expression_error    { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3081    | anon_instantiation_expression_error  { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3082         ;
3083
3084 initializer_list:
3085           initializer                       { $$ = MkList(); ListAdd($$, $1); }
3086    | initializer_error                 { $$ = MkList(); ListAdd($$, $1); }
3087         | initializer_list ',' initializer  { $$ = $1; ListAdd($1, $3); }
3088    | initializer_list ',' initializer_error  { $$ = $1; ListAdd($1, $3); }
3089
3090    // Errors
3091         | initializer_list initializer  { yyerror(); $$ = $1; ListAdd($1, $2); }
3092    | initializer_list initializer_error  { $$ = $1; ListAdd($1, $2); }
3093         ;
3094
3095 init_declarator:
3096           declarator                     { $$ = MkInitDeclarator($1, null); $$.loc = @$; }
3097    | declarator_type_ok             { $$ = MkInitDeclarator($1, null); $$.loc = @$; }
3098         | declarator '=' initializer     { $$ = MkInitDeclarator($1, $3); $$.loc = @$; $$.initializer.loc.start = @2.end; }
3099         ;
3100
3101 init_declarator_error:
3102           declarator error                 { $$ = MkInitDeclarator($1, null); $$.loc = @$; }
3103    /* Useless rules due to conflicts
3104    | declarator '=' error                 { $$ = MkInitDeclarator($1, MkInitializerAssignment(MkExpDummy())); $$.loc = @$; $$.initializer.loc = @2; $$.initializer.exp.loc = @2; }
3105    */
3106         | declarator '=' initializer_error     { $$ = MkInitDeclarator($1, $3); $$.loc = @$; $$.initializer.loc.start = @2.end; }
3107         ;
3108
3109 init_declarator_list:
3110           init_declarator                            { $$ = MkList(); ListAdd($$, $1); }
3111         | init_declarator_list ',' init_declarator   { $$ = $1; ListAdd($1, $3); }
3112         | UINT ',' init_declarator                  { $$ = MkList(); ListAdd($$, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("uint")), null)); ListAdd($$, $3); }
3113    | INT64 ',' init_declarator                  { $$ = MkList(); ListAdd($$, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("int64")), null)); ListAdd($$, $3); }
3114    | INT128 ',' init_declarator                 { $$ = MkList(); ListAdd($$, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("__int128")), null)); ListAdd($$, $3); }
3115         | base_strict_type ',' init_declarator
3116    {
3117       char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
3118       String s = colon ? colon + 2 : $1.name;
3119       $$ = MkList();
3120       ListAdd($$, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
3121       ListAdd($$, $3);
3122       FreeSpecifier($1);
3123    }
3124    | init_declarator_list_error ',' init_declarator   { $$ = $1; ListAdd($1, $3); }
3125    /*| base_strict_type ',' init_declarator
3126       {
3127          $$ = MkList();
3128          ListAdd($1, $3);
3129       }*/
3130         ;
3131
3132 init_declarator_list_error:
3133           init_declarator_error                            { $$ = MkList(); ListAdd($$, $1); }
3134    | init_declarator error                            { $$ = MkList(); ListAdd($$, $1); }
3135         | init_declarator_list ',' init_declarator_error   { $$ = $1; ListAdd($1, $3); }
3136    | init_declarator_list_error ',' init_declarator_error   { $$ = $1; ListAdd($1, $3); }
3137         ;
3138
3139 type_name:
3140           specifier_qualifier_list                      { $$ = MkTypeName($1, null); }
3141         | specifier_qualifier_list abstract_declarator  { $$ = MkTypeName($1, $2); }
3142         ;
3143
3144 guess_type_name:
3145           guess_specifier_qualifier_list                         { $$ = MkTypeName($1, null); }
3146         | guess_specifier_qualifier_list abstract_declarator     { $$ = MkTypeName($1, $2); }
3147         ;
3148
3149 /*** PARAMETERS **********************************************************************/
3150 parameter_declaration:
3151      guess_declaration_specifiers declarator_type_ok          { $$ = MkTypeName($1, $2); }
3152    | guess_declaration_specifiers abstract_declarator { $$ = MkTypeName($1, $2); }
3153    | guess_declaration_specifiers '&'                 { $$ = MkTypeName($1, MkDeclaratorPointer(MkPointer(null,null), null)); }
3154    | guess_declaration_specifiers '&' declarator_type_ok      { $$ = MkTypeName($1, MkDeclaratorPointer(MkPointer(null,null), $3)); }
3155         | guess_declaration_specifiers                     { $$ = MkTypeNameGuessDecl($1, null); }
3156    | CLASS
3157       { $$ = MkTypeName(MkListOne(MkSpecifier(CLASS)), null); }
3158 /*
3159    | TYPED_OBJECT
3160       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), null); }
3161    | TYPED_OBJECT '&'
3162       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), MkDeclaratorPointer(MkPointer(null,null), null)); }
3163    | TYPED_OBJECT declarator
3164       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), $2);  }
3165    | TYPED_OBJECT '&' declarator
3166       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), MkDeclaratorPointer(MkPointer(null,null), $3)); }
3167    | ANY_OBJECT
3168       { $$ = MkTypeName(MkListOne(MkSpecifier(ANY_OBJECT)), null); }
3169    | ANY_OBJECT declarator
3170       { $$ = MkTypeName(MkListOne(MkSpecifier(ANY_OBJECT)), $2); }
3171 */
3172         ;
3173
3174 parameter_declaration_error:
3175           guess_declaration_specifiers declarator_type_ok error          { $$ = MkTypeName($1, $2); }
3176         | guess_declaration_specifiers abstract_declarator error { $$ = MkTypeName($1, $2); }
3177         ;
3178
3179 parameter_list:
3180           parameter_declaration                      { $$ = MkList(); ListAdd($$, $1); }
3181         | parameter_list ',' parameter_declaration   { $$ = $1; ListAdd($1, $3); }
3182    | parameter_list error ',' parameter_declaration   { $$ = $1; ListAdd($1, $4); }
3183    | parameter_list_error ',' parameter_declaration   { $$ = $1; ListAdd($1, $3); }
3184    | parameter_list_error error ',' parameter_declaration   { $$ = $1; ListAdd($1, $4); }
3185    | error ',' parameter_declaration   { $$ = MkList(); ListAdd($$, MkTypeName(MkList(), null)); ListAdd($$, $3); }
3186
3187         | identifier_list ',' parameter_declaration   { $$ = $1; ListAdd($1, $3); }
3188    | identifier_list error ',' parameter_declaration   { $$ = $1; ListAdd($1, $4); }
3189    | identifier_list_error ',' parameter_declaration   { $$ = $1; ListAdd($1, $3); }
3190    | identifier_list_error error ',' parameter_declaration   { $$ = $1; ListAdd($1, $4); }
3191 ;
3192
3193 parameter_list_error:
3194           parameter_declaration_error                      { $$ = MkList(); ListAdd($$, $1); }
3195         | parameter_list ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $3); }
3196    | parameter_list_error ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $3); }
3197    | parameter_list_error error ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $4); }
3198    | error ',' parameter_declaration_error   { $$ = MkList(); ListAdd($$, MkTypeName(MkList(), null)); ListAdd($$, $3); }
3199
3200         | identifier_list ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $3); }
3201    | identifier_list_error ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $3); }
3202    | identifier_list_error error ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $4); }
3203         ;
3204
3205 parameter_type_list:
3206           parameter_list
3207         | parameter_list ',' ELLIPSIS                { $$ = $1; ListAdd($1, MkTypeName(null, null)); }
3208    | parameter_list_error ',' ELLIPSIS                { $$ = $1; ListAdd($1, MkTypeName(null, null)); }
3209         | identifier_list ',' ELLIPSIS                { $$ = $1; ListAdd($1, MkTypeName(null, null)); }
3210    | identifier_list_error ',' ELLIPSIS                { $$ = $1; ListAdd($1, MkTypeName(null, null)); }
3211    | error ',' ELLIPSIS                { $$ = MkList(); ListAdd($$, MkTypeName(null, null)); }
3212         ;
3213
3214 parameter_type_list_error:
3215     parameter_list_error
3216    | parameter_list ',' error                { $$ = $1; ListAdd($1, null); }
3217    | parameter_list_error error
3218         ;
3219
3220 /****** STATEMENTS *******************************************************************/
3221 statement:
3222           labeled_statement
3223    | attrib { $$ = MkExpressionStmt(null); FreeAttrib($1); }   // Ignoring this for now... ( For __attribute__ ((__unused__)) )
3224         | compound_statement
3225    | ';' { $$ = MkExpressionStmt(null); }
3226    | ':' { $$ = MkExpressionStmt(null); }
3227         | expression ';'              { $$ = MkExpressionStmt($1); $$.loc = @$; }
3228         | selection_statement
3229         | iteration_statement
3230         | jump_statement
3231    | asm_statement
3232    | firewatchers ';'
3233    | stopwatching ';'
3234    | watch_definition ';'
3235         ;
3236
3237 statement_error:
3238         labeled_statement_error          { $$ = $1; Compiler_Error($"syntax error\n"); }
3239    | iteration_statement_error      { $$ = $1; Compiler_Error($"syntax error\n"); }
3240    | compound_statement_error       { $$ = $1; Compiler_Error($"syntax error\n"); }
3241         | selection_statement_error      { $$ = $1; Compiler_Error($"syntax error\n"); }
3242    | jump_statement_error           { $$ = $1; Compiler_Error($"syntax error\n"); }
3243         | jump_statement error           { $$ = $1; Compiler_Error($"syntax error\n"); }
3244    | expression_error { $$ = MkExpressionStmt($1); Compiler_Error($"syntax error\n"); $$.loc = @1; }
3245    ;
3246
3247 asm_field:
3248      string_literal { $$ = MkAsmField($1, null, null); $$.loc = @1; }
3249    | string_literal '(' assignment_expression ')' { $$ = MkAsmField($1, $3, null); $$.loc = @$; }
3250    | '[' identifier ']' string_literal '(' assignment_expression ')' { $$ = MkAsmField($4, $6, $2); $$.loc = @$; }
3251    ;
3252
3253 asm_field_list:
3254      asm_field { $$ = MkListOne($1); }
3255    | asm_field_list ',' asm_field { ListAdd($$, $3); }
3256    | { $$ = null; }
3257    ;
3258
3259 asm_statement:
3260      ASM type_qualifier '(' string_literal ')' ';'                                                          { $$ = MkAsmStmt($2, $4, null, null, null); $$.loc = @$; }
3261    | ASM type_qualifier '(' string_literal ':' asm_field_list ')' ';'                                       { $$ = MkAsmStmt($2, $4, $6, null, null); $$.loc = @$; }
3262    | ASM type_qualifier '(' string_literal ':' asm_field_list ':' asm_field_list ')' ';'                    { $$ = MkAsmStmt($2, $4, $6, $8, null); $$.loc = @$; }
3263    | ASM type_qualifier '(' string_literal ':' asm_field_list ':' asm_field_list ':' asm_field_list ')' ';' { $$ = MkAsmStmt($2, $4, $6, $8, $10); $$.loc = @$; }
3264
3265    | ASM type_qualifier '(' string_literal IDENTIFIER asm_field_list ')' ';'                                { $$ = MkAsmStmt($2, $4, null, $6, null); $$.loc = @$; }
3266    | ASM type_qualifier '(' string_literal IDENTIFIER asm_field_list ':' asm_field_list ')' ';'             { $$ = MkAsmStmt($2, $4, null, $6, $8); $$.loc = @$; }
3267    | ASM type_qualifier '(' string_literal ':' asm_field_list IDENTIFIER asm_field_list ')' ';'             { $$ = MkAsmStmt($2, $4, $6, null, $8); $$.loc = @$; }
3268
3269    | ASM '(' string_literal ')' ';'                                                                         { $$ = MkAsmStmt(null, $3, null, null, null); $$.loc = @$; }
3270    | ASM '(' string_literal ':' asm_field_list ')' ';'                                                      { $$ = MkAsmStmt(null, $3, $5, null, null); $$.loc = @$; }
3271    | ASM '(' string_literal ':' asm_field_list ':' asm_field_list ')' ';'                                   { $$ = MkAsmStmt(null, $3, $5, $7, null); $$.loc = @$; }
3272    | ASM '(' string_literal ':' asm_field_list ':' asm_field_list ':' asm_field_list ')' ';'                { $$ = MkAsmStmt(null, $3, $5, $7, $9); $$.loc = @$; }
3273
3274    | ASM '(' string_literal IDENTIFIER asm_field_list ')' ';'                                               { $$ = MkAsmStmt(null, $3, null, $5, null); $$.loc = @$; }
3275    | ASM '(' string_literal IDENTIFIER asm_field_list ':' asm_field_list ')' ';'                            { $$ = MkAsmStmt(null, $3, null, $5, $7); $$.loc = @$; }
3276    | ASM '(' string_literal ':' asm_field_list IDENTIFIER asm_field_list ')' ';'                            { $$ = MkAsmStmt(null, $3, $5, null, $7); $$.loc = @$; }
3277    ;
3278
3279 labeled_statement:
3280      identifier ':' statement                      { $$ = MkLabeledStmt($1, $3); $$.loc = @$; }
3281    | CASE constant_expression ':' statement        { /*if($4.type == labeledStmt) Compiler_Warning(CASE_LABELED_STMT_WARNING);*/ $$ = MkCaseStmt($2, $4); $$.loc = @$; $2.loc.start = @1.end; }
3282    | CASE constant_expression_error ':' statement  { /*if($4.type == labeledStmt) Compiler_Warning(CASE_LABELED_STMT_WARNING);*/ $$ = MkCaseStmt($2, $4); $$.loc = @$; $2.loc.start = @1.end; }
3283    | CASE ':' statement                            { /*if($3.type == labeledStmt) Compiler_Warning(CASE_LABELED_STMT_WARNING);*/ $$ = MkCaseStmt(MkExpDummy(), $3); $$.caseStmt.exp.loc = @2; $$.loc = @$; $$.caseStmt.exp.loc.start = @1.end; }
3284    | DEFAULT ':' statement                         { /*if($3.type == labeledStmt) Compiler_Warning(CASE_LABELED_STMT_WARNING);*/ $$ = MkCaseStmt(null, $3); $$.loc = @$; }
3285
3286    | identifier ':' declaration                      { Statement stmt = MkBadDeclStmt($3); stmt.loc = @3; Compiler_Warning(C89_DECL_WARNING); $$ = MkLabeledStmt($1, stmt); $$.loc = @$; }
3287    | CASE constant_expression ':' declaration        { Statement stmt = MkBadDeclStmt($4); stmt.loc = @4; Compiler_Warning(C89_DECL_WARNING); $$ = MkCaseStmt($2, stmt); $$.loc = @$; $2.loc.start = @1.end; }
3288    | CASE constant_expression_error ':' declaration  { Statement stmt = MkBadDeclStmt($4); stmt.loc = @4; Compiler_Warning(C89_DECL_WARNING); $$ = MkCaseStmt($2, stmt); $$.loc = @$; $2.loc.start = @1.end; }
3289    | CASE ':' declaration                            { Statement stmt = MkBadDeclStmt($3); stmt.loc = @3; Compiler_Warning(C89_DECL_WARNING); $$ = MkCaseStmt(MkExpDummy(), stmt); $$.caseStmt.exp.loc = @2; $$.loc = @$; $$.caseStmt.exp.loc.start = @1.end; }
3290    | DEFAULT ':' declaration                         { Statement stmt = MkBadDeclStmt($3); stmt.loc = @3; Compiler_Warning(C89_DECL_WARNING); $$ = MkCaseStmt(null, stmt); $$.loc = @$; }
3291    ;
3292
3293 labeled_statement_error:
3294           identifier ':' statement_error                { $$ = MkLabeledStmt($1, $3); $$.loc = @$; }
3295    | CASE constant_expression ':' statement_error  { /*if($4.type == labeledStmt) Compiler_Warning(CASE_LABELED_STMT_WARNING);*/ $$ = MkCaseStmt($2, $4); $$.loc = @$; $2.loc.start = @1.end; }
3296    | CASE constant_expression_error ':' statement_error  { /*if($4.type == labeledStmt) Compiler_Warning(CASE_LABELED_STMT_WARNING);*/ $$ = MkCaseStmt($2, $4); $$.loc = @$; $2.loc.start = @1.end; }
3297    | CASE ':' statement_error  { /*if($3.type == labeledStmt) Compiler_Warning(CASE_LABELED_STMT_WARNING);*/ $$ = MkCaseStmt(MkExpDummy(), $3); $$.caseStmt.exp.loc = @2; $$.loc = @$; $$.caseStmt.exp.loc.start = @1.end; }
3298    | CASE ':' { $$ = MkCaseStmt(MkExpDummy(), null); $$.caseStmt.exp.loc = @2; $$.loc = @$; $$.caseStmt.exp.loc.start = @1.end; }
3299         | DEFAULT ':' statement_error                   { /*if($3.type == labeledStmt) Compiler_Warning(CASE_LABELED_STMT_WARNING);*/ $$ = MkCaseStmt(null, $3); $$.loc = @$; }
3300    | DEFAULT ':'  { $$ = MkCaseStmt(null, null); $$.loc = @$; }
3301
3302    | identifier ':' declaration_error                      { Statement stmt = MkBadDeclStmt($3); stmt.loc = @3; Compiler_Warning(C89_DECL_WARNING); $$ = MkLabeledStmt($1, stmt); $$.loc = @$; }
3303    | CASE constant_expression ':' declaration_error        { Statement stmt = MkBadDeclStmt($4); stmt.loc = @4; Compiler_Warning(C89_DECL_WARNING); $$ = MkCaseStmt($2, stmt); $$.loc = @$; $2.loc.start = @1.end; }
3304    | CASE constant_expression_error ':' declaration_error  { Statement stmt = MkBadDeclStmt($4); stmt.loc = @4; Compiler_Warning(C89_DECL_WARNING); $$ = MkCaseStmt($2, stmt); $$.loc = @$; $2.loc.start = @1.end; }
3305    | CASE ':' declaration_error                            { Statement stmt = MkBadDeclStmt($3); stmt.loc = @3; Compiler_Warning(C89_DECL_WARNING); $$ = MkCaseStmt(MkExpDummy(), stmt); $$.caseStmt.exp.loc = @2; $$.loc = @$; $$.caseStmt.exp.loc.start = @1.end; }
3306    | DEFAULT ':' declaration_error                         { Statement stmt = MkBadDeclStmt($3); stmt.loc = @3; Compiler_Warning(C89_DECL_WARNING); $$ = MkCaseStmt(null, stmt); $$.loc = @$; }
3307         ;
3308
3309 declaration_mode:
3310      PUBLIC    { $$ = structDeclMode = declMode = publicAccess; }
3311    | PRIVATE   { $$ = structDeclMode = declMode = privateAccess; }
3312    | DEFAULT   { $$ = structDeclMode = declMode = defaultAccess; }
3313    ;
3314
3315 member_access:
3316      PUBLIC    { $$ = publicAccess; }
3317    | PRIVATE   { $$ = privateAccess; }
3318    ;
3319
3320 declaration:
3321           declaration_specifiers ';'                       { $$ = MkDeclaration($1, null); $$.loc = @$; structDeclMode = defaultDeclMode; }
3322         | declaration_specifiers init_declarator_list ';'  { $$ = MkDeclaration($1, $2); $$.loc = @$; structDeclMode = defaultDeclMode; }
3323    | instantiation_named ';'                          { $$ = MkDeclarationInst($1); $$.loc = @$; structDeclMode = defaultDeclMode; }
3324    | declaration_error ';'                            { $$ = $1; structDeclMode = defaultDeclMode; }
3325         ;
3326
3327 external_guess_declaration:
3328      external_guess_declaration_specifiers ';'                 { $$ = MkDeclaration($1, null); $$.loc = @$; }
3329    | external_guess_declaration_specifiers init_declarator_list ';'                { $$ = MkDeclaration($1, $2); $$.loc = @$; }
3330    | external_guess_declaration_specifiers_error init_declarator_list ';'                { $$ = MkDeclaration($1, $2); $$.loc = @$; }
3331
3332    | external_guess_instantiation_named ';'                          { $$ = MkDeclarationInst($1); $$.loc = @$; }
3333    | DEFINE identifier '=' conditional_expression ';' { $$ = MkDeclarationDefine($2, $4); $$.loc = @$; }
3334    | STATIC DEFINE identifier '=' conditional_expression ';' { structDeclMode = declMode = staticAccess; $$ = MkDeclarationDefine($3, $5); $$.loc = @$; }
3335         ;
3336
3337 external_guess_declaration_error:
3338    external_guess_declaration_specifiers error { $$ = MkDeclaration($1, null); $$.loc = @$; yyerrok; }
3339         ;
3340
3341 declaration_error:
3342      declaration_specifiers error                       { $$ = MkDeclaration($1, null); $$.loc = @$; structDeclMode = defaultDeclMode; }
3343    | declaration_error error                            { structDeclMode = defaultDeclMode;  }
3344
3345    | instantiation_named_error error                   { $$ = MkDeclarationInst($1); $$.loc = @$; structDeclMode = defaultDeclMode; }
3346    | instantiation_named error                         { $$ = MkDeclarationInst($1); $$.loc = @$; structDeclMode = defaultDeclMode; }
3347    | declaration_specifiers init_declarator_list_error  { $$ = MkDeclaration($1, $2); $$.loc = @$; structDeclMode = defaultDeclMode; }
3348    ;
3349
3350 declaration_list:
3351           declaration                       { $$ = MkList(); ListAdd($$, $1); /*declMode = defaultDeclMode;*/ }
3352         | declaration_list declaration      { $$ = $1; ListAdd($1, $2); /*declMode = defaultDeclMode; */}
3353    | declaration_list_error declaration      { $$ = $1; ListAdd($1, $2); /*declMode = defaultDeclMode; */}
3354    | declaration_list error ';'       { $$ = $1; }
3355         ;
3356
3357 declaration_list_error:
3358     declaration_error                       { $$ = MkList(); ListAdd($$, $1); }
3359    | declaration_list declaration_error { $$ = $1; ListAdd($1, $2); }
3360         ;
3361
3362 statement_list:
3363           statement                         { $$ = MkList(); ListAdd($$, $1); }
3364         | statement_list statement          { $$ = $1; ListAdd($1, $2); }
3365    | statement_list_error statement          { $$ = $1; ListAdd($1, $2); }
3366         ;
3367
3368 statement_list_error:
3369      statement_error                   { $$ = MkList(); ListAdd($$, $1); }
3370    | statement_list statement_error          { $$ = $1; ListAdd($1, $2); }
3371    | statement_list_error statement_error          { $$ = $1; ListAdd($1, $2); }
3372    | statement_list declaration              { Statement stmt = MkBadDeclStmt($2); stmt.loc = @2; Compiler_Warning(C89_DECL_WARNING); $$ = $1; ListAdd($1, stmt); /*declMode = defaultDeclMode;*/ }
3373    | statement_list_error declaration        { Statement stmt = MkBadDeclStmt($2); stmt.loc = @2; Compiler_Warning(C89_DECL_WARNING); $$ = $1; ListAdd($1, stmt); /*declMode = defaultDeclMode;*/ }
3374    | statement_list declaration_error        { Statement stmt = MkBadDeclStmt($2); stmt.loc = @2; Compiler_Warning(C89_DECL_WARNING); $$ = $1; ListAdd($1, stmt); /*declMode = defaultDeclMode;*/ }
3375    | statement_list_error declaration_error  { Statement stmt = MkBadDeclStmt($2); stmt.loc = @2; Compiler_Warning(C89_DECL_WARNING); $$ = $1; ListAdd($1, stmt); /*declMode = defaultDeclMode;*/ }
3376    ;
3377
3378 compound_inside:
3379         statement_list                      { $$ = MkCompoundStmt(null, $1); }
3380         | declaration_list                  { $$ = MkCompoundStmt($1, null); }
3381         | declaration_list statement_list   { $$ = MkCompoundStmt($1, $2); }
3382    | declaration_list_error statement_list   { $$ = MkCompoundStmt($1, $2); }
3383    ;
3384
3385 compound_inside_error:
3386         statement_list_error                      { $$ = MkCompoundStmt(null, $1); }
3387         | declaration_list_error                  { $$ = MkCompoundStmt($1, null); }
3388         | declaration_list statement_list_error   { $$ = MkCompoundStmt($1, $2); }
3389    | declaration_list_error statement_list_error   { $$ = MkCompoundStmt($1, $2); }
3390    ;
3391
3392 compound_start:
3393     '{' { $<context>$ = PushContext(); }
3394     ;
3395
3396 compound_statement:
3397    compound_statement_error '}'     { $$ = $1; $$.loc = @$; }
3398         ;
3399
3400 compound_statement_error:
3401           compound_start compound_inside_error
3402       { $$ = $2; $$.compound.context = $<context>1; PopContext($<context>1); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; }
3403    |    compound_start
3404       { $$ = MkCompoundStmt(null, null); $$.compound.context = $<context>1; PopContext($<context>1); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; }
3405
3406         | compound_start compound_inside
3407       { $$ = $2; $$.compound.context = $<context>1; PopContext($<context>1); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; }
3408
3409         ;
3410
3411 expression_statement:
3412         ';'                         { $$ = MkExpressionStmt(null); $$.loc = @$; }
3413         | expression ';'              { $$ = MkExpressionStmt($1); $$.loc = @$; }
3414    | expression_error ';'            { $$ = MkExpressionStmt($1); $$.loc = @$; }
3415         ;
3416
3417 selection_statement:
3418           IF '(' expression ')' statement %prec IFX        { $$ = MkIfStmt($3, $5, null); $$.loc = @$; }
3419    | IF '(' expression_error ')' statement %prec IFX        { $$ = MkIfStmt($3, $5, null); $$.loc = @$; }
3420         | IF '(' expression ')' statement ELSE statement   { $$ = MkIfStmt($3, $5, $7); $$.loc = @$; }
3421    | IF '(' expression_error ')' statement ELSE statement   { $$ = MkIfStmt($3, $5, $7); $$.loc = @$; }
3422         | SWITCH '(' expression ')' statement              { $$ = MkSwitchStmt($3, $5); $$.loc = @$; }
3423    | SWITCH '(' expression_error ')' statement              { $$ = MkSwitchStmt($3, $5); $$.loc = @$; }
3424         ;
3425
3426 selection_statement_error:
3427    IF '(' expression_error    { $$ = MkIfStmt($3, null, null); $$.loc = @$; }
3428    | selection_statement error
3429    ;
3430
3431 iteration_statement:
3432           WHILE '(' expression ')' statement           { $$ = MkWhileStmt($3, $5); $$.loc = @$; }
3433    | WHILE '(' expression_error statement     { $$ = MkWhileStmt($3, $4); $$.loc = @$; }
3434    | WHILE '(' ')' statement     { yyerror(); $$ = MkWhileStmt(null, $4); $$.loc = @$; }
3435
3436         | DO statement WHILE '(' expression ')' ';'     { $$ = MkDoWhileStmt($2, $5); $$.loc = @$; }
3437    | DO statement WHILE '(' expression_error ';'     { $$ = MkDoWhileStmt($2, $5); $$.loc = @$; }
3438
3439         | FOR '(' expression_statement expression_statement ')' statement                   { $$ = MkForStmt($3, $4, null, $6); $$.loc = @$; }
3440    | FOR '(' expression_statement ')' statement                   { yyerror(); $$ = MkForStmt($3, null, null, $5); $$.loc = @$; }
3441         | FOR '(' expression_statement expression_statement expression ')' statement        { $$ = MkForStmt($3, $4, $5, $7); $$.loc = @$; }
3442    | FOR '(' expression_statement expression_statement expression_error statement  { $$ = MkForStmt($3, $4, $5, $6 ); $$.loc = @$; }
3443    | FOR '(' ')' statement  { yyerror(); $$ = MkForStmt(null, null, null, $4); $$.loc = @$; }
3444
3445    | FOR '(' identifier ':' expression ')' statement                   { $$ = MkForEachStmt($3, $5, null, $7); $$.loc = @$; }
3446    | FOR '(' identifier ':' expression ';' expression ')' statement    { $$ = MkForEachStmt($3, $5, $7, $9); $$.loc = @$; }
3447         ;
3448
3449 iteration_statement_error:
3450    FOR '(' error                                                        { $$ = MkForStmt(null, null, null, null); $$.loc = @$; } |
3451         FOR '(' expression_error error                                       { $$ = MkForStmt(MkExpressionStmt($3), null, null, null); $$.forStmt.init.loc = @3; $$.loc = @$; } |
3452         FOR '(' expression_statement error                                   { $$ = MkForStmt($3, null, null, null); $$.loc = @$; } |
3453         FOR '(' expression_statement expression_error error                  { $$ = MkForStmt($3, MkExpressionStmt($4), null, null); $$.loc = @$; $$.forStmt.check.loc = @4; } |
3454    /* Useless rules due to conflicts
3455         FOR '(' expression_statement expression_statement error              { $$ = MkForStmt($3, $4, null, null); $$.loc = @$; } |
3456    */
3457    FOR '(' expression_statement expression_statement expression_error   { $$ = MkForStmt($3, $4, $5, null); $$.loc = @$; } |
3458         FOR '(' expression_statement expression_statement ')' statement_error                   { $$ = MkForStmt($3, $4, null, $6); $$.loc = @$; } |
3459         FOR '(' expression_statement expression_statement expression ')' statement_error  { $$ = MkForStmt($3, $4, $5, $7); $$.loc = @$; } |
3460    FOR '(' expression_statement expression_statement expression_error statement_error  { $$ = MkForStmt($3, $4, $5, $6 ); $$.loc = @$; } |
3461
3462         DO statement WHILE '(' expression ')'     { yyerror(); $$ = MkDoWhileStmt($2, $5); $$.loc = @$; } |
3463         DO statement WHILE '(' expression      { yyerror(); $$ = MkDoWhileStmt($2, $5); $$.loc = @$; } |
3464    DO statement WHILE '(' expression_error      { $$ = MkDoWhileStmt($2, $5); $$.loc = @$; } |
3465         DO statement WHILE '(' { $$ = MkDoWhileStmt($2, null); $$.loc = @$; } |
3466    DO statement WHILE { yyerror(); $$ = MkDoWhileStmt($2, null); $$.loc = @$; } |
3467         DO statement { yyerror(); $$ = MkDoWhileStmt($2, null); $$.loc = @$; } |
3468    DO { yyerror(); $$ = MkDoWhileStmt(null, null); $$.loc = @$; } |
3469
3470
3471    WHILE error           { $$ = MkWhileStmt(null, null); $$.loc = @$; } |
3472    /* Useless rules due to conflicts
3473         WHILE '(' error           { $$ = MkWhileStmt(null, null); $$.loc = @$; } |
3474    */
3475    WHILE '(' ')' error           { $$ = MkWhileStmt(null, null); $$.loc = @$; } |
3476         WHILE '(' expression_error           { $$ = MkWhileStmt($3, null); $$.loc = @$; } |
3477    /* Useless rules due to conflicts
3478    WHILE '(' expression_error error          { $$ = MkWhileStmt($3, null); $$.loc = @$; } |
3479    */
3480         WHILE '(' expression ')' statement_error           { $$ = MkWhileStmt($3, $5); $$.loc = @$; } |
3481    WHILE '(' expression_error statement_error     { $$ = MkWhileStmt($3, $4 ); $$.loc = @$; }
3482
3483
3484 jump_statement:
3485           GOTO identifier ';'   { $$ = MkGotoStmt($2); $$.loc = @$; }
3486         | CONTINUE ';'          { $$ = MkContinueStmt(); $$.loc = @$; }
3487         | BREAK ';'             { $$ = MkBreakStmt(); $$.loc = @$; }
3488         | RETURN ';'            { Expression exp = MkExpDummy(); $$ = MkReturnStmt(MkListOne(exp)); $$.loc = @$; exp.loc = @2; }
3489         | RETURN expression ';' { $$ = MkReturnStmt($2); $$.loc = @$; }
3490    | RETURN expression_error ';' { $$ = MkReturnStmt($2); $$.loc = @$; }
3491         | RETURN anon_instantiation_expression ';' { $$ = MkReturnStmt(MkListOne($2)); $$.loc = @$; }
3492    | RETURN anon_instantiation_expression_error ';' { $$ = MkReturnStmt(MkListOne($2)); $$.loc = @$; }
3493         ;
3494
3495 jump_statement_error:
3496      RETURN expression_error { $$ = MkReturnStmt($2); $$.loc = @$; } |
3497      RETURN anon_instantiation_expression_error { $$ = MkReturnStmt(MkListOne($2)); $$.loc = @$; } |
3498      RETURN { Expression exp = MkExpDummy(); $$ = MkReturnStmt(MkListOne(exp)); $$.loc = @$; exp.loc.start = exp.loc.end = @1.end; } |
3499      GOTO { $$ = MkGotoStmt(null); $$.loc = @$; }
3500         ;
3501
3502 /*************************************************************************************/
3503
3504 function_definition:
3505           external_guess_declaration_specifiers declarator_function declaration_list compound_statement      { $$ = MkFunction($1, $2, $3); ProcessFunctionBody($$, $4); $$.loc = @$; }
3506         | external_guess_declaration_specifiers declarator_function compound_statement
3507        { $$ = MkFunction($1, $2, null); ProcessFunctionBody($$, $3); $$.loc = @$; }
3508         | external_guess_declaration_specifiers declarator_function_type_ok declaration_list compound_statement      { $$ = MkFunction($1, $2, $3); ProcessFunctionBody($$, $4); $$.loc = @$; }
3509         | external_guess_declaration_specifiers declarator_function_type_ok compound_statement
3510        { $$ = MkFunction($1, $2, null); ProcessFunctionBody($$, $3); $$.loc = @$; }
3511
3512         | declarator_function declaration_list compound_statement                             { $$ = MkFunction(null, $1, $2); ProcessFunctionBody($$, $3); $$.loc = @$; }
3513         | declarator_function compound_statement                                              { $$ = MkFunction(null, $1, null); ProcessFunctionBody($$, $2); $$.loc = @$;}
3514    ;
3515 function_definition_error:
3516      external_guess_declaration_specifiers declarator_function declaration_list compound_statement_error      { $$ = MkFunction($1, $2, $3); ProcessFunctionBody($$, $4); $$.loc = @$; $$.loc.end = $4.loc.end; }
3517         | external_guess_declaration_specifiers declarator_function compound_statement_error                       { $$ = MkFunction($1, $2, null); ProcessFunctionBody($$, $3); $$.loc = @$; $$.loc.end = $3.loc.end; }
3518    | external_guess_declaration_specifiers declarator_function_type_ok declaration_list compound_statement_error      { $$ = MkFunction($1, $2, $3); ProcessFunctionBody($$, $4); $$.loc = @$; $$.loc.end = $4.loc.end; }
3519         | external_guess_declaration_specifiers declarator_function_type_ok compound_statement_error                       { $$ = MkFunction($1, $2, null); ProcessFunctionBody($$, $3); $$.loc = @$; $$.loc.end = $3.loc.end; }
3520         | declarator_function declaration_list compound_statement_error                             { $$ = MkFunction(null, $1, $2); ProcessFunctionBody($$, $3); $$.loc = @$; $$.loc.end = $3.loc.end; }
3521         | declarator_function compound_statement_error                                              { $$ = MkFunction(null, $1, null); ProcessFunctionBody($$, $2); $$.loc = @$; $$.loc.end = $2.loc.end; }
3522    ;
3523
3524 string_literal:
3525    STRING_LITERAL { $$ = CopyString(yytext); }
3526    | string_literal STRING_LITERAL
3527    {
3528       int len1 = strlen($1);
3529       int len2 = strlen(yytext);
3530       $$ = new byte[len1-1 + len2-1 + 1];
3531       memcpy($$, $1, len1-1);
3532       memcpy($$ + len1-1, yytext+1, len2);
3533       delete $1;
3534    }
3535    ;
3536
3537 external_declaration:
3538           function_definition { $$ = MkExternalFunction($1); $$.loc = @$; $1.declMode = declMode; structDeclMode = declMode = defaultDeclMode; }
3539    | class
3540       { $$ = MkExternalClass($1);  $$.loc = @$; $1.declMode = (declMode != defaultAccess) ? declMode : privateAccess; structDeclMode = declMode = defaultDeclMode; }
3541
3542    | external_guess_declaration_specifiers class
3543       { $$ = MkExternalClass($2);  $$.loc = @$; $2.declMode = (declMode != defaultAccess) ? declMode : privateAccess; structDeclMode = declMode = defaultDeclMode; FreeList($1, FreeSpecifier); }
3544
3545         | external_guess_declaration
3546       { $$ = MkExternalDeclaration($1);  $$.loc = @$; $1.declMode = declMode; structDeclMode = declMode = defaultDeclMode; }
3547    | IMPORT string_literal { $$ = MkExternalImport($2, normalImport, (declMode != defaultAccess) ? declMode : privateAccess);  $$.loc = @$; }
3548    | IMPORT STATIC string_literal { $$ = MkExternalImport($3, staticImport, (declMode != defaultAccess) ? declMode : privateAccess);  $$.loc = @$; }
3549    | IMPORT identifier string_literal
3550    {
3551       bool isRemote = !strcmp($2.string, "remote");
3552       $$ = MkExternalImport($3, isRemote ? remoteImport : normalImport, (declMode != defaultAccess) ? declMode : privateAccess);
3553       $$.loc = @$;
3554       FreeIdentifier($2);
3555       if(!isRemote)
3556          yyerror();
3557    }
3558
3559    | ';' { $$ = null; }
3560
3561         | declaration_mode function_definition { $$ = MkExternalFunction($2); $$.loc = @$; $2.declMode = $1; structDeclMode = declMode = defaultDeclMode; }
3562    | declaration_mode class
3563       { $$ = MkExternalClass($2);  $$.loc = @$; $2.declMode = ($1 != defaultAccess) ? $1 : privateAccess; structDeclMode = declMode = defaultDeclMode; }
3564         | declaration_mode external_guess_declaration         { $$ = MkExternalDeclaration($2); $$.loc = @$; $2.declMode = $1; structDeclMode = declMode = defaultDeclMode; }
3565    | declaration_mode IMPORT string_literal { $$ = MkExternalImport($3, normalImport, ($1 != defaultAccess) ? $1 : privateAccess);  $$.loc = @$; structDeclMode = declMode = defaultDeclMode; }
3566    | declaration_mode IMPORT STATIC string_literal { $$ = MkExternalImport($4, staticImport, ($1 != defaultAccess) ? $1 : privateAccess);  $$.loc = @$; structDeclMode = declMode = defaultDeclMode; }
3567    | declaration_mode IMPORT identifier string_literal
3568    {
3569       bool isRemote = !strcmp($3.string, "remote");
3570       $$ = MkExternalImport($4, isRemote ? remoteImport : normalImport, ($1 != defaultAccess) ? $1 : privateAccess);
3571       $$.loc = @$;
3572       FreeIdentifier($3);
3573       structDeclMode = declMode = defaultDeclMode;
3574       if(!isRemote)
3575          yyerror();
3576    }
3577    | declaration_mode ':' { defaultDeclMode = $1; $$ = null; }
3578    | STATIC ':' { defaultDeclMode = staticAccess; $$ = null; }
3579    | NAMESPACE identifier { $$ = MkExternalNameSpace($2); $$.loc = @$; }
3580    | NAMESPACE strict_type { $$ = MkExternalNameSpace(MkIdentifier($2.name)); FreeSpecifier($2); $$.loc = @$; }
3581    | dbtable_definition { $$ = MkExternalDBTable($1); $$.loc = @$;  $1.declMode = (declMode != defaultAccess) ? declMode : privateAccess; structDeclMode = declMode = defaultDeclMode; }
3582    | declaration_mode  dbtable_definition { $$ = MkExternalDBTable($2); $$.loc = @$;  $2.declMode = ($1 != defaultAccess) ? declMode : privateAccess; structDeclMode = declMode = defaultDeclMode; }
3583    ;
3584
3585 external_declaration_error:
3586      class_error               { yyerror(); $$ = MkExternalClass($1);  $$.loc = $1.loc; $1.declMode = (declMode != defaultAccess) ? declMode : privateAccess; structDeclMode = declMode = defaultDeclMode; }
3587    | external_guess_declaration_specifiers class_error
3588    {
3589       yyerror();
3590       FreeList($1, FreeSpecifier);
3591       $$ = MkExternalClass($2);
3592       $$.loc = $2.loc;
3593       $2.declMode = (declMode != defaultAccess) ? declMode : privateAccess;
3594       structDeclMode = declMode = defaultDeclMode;
3595    }
3596    | function_definition_error { yyerror(); $$ = MkExternalFunction($1); $$.loc = $1.loc;  $1.declMode = declMode; structDeclMode = declMode = defaultDeclMode; }
3597
3598    | declaration_mode class_error               { yyerror(); $$ = MkExternalClass($2);  $$.loc = $2.loc; $2.declMode = ($1 != defaultAccess) ? $1 : privateAccess; structDeclMode = declMode = defaultDeclMode; }
3599    | declaration_mode function_definition_error { yyerror(); $$ = MkExternalFunction($2); $$.loc = $2.loc; $2.declMode = $1; structDeclMode = declMode = defaultDeclMode; }
3600
3601         | external_guess_declaration_error
3602       { yyerror(); $$ = MkExternalDeclaration($1);  $$.loc = @$; $1.declMode = declMode; structDeclMode = declMode = defaultDeclMode; }
3603    | declaration_mode external_guess_declaration_error         { yyerror(); $$ = MkExternalDeclaration($2); $$.loc = @$; $2.declMode = $1; structDeclMode = declMode = defaultDeclMode; }
3604    ;
3605
3606 translation_unit_error:
3607      external_declaration_error                    { $$ = MkList(); ListAdd($$, $1); ast = $$; }
3608    | translation_unit external_declaration_error   { $$ = $1; ListAdd($1, $2); }
3609    | translation_unit_error external_declaration_error   { $$ = $1; ListAdd($1, $2); }
3610    | translation_unit error
3611    | translation_unit_error error
3612         ;
3613
3614 translation_unit:
3615           external_declaration                    { $$ = MkList(); ListAdd($$, $1); ast = $$; }
3616         | translation_unit external_declaration   { $$ = $1; ListAdd($1, $2); }
3617    | translation_unit_error class
3618       { External _class = MkExternalClass($2); $$ = $1; ListAdd($1, _class); _class.loc = @2;  $2.declMode = (declMode != defaultAccess) ? declMode : privateAccess; structDeclMode = declMode = defaultDeclMode; }
3619    | translation_unit_error declaration_mode class
3620       { External _class = MkExternalClass($3); $$ = $1; ListAdd($1, _class); _class.loc = @3;  $3.declMode = ($2 != defaultAccess) ? $2 : privateAccess; structDeclMode = declMode = defaultDeclMode; }
3621         ;
3622
3623 thefile:
3624    translation_unit
3625    | translation_unit_error
3626    | { ast = MkList(); }
3627    ;
3628
3629 dbtable_definition:
3630      DBTABLE string_literal identifier   '{' dbfield_definition_list '}' { Symbol symbol = DeclClassAddNameSpace($3._class, $3.string); FreeIdentifier($3); $$ = MkDBTableDef($2, symbol, $5); }
3631    | DBTABLE string_literal strict_type  '{' dbfield_definition_list '}' { Symbol symbol = DeclClass($3.nsSpec, $3.name); FreeSpecifier($3); $$ = MkDBTableDef($2, symbol, $5); }
3632    | DBTABLE string_literal '{' dbfield_definition_list '}' { $$ = MkDBTableDef($2, null, $4); }
3633    ;
3634
3635 dbfield_entry:
3636    guess_declaration_specifiers identifier string_literal ';' { $$ = MkDBFieldEntry(MkTypeName($1, null), $2, $3); }
3637    ;
3638
3639 dbindex_item:
3640      identifier      { $$ = MkDBIndexItem($1, ascending); }
3641    | '>' identifier  { $$ = MkDBIndexItem($2, descending); }
3642    | '<' identifier  { $$ = MkDBIndexItem($2, ascending); }
3643    ;
3644
3645 dbindex_item_list:
3646      dbindex_item                         { $$ = MkList(); ListAdd($$, $1); }
3647    | dbindex_item_list ',' dbindex_item   { ListAdd($1, $3); }
3648    ;
3649
3650 dbindex_entry:
3651      DBINDEX dbindex_item_list ';'             { $$ = MkDBIndexEntry($2, null); }
3652    | DBINDEX dbindex_item_list identifier ';'  { $$ = MkDBIndexEntry($2, $3); }
3653    ;
3654
3655 dbfield_definition_list:
3656      dbfield_entry                           { $$ = MkList(); ListAdd($$, $1); }
3657    | dbindex_entry                           { $$ = MkList(); ListAdd($$, $1); }
3658    | dbfield_definition_list dbfield_entry   { ListAdd($1, $2); }
3659    | dbfield_definition_list dbindex_entry   { ListAdd($1, $2); }
3660    ;
3661
3662 database_open:
3663    DATABASE_OPEN '(' assignment_expression ',' assignment_expression ')'     { $$ = MkExpDBOpen($3, $5); }
3664    ;
3665
3666 dbfield:
3667    DBFIELD '(' string_literal ',' identifier ')'      { $$ = MkExpDBField($3, $5); }
3668    ;
3669
3670 dbindex:
3671    DBINDEX '(' string_literal ',' identifier ')'      { $$ = MkExpDBIndex($3, $5); }
3672    ;
3673
3674 dbtable:
3675    DBTABLE '(' string_literal ')'                     { $$ = MkExpDBTable($3); }
3676    ;
3677
3678 %%