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