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