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