compiler/libec/grammar: Fixed warning; Updated bootstrap
[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             simple_postfix_expression simple_postfix_expression_error
101             common_unary_expression common_unary_expression_error
102             simple_unary_expression simple_unary_expression_error
103             database_open dbfield dbindex dbtable
104
105 %type <list> argument_expression_list expression expression_anon_inst expression_anon_inst_error enumerator_list type_qualifier_list
106              struct_declarator_list struct_declaration_list
107              declaration_specifiers identifier_list identifier_list_error initializer_list init_declarator_list
108              parameter_list parameter_list_error parameter_type_list parameter_type_list_error declaration_list declaration_list_error statement_list statement_list_error
109              translation_unit members_initialization_list members_initialization_list_coloned members_initialization_list_error  data_member_initialization_list data_member_initialization_list_coloned
110              default_property_list data_member_initialization_list_error
111              expression_error init_declarator_list_error argument_expression_list_error default_property_list_error struct_declaration_list_error
112              translation_unit_error
113              guess_declaration_specifiers
114              external_guess_declaration_specifiers external_guess_declaration_specifiers_error
115              specifier_qualifier_list guess_specifier_qualifier_list
116              _inheritance_specifiers inheritance_specifiers property_specifiers
117              new_specifiers renew_specifiers asm_field_list
118              property_watch_list watch_property_list
119              dbindex_item_list dbfield_definition_list
120              template_arguments_list template_parameters_list attribs_list
121
122 %type <asmField> asm_field
123 %type <specifier> storage_class_specifier enum_specifier_compound enum_specifier_nocompound type_qualifier type_specifier class_specifier class_specifier_error
124                   struct_or_union_specifier_compound struct_or_union_specifier_nocompound ext_storage type strict_type guess_type enum_class strict_type_specifier struct_class
125                   struct_or_union_specifier_compound_error struct_class_error struct_decl
126                   enum_specifier_compound_error enum_class_error external_storage_class_specifier
127                   base_strict_type struct_head struct_entry
128 %type <enumerator> enumerator
129 %type <declarator> declarator direct_declarator direct_abstract_declarator abstract_declarator
130                    direct_abstract_declarator_noarray abstract_declarator_noarray
131                    struct_declarator direct_declarator_function direct_declarator_function_start declarator_function_error direct_declarator_function_error declarator_function direct_declarator_nofunction
132                    direct_declarator_function_type_ok declarator_nofunction_type_ok direct_declarator_nofunction_type_ok declarator_function_type_ok direct_declarator_function_error_type_ok
133                    direct_declarator_function_start_type_ok direct_declarator_type_ok declarator_type_ok declarator_function_error_type_ok
134 %type <pointer> pointer
135 %type <initializer> initializer initializer_error initializer_condition initializer_condition_error
136 %type <initDeclarator> init_declarator init_declarator_error
137 %type <typeName> type_name guess_type_name parameter_declaration parameter_declaration_error
138 %type <stmt> statement labeled_statement labeled_statement_error compound_statement compound_statement_error expression_statement
139              selection_statement selection_statement_error iteration_statement jump_statement jump_statement_error compound_inside compound_inside_error
140              iteration_statement_error statement_error asm_statement
141              stopwatching watch_definition firewatchers
142
143 %type <declaration> declaration declaration_error external_guess_declaration external_guess_declaration_error
144 %type <function>  function_definition  function_definition_error
145 %type <external>  external_declaration external_declaration_error
146
147 %type <instance> instantiation_named instantiation_named_error instantiation_unnamed instantiation_unnamed_error guess_instantiation_named guess_instantiation_named_error external_guess_instantiation_named
148                  instantiation_anon instantiation_anon_error
149 %type <memberInit> data_member_initialization data_member_initialization_error default_property default_property_error
150 %type <classFunction> class_function_definition class_function_definition_error class_function_definition_start
151                      class_function_definition_start_error virtual_class_function_definition_start virtual_class_function_definition_start_error
152                      constructor_function_definition_start destructor_function_definition_start
153 %type <classFunction> instance_class_function_definition instance_class_function_definition_error instance_class_function_definition_start instance_class_function_definition_start_error
154 %type <_class> class class_error class_head
155 %type <classDef> struct_declaration struct_declaration_error
156 %type <string> string_literal base_strict_type_name attribute_word
157 %type <extDecl> ext_decl
158 %type <attrib> attrib
159 %type <attribute> attribute
160 %type <prop> property property_start property_body class_property class_property_start class_property_body
161 %type <propertyWatch> property_watch self_watch_definition
162
163 %type <templateParameter> template_parameter template_type_parameter template_identifier_parameter template_expression_parameter
164 %type <templateArgument> template_argument template_type_argument template_identifier_argument template_expression_argument
165 %type <templateDatatype> template_datatype
166
167 %type <dbtableEntry> dbindex_entry dbfield_entry
168 %type <dbindexItem> dbindex_item
169 %type <dbtableDef> dbtable_definition
170 %type <context> compound_start class_entry
171
172 %token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF
173 %token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
174 %token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
175 %token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN
176 %token XOR_ASSIGN OR_ASSIGN TYPE_NAME
177
178 %token TYPEDEF EXTERN STATIC AUTO REGISTER
179 %token CHAR SHORT INT UINT INT64 LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID VALIST
180 %token STRUCT UNION ENUM ELLIPSIS
181
182 %token CASE DEFAULT IF SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
183
184 %nonassoc IFX
185 %nonassoc ELSE
186 %token CLASS THISCLASS CLASS_NAME
187 %token PROPERTY SETPROP GETPROP NEWOP RENEW DELETE EXT_DECL EXT_STORAGE IMPORT DEFINE VIRTUAL ATTRIB
188 %token PUBLIC PRIVATE
189 %token TYPED_OBJECT ANY_OBJECT _INCREF EXTENSION ASM TYPEOF
190 %token WATCH STOPWATCHING FIREWATCHERS WATCHABLE CLASS_DESIGNER CLASS_NO_EXPANSION CLASS_FIXED ISPROPSET
191 %token CLASS_DEFAULT_PROPERTY PROPERTY_CATEGORY CLASS_DATA CLASS_PROPERTY SUBCLASS NAMESPACE
192 %token NEW0OP RENEW0 VAARG
193 %token DBTABLE DBFIELD DBINDEX DATABASE_OPEN
194 %token ALIGNOF ATTRIB_DEP __ATTRIB
195 %token BOOL _BOOL _COMPLEX _IMAGINARY RESTRICT THREAD
196
197 %destructor { FreeIdentifier($$); } identifier
198 %destructor { FreePointer($$); } pointer
199 %destructor { FreeExpression($$); } primary_expression primary_expression_error postfix_expression unary_expression cast_expression
200                                     multiplicative_expression additive_expression shift_expression
201                                     relational_expression equality_expression and_expression
202                                     exclusive_or_expression inclusive_or_expression logical_and_expression
203                                     logical_or_expression conditional_expression assignment_expression
204                                     constant_expression constant_expression_error
205                                     postfix_expression_error unary_expression_error cast_expression_error
206                                     multiplicative_expression_error additive_expression_error shift_expression_error
207                                     relational_expression_error equality_expression_error and_expression_error
208                                     exclusive_or_expression_error inclusive_or_expression_error logical_and_expression_error
209                                     logical_or_expression_error conditional_expression_error assignment_expression_error i18n_string
210 %destructor { FreeSpecifier($$); }  storage_class_specifier enum_specifier_compound enum_specifier_nocompound type_qualifier type_specifier class_specifier class_specifier_error
211                                     struct_or_union_specifier_compound struct_or_union_specifier_nocompound ext_storage type strict_type guess_type enum_class strict_type_specifier struct_class
212                                     struct_or_union_specifier_compound_error struct_class_error struct_decl
213                                     enum_specifier_compound_error enum_class_error external_storage_class_specifier
214                                     base_strict_type struct_head struct_entry
215 %destructor { FreeEnumerator($$); } enumerator
216 %destructor { FreeDeclarator($$); } declarator direct_declarator direct_abstract_declarator abstract_declarator
217                                     direct_abstract_declarator_noarray abstract_declarator_noarray
218                                     struct_declarator direct_declarator_function direct_declarator_function_start declarator_function_error direct_declarator_function_error declarator_function direct_declarator_nofunction
219                                     direct_declarator_function_type_ok declarator_nofunction_type_ok direct_declarator_nofunction_type_ok declarator_function_type_ok direct_declarator_function_error_type_ok
220                                     direct_declarator_function_start_type_ok direct_declarator_type_ok declarator_type_ok declarator_function_error_type_ok
221
222 %destructor { FreeInitializer($$); } initializer initializer_error initializer_condition initializer_condition_error
223 %destructor { FreeInitDeclarator($$); } init_declarator init_declarator_error
224 %destructor { FreeTypeName($$); } type_name guess_type_name parameter_declaration parameter_declaration_error
225 %destructor { FreeStatement($$); }  statement labeled_statement labeled_statement_error compound_statement compound_statement_error expression_statement
226                                     selection_statement selection_statement_error iteration_statement jump_statement jump_statement_error compound_inside compound_inside_error
227                                     iteration_statement_error statement_error
228
229 %destructor { FreeDeclaration($$); } declaration
230 %destructor { FreeFunction($$); } function_definition  function_definition_error
231 %destructor { FreeExternal($$); } external_declaration external_declaration_error
232
233 %destructor { FreeInstance($$); } instantiation_named instantiation_named_error instantiation_unnamed instantiation_unnamed_error
234
235 %destructor { FreeMemberInit($$); } data_member_initialization data_member_initialization_error default_property default_property_error
236
237 %destructor { FreeClassFunction($$); } class_function_definition class_function_definition_error class_function_definition_start
238                                        class_function_definition_start_error virtual_class_function_definition_start virtual_class_function_definition_start_error
239                                        constructor_function_definition_start destructor_function_definition_start
240                                        instance_class_function_definition instance_class_function_definition_error instance_class_function_definition_start instance_class_function_definition_start_error
241 %destructor { Context ctx = curContext; PopContext(ctx); FreeContext(ctx); delete ctx; } class_entry
242 %destructor { Context ctx = curContext; PopContext(ctx); FreeContext(ctx); delete ctx; } class_decl
243 %destructor { FreeClass($$); } class class_error class_head
244 %destructor { FreeClassDef($$); } struct_declaration struct_declaration_error
245 %destructor { delete $$; } string_literal attribute_word base_strict_type_name
246 %destructor { FreeProperty($$); } property
247
248 %destructor { FreeList($$, FreeExpression); }  argument_expression_list expression expression_error argument_expression_list_error
249 %destructor { FreeList($$, FreeEnumerator); }  enumerator_list
250 %destructor { FreeList($$, FreeSpecifier); }   type_qualifier_list specifier_qualifier_list declaration_specifiers inheritance_specifiers _inheritance_specifiers external_guess_declaration_specifiers external_guess_declaration_specifiers_error
251                                                guess_declaration_specifiers guess_specifier_qualifier_list
252 %destructor { FreeList($$, FreeDeclarator); }  struct_declarator_list
253 %destructor { FreeList($$, FreeDeclaration); } declaration_list declaration_list_error
254 %destructor { FreeList($$, FreeInitializer); } initializer_list
255 %destructor { FreeList($$, FreeInitDeclarator); } init_declarator_list init_declarator_list_error
256 %destructor { FreeList($$, FreeTypeName); } parameter_list parameter_list_error parameter_type_list parameter_type_list_error identifier_list identifier_list_error
257 %destructor { FreeList($$, FreeStatement); } statement_list statement_list_error
258 %destructor { if($$ != ast) FreeList($$, FreeExternal); } translation_unit translation_unit_error
259 %destructor { FreeList($$, FreeClassDef); } struct_declaration_list struct_declaration_list_error
260 %destructor { FreeList($$, FreeMemberInit); } default_property_list default_property_list_error data_member_initialization_list data_member_initialization_list_coloned data_member_initialization_list_error
261 %destructor { FreeList($$, FreeMembersInit); } members_initialization_list members_initialization_list_coloned members_initialization_list_error
262 %destructor { PopContext($$); FreeContext($$); delete $$; } compound_start
263 %destructor { FreeTemplateParameter($$); } template_parameter template_type_parameter template_identifier_parameter template_expression_parameter
264 %destructor { FreeTemplateArgument($$); } template_argument template_type_argument template_identifier_argument template_expression_argument
265 %destructor { FreeTemplateDataType($$); } template_datatype
266 %destructor { FreeList($$, FreeTemplateParameter); } template_parameters_list
267 %destructor { FreeList($$, FreeTemplateArgument); } template_arguments_list
268 %destructor { } declaration_mode
269 %destructor { FreeAttrib($$); } attrib
270 %destructor { FreeExtDecl($$); } ext_decl
271 %destructor { FreeAttribute($$); } attribute
272 %destructor { FreeList($$, FreeAttribute); }  attribs_list
273
274 %start thefile
275
276 %%
277
278 guess_type:
279    identifier '*'
280    {
281       $$ = null;
282       // if($1._class && !$1._class.name)
283       if($1._class)
284       {
285          char name[1024];
286          strcpy(name,  $1._class.name ? $1._class.name : "");
287          strcat(name, "::");
288          strcat(name, $1.string);
289          _DeclClass(0, name);
290       }
291       else
292          _DeclClass(0, $1.string);
293
294       FreeIdentifier($1);
295
296       fileInput.Seek(@1.start.pos, start);
297       resetScannerPos(&@1.start);
298       yyclearin;
299
300       YYPOPSTACK(1);
301       yystate = *yyssp;
302       YY_STACK_PRINT (yyss, yyssp);
303       YYPOPSTACK(1);
304       yystate = *yyssp;
305       YY_STACK_PRINT (yyss, yyssp);
306       goto yysetstate;
307    }
308    | identifier '<'
309    {
310       $$ = null;
311    #ifdef PRECOMPILER
312       // if($1._class && !$1._class.name)
313       if($1._class)
314       {
315          char name[1024];
316          strcpy(name,  $1._class.name ? $1._class.name : "");
317          strcat(name, "::");
318          strcat(name, $1.string);
319          _DeclClass(0, name);
320       }
321       else
322          _DeclClass(0, $1.string);
323
324       FreeIdentifier($1);
325
326       fileInput.Seek(@1.start.pos, start);
327       resetScannerPos(&@1.start);
328       yyclearin;
329
330       YYPOPSTACK(1);
331       yystate = *yyssp;
332       YY_STACK_PRINT (yyss, yyssp);
333       YYPOPSTACK(1);
334       yystate = *yyssp;
335       YY_STACK_PRINT (yyss, yyssp);
336       goto yysetstate;
337    #endif
338    }
339 /*   | identifier '*' '<' template_arguments_list '>'
340    {
341       //if($1._class && !$1._class.name)
342       if($1._class)
343       {
344          char name[1024];
345          strcpy(name,  $1._class.name ? $1._class.name : "");
346          strcat(name, "::");
347          strcat(name, $1.string);
348          _DeclClass(0, name);
349       }
350       else
351          _DeclClass(0, $1.string);
352       fileInput.Seek(@1.start.pos, start);
353       resetScannerPos(&@1.start);
354       yyclearin;
355
356       YYPOPSTACK(1);
357       yystate = *yyssp;
358       YY_STACK_PRINT (yyss, yyssp);
359       YYPOPSTACK(1);
360       yystate = *yyssp;
361       YY_STACK_PRINT (yyss, yyssp);
362       goto yysetstate;
363    }*/
364    ;
365
366 type:
367    strict_type       { $$ = $1; }
368    | identifier identifier
369    {
370    #ifdef PRECOMPILER
371       if(!$1.string[0])
372       {
373          $$ = MkSpecifierName($1.string);
374          FreeIdentifier($1);
375          FreeIdentifier($2);
376          return;
377       }
378
379       // if($1._class && !$1._class.name)
380       if($1._class)
381       {
382          char name[1024];
383          strcpy(name,  $1._class.name ? $1._class.name : "");
384          strcat(name, "::");
385          strcat(name, $1.string);
386          _DeclClass(0, name);
387       }
388       else
389          _DeclClass(0, $1.string);
390
391       FreeIdentifier($1);
392       FreeIdentifier($2);
393
394       fileInput.Seek(@1.start.pos, start);
395       resetScannerPos(&@1.start);
396       yyclearin;
397
398       YYPOPSTACK(1);
399       yystate = *yyssp;
400       YY_STACK_PRINT (yyss, yyssp);
401       YYPOPSTACK(1);
402       yystate = *yyssp;
403       YY_STACK_PRINT (yyss, yyssp);
404       goto yysetstate;
405    #else
406       Location tmpLoc = yylloc; $$ = $2; yylloc = @1;
407       Compiler_Error($"Not a type: %s\n", $1.string);
408       yylloc = tmpLoc; $2.badID = $1;
409    #endif
410    }
411    /*
412    | identifier '<'
413    {
414    #ifdef PRECOMPILER
415       //if($1._class && !$1._class.name)
416       if($1._class)
417       {
418          char name[1024];
419          strcpy(name,  $1._class.name ? $1._class.name : "");
420          strcat(name, "::");
421          strcat(name, $1.string);
422          _DeclClass(0, name);
423       }
424       else
425          _DeclClass(0, $1.string);
426       fileInput.Seek(@1.start.pos, start);
427       resetScannerPos(&@1.start);
428       yyclearin;
429
430       YYPOPSTACK(1);
431       yystate = *yyssp;
432       YY_STACK_PRINT (yyss, yyssp);
433       YYPOPSTACK(1);
434       yystate = *yyssp;
435       YY_STACK_PRINT (yyss, yyssp);
436       goto yysetstate;
437    #endif
438    }
439 /*   | strict_type '<' template_arguments_list '>'      { $$ = $1; }
440    | identifier identifier '<' template_arguments_list '>'
441    {
442    #ifdef PRECOMPILER
443       // if($1._class && !$1._class.name)
444       if($1._class)
445       {
446          char name[1024];
447          strcpy(name,  $1._class.name ? $1._class.name : "");
448          strcat(name, "::");
449          strcat(name, $1.string);
450          _DeclClass(0, name);
451       }
452       else
453          _DeclClass(0, $1.string);
454       FreeIdentifier($1);
455       FreeIdentifier($2);
456
457       fileInput.Seek(@1.start.pos, start);
458       resetScannerPos(&@1.start);
459       yyclearin;
460
461       YYPOPSTACK(1);
462       yystate = *yyssp;
463       YY_STACK_PRINT (yyss, yyssp);
464       YYPOPSTACK(1);
465       yystate = *yyssp;
466       YY_STACK_PRINT (yyss, yyssp);
467       goto yysetstate;
468    #else
469       Location tmpLoc = yylloc; $$ = $2; yylloc = @1;
470       Compiler_Error($"Not a type: %s\n", $1.string);
471       yylloc = tmpLoc; $2.badID = $1;
472    #endif
473    }*/
474    ;
475
476 base_strict_type:
477      TYPE_NAME    { $$ = MkSpecifierName(yytext); }
478    ;
479
480 base_strict_type_name:
481      TYPE_NAME    { $$ = CopyString(yytext); }
482    ;
483 strict_type:
484      base_strict_type
485     | base_strict_type '<' template_arguments_list '>' { $$ = $1; SetClassTemplateArgs($$, $3); $$.loc = @$; }
486     | base_strict_type '<' template_arguments_list RIGHT_OP
487     {
488       $$ = $1;
489       SetClassTemplateArgs($$, $3);
490       $$.loc = @$;
491
492       @4.end.pos--;
493       fileInput.Seek(@4.end.pos, start);
494       resetScannerPos(&@4.end);
495       yyclearin;
496     }
497
498 /*    | identifier '<' template_arguments_list '>' */
499       /*| identifier '<' error
500       {
501          // if($1._class && !$1._class.name)
502          if($1._class)
503          {
504             char name[1024];
505             strcpy(name,  $1._class.name ? $1._class.name : "");
506             strcat(name, "::");
507             strcat(name, $1.string);
508             _DeclClass(0, name);
509          }
510          else
511             _DeclClass(0, $1.string);
512
513          yyerrok;
514
515          fileInput.Seek(@1.start.pos, start);
516          resetScannerPos(&@1.start);
517          yyclearin;
518
519          YYPOPSTACK(1);
520          yystate = *yyssp;
521          YY_STACK_PRINT (yyss, yyssp);
522          YYPOPSTACK(1);
523          yystate = *yyssp;
524          YY_STACK_PRINT (yyss, yyssp);
525          YYPOPSTACK(1);
526          yystate = *yyssp;
527          YY_STACK_PRINT (yyss, yyssp);
528          goto yysetstate;
529
530          /* $$ = MkSpecifierNameArgs($1.string, $3); $$.loc = @$; FreeIdentifier($1); */
531       /*}*/
532    ;
533
534 class_function_definition_start:
535    guess_declaration_specifiers declarator_function_type_ok
536       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; $$.id = ++globalContext.nextID; }
537    | declarator_function
538       { $$ = MkClassFunction(null, null, $1, null); $$.loc = @$; $$.id = ++globalContext.nextID; }
539    ;
540
541 constructor_function_definition_start:
542    guess_declaration_specifiers '(' ')'
543       { $$ = MkClassFunction(null, null, null, null); $$.isConstructor = true; $$.loc = @$; $$.id = ++globalContext.nextID; FreeList($1, FreeSpecifier); }
544    ;
545
546 destructor_function_definition_start:
547    '~' guess_declaration_specifiers '(' ')'
548       { $$ = MkClassFunction(null, null, null, null); $$.isDestructor = true; $$.loc = @$; $$.id = ++globalContext.nextID; FreeList($2, FreeSpecifier) }
549    ;
550
551 virtual_class_function_definition_start:
552      VIRTUAL guess_declaration_specifiers declarator_function_type_ok
553       { $$ = MkClassFunction($2, null, $3, null); $$.isVirtual = true; $$.loc = @$; $$.id = ++globalContext.nextID; }
554    | VIRTUAL declarator_function
555       { $$ = MkClassFunction(null, null, $2, null); $$.isVirtual = true; $$.loc = @$; $$.id = ++globalContext.nextID; }
556       ;
557
558 class_function_definition_start_error:
559      guess_declaration_specifiers declarator_function_error_type_ok
560       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; $$.id = ++globalContext.nextID; }
561    | declarator_function_error
562       { $$ = MkClassFunction(null, null, $1, null); $$.loc = @$; $$.id = ++globalContext.nextID; }
563    ;
564
565 virtual_class_function_definition_start_error:
566      VIRTUAL guess_declaration_specifiers declarator_function_error_type_ok
567       { $$ = MkClassFunction($2, null, $3, null); $$.isVirtual = true; $$.loc = @$; $$.id = ++globalContext.nextID; }
568    | VIRTUAL declarator_function_error
569       { $$ = MkClassFunction(null, null, $2, null); $$.isVirtual = true; $$.loc = @$; $$.id = ++globalContext.nextID; }
570       ;
571
572 class_function_definition:
573         class_function_definition_start compound_statement
574       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
575         | virtual_class_function_definition_start compound_statement
576       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
577    | virtual_class_function_definition_start ';'
578       { ProcessClassFunctionBody($1, null); $$.loc = @$; }
579         | constructor_function_definition_start compound_statement
580       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
581         | destructor_function_definition_start compound_statement
582       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
583
584    // TESTING THIS
585    | class_function_definition_start ';'
586       { ProcessClassFunctionBody($1, null); $$.loc = @$; }
587
588    // Added this to fix attrib not working after function pointer declarations
589    | class_function_definition_start attrib ';'
590       {
591          if($1.declarator)
592          {
593             $1.declarator = MkStructDeclarator($1.declarator, null);
594             $1.declarator.structDecl.attrib = $2;
595          }
596          ProcessClassFunctionBody($1, null);
597          $$.loc = @$;
598       }
599         ;
600
601 class_function_definition_error:
602            class_function_definition_start compound_statement_error
603       { ProcessClassFunctionBody($1, $2); $$.loc = @$; $$.loc.end = $2.loc.end; }
604    |    class_function_definition_start_error
605       { ProcessClassFunctionBody($1, null); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;}
606         |  virtual_class_function_definition_start compound_statement_error
607       { ProcessClassFunctionBody($1, $2); $$.loc = @$; $$.loc.end = $2.loc.end; }
608    |    virtual_class_function_definition_start_error
609       { ProcessClassFunctionBody($1, null); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;}
610    |    virtual_class_function_definition_start_error ';'
611       { ProcessClassFunctionBody($1, null); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;}
612         ;
613
614 // In Instances, return type is required to distinguish from calling the function
615 instance_class_function_definition_start:
616    declaration_specifiers declarator_function_type_ok
617       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; $$.id = ++globalContext.nextID; }
618    |  declaration_specifiers declarator_nofunction_type_ok
619       { $$ = MkClassFunction($1, null, MkDeclaratorFunction($2, null), null); $$.loc = @$; $$.id = ++globalContext.nextID; }
620       ;
621
622 instance_class_function_definition_start_error:
623    declaration_specifiers declarator_function_error_type_ok
624       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; $$.id = ++globalContext.nextID; }
625       ;
626
627 instance_class_function_definition:
628         instance_class_function_definition_start compound_statement
629       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
630         ;
631
632 instance_class_function_definition_error:
633         instance_class_function_definition_start compound_statement_error
634       { ProcessClassFunctionBody($1, $2); $$.loc = @$; $$.loc.end = $2.loc.end; $$.loc.end.charPos++; $$.loc.end.pos++;}
635    |    instance_class_function_definition_start_error
636       { ProcessClassFunctionBody($1, null); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;}
637    |    instance_class_function_definition_start
638       { ProcessClassFunctionBody($1, null); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++;}
639         ;
640
641 data_member_initialization:
642      postfix_expression '=' initializer_condition { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = @2.end;}
643    | initializer_condition                { $$ = MkMemberInit(null, $1); $$.loc = @$; $$.realLoc = @$;}
644    ;
645
646 data_member_initialization_error:
647      postfix_expression '=' initializer_condition_error { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = @2.end;}
648    | postfix_expression '=' error
649       {
650          $$ = MkMemberInitExp($1, MkInitializerAssignment(MkExpDummy()));
651          $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = $$.initializer.loc.end = @2.end;
652
653          fileInput.Seek(@2.end.pos, start);
654          yyclearin;
655          resetScannerPos(&@2.end);
656          @$.start = @1.start;
657          @$.end = @2.end;
658       }
659    | initializer_condition_error { $$ = MkMemberInit(null, $1); $$.loc = @$; $$.realLoc = @$;}
660    ;
661
662 data_member_initialization_list:
663    data_member_initialization { $$ = MkList(); ListAdd($$, $1); }
664    | data_member_initialization_list ',' data_member_initialization
665       { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
666    | data_member_initialization_list_error ',' data_member_initialization
667       { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
668    ;
669
670 data_member_initialization_list_error:
671    data_member_initialization_error { $$ = MkList(); ListAdd($$, $1); }
672    | data_member_initialization_list ',' data_member_initialization_error
673       { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
674    | data_member_initialization_list_error ',' data_member_initialization_error
675       { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
676
677    | data_member_initialization_list ',' error
678       { ((MemberInit)$1->last).loc.end = @2.end;
679          {
680             Initializer dummy = MkInitializerAssignment(MkExpDummy());
681             MemberInit memberInit = MkMemberInit(null, dummy);
682             memberInit.realLoc.start = memberInit.loc.start = dummy.loc.start = @2.end;
683             memberInit.realLoc.end = memberInit.loc.end = dummy.loc.end = @2.end;
684             ListAdd($1, memberInit);
685           }
686           $$ = $1;
687        }
688    |
689    data_member_initialization_list_error ',' error
690       { ((MemberInit)$1->last).loc.end = @2.end;
691          {
692             Initializer dummy = MkInitializerAssignment(MkExpDummy());
693             MemberInit memberInit = MkMemberInit(null, dummy);
694             memberInit.realLoc.start = memberInit.loc.start = dummy.loc.start = @2.end;
695             memberInit.realLoc.end = memberInit.loc.end = dummy.loc.end = @2.end;
696             ListAdd($1, memberInit);
697           }
698           $$ = $1;
699        }
700        |   ','
701       {
702          Initializer dummy = MkInitializerAssignment(MkExpDummy());
703          MemberInit memberInit = MkMemberInit(null, dummy);
704          memberInit.realLoc.start = memberInit.loc.start = dummy.loc.start = @1.start;
705          memberInit.realLoc.end = memberInit.loc.end = dummy.loc.end = @1.start;
706
707          $$ = MkList();
708          ListAdd($$, memberInit);
709
710          dummy = MkInitializerAssignment(MkExpDummy());
711          memberInit = MkMemberInit(null, dummy);
712          memberInit.realLoc.start = memberInit.loc.start = dummy.loc.start = @1.end;
713          memberInit.realLoc.end = memberInit.loc.end = dummy.loc.end = @1.end;
714          ListAdd($$, memberInit);
715       }
716    ;
717
718 data_member_initialization_list_coloned:
719    data_member_initialization_list ';'
720       { if($1->last) ((MemberInit)$1->last).loc.end = @2.end; $$ = $1; }
721    | data_member_initialization_list_error ';'
722       { if($1->last) ((MemberInit)$1->last).loc.end = @2.end; $$ = $1; }
723    ;
724
725 members_initialization_list_coloned:
726      data_member_initialization_list_coloned                                        { MembersInit members = MkMembersInitList($1); $$ = MkList(); ListAdd($$, members); members.loc = @1; }
727    | instance_class_function_definition                                             { $$ = MkList(); ListAdd($$, MkMembersInitMethod($1)); ((MembersInit)$$->last).loc = @1; }
728    | members_initialization_list_error data_member_initialization_list_coloned      { MembersInit members = MkMembersInitList($2); ListAdd($$, members);  members.loc = @2; $$ = $1; }
729    | members_initialization_list_error    instance_class_function_definition        { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
730    | members_initialization_list_coloned  data_member_initialization_list_coloned   { MembersInit members = MkMembersInitList($2); ListAdd($$, members); members.loc = @2; $$ = $1; }
731    | members_initialization_list_coloned  instance_class_function_definition        { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
732    | members_initialization_list_error ';'
733    | members_initialization_list_coloned ';'
734    {
735       MembersInit members = (MembersInit)$$->last;
736       if(members.type == dataMembersInit)
737          members.loc.end = @$.end;
738       else
739       {
740          MembersInit members = MkMembersInitList(MkList());
741          ListAdd($$, members);
742          members.loc = @2;
743       }
744       $$ = $1;
745    }
746    | ';'                                                                            { MembersInit members = MkMembersInitList(MkList()); $$ = MkList(); ListAdd($$, members); members.loc = @1;  }
747    ;
748
749 members_initialization_list:
750      members_initialization_list_coloned
751    | data_member_initialization_list                                       { $$ = MkList(); ListAdd($$, MkMembersInitList($1)); ((MembersInit)$$->last).loc = @1; }
752    | members_initialization_list_coloned data_member_initialization_list   { ListAdd($1, MkMembersInitList($2));   ((MembersInit)$$->last).loc = @2; }
753    | members_initialization_list_error data_member_initialization_list     { ListAdd($1, MkMembersInitList($2));   ((MembersInit)$$->last).loc = @2; }
754    ;
755
756 members_initialization_list_error:
757      instance_class_function_definition_error                                 { $$ = MkList(); ListAdd($$, MkMembersInitMethod($1)); ((MembersInit)$$->last).loc = @1; }
758      | members_initialization_list instance_class_function_definition_error  { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
759      | members_initialization_list_error instance_class_function_definition_error  { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
760      | members_initialization_list_coloned instance_class_function_definition_error  { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
761      | members_initialization_list_coloned data_member_initialization_list_error  { ListAdd($$, MkMembersInitList($2)); ((MembersInit)$$->last).loc = @2; $$ = $1; }
762      | data_member_initialization_list_error                                  { $$ = MkList(); ListAdd($$, MkMembersInitList($1)); ((MembersInit)$$->last).loc = @1; }
763      | data_member_initialization_list error                                  { $$ = MkList(); ListAdd($$, MkMembersInitList($1)); ((MembersInit)$$->last).loc = @2; }
764    ;
765
766 instantiation_named:
767      instantiation_named_error '}'
768       { $$.loc = @$; $$.insideLoc.end = @2.start; $$ = $1; }
769     | instantiation_named_error error '}'
770       { $$.loc = @$; $$.insideLoc.end = @2.start; $$ = $1; }
771    ;
772
773 instantiation_named_error:
774     declaration_specifiers identifier '{' members_initialization_list_error
775       { $$ = 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++; }
776 |   declaration_specifiers identifier '{' members_initialization_list error
777       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
778 |   declaration_specifiers identifier '{' members_initialization_list
779       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
780 |   declaration_specifiers identifier '{'
781       { $$ = 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++; }
782 |   declaration_specifiers identifier '{' error
783       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), null);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
784    ;
785
786 /*
787 instantiation_named:
788      declaration_specifiers identifier '{' members_initialization_list '}'
789       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
790    | declaration_specifiers identifier '{' members_initialization_list_error '}'
791       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
792    | declaration_specifiers identifier '{' '}'
793       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), MkList()); $$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.start;}
794    ;
795
796 instantiation_named_error:
797     declaration_specifiers identifier '{' members_initialization_list_error
798       { $$ = 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++; }
799 |   declaration_specifiers identifier '{' members_initialization_list error
800       { $$ = 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++; }
801 |   declaration_specifiers identifier '{' members_initialization_list
802       { $$ = 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++; }
803 |   declaration_specifiers identifier '{'
804       { $$ = 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++; }
805 |   declaration_specifiers identifier '{' error
806       { $$ = 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++; }
807    ;
808 */
809
810
811 guess_instantiation_named:
812      guess_instantiation_named_error '}'
813       { $$.loc = @$; $$.insideLoc.end = @2.start; }
814     | guess_instantiation_named_error error '}'
815       { $$.loc = @$; $$.insideLoc.end = @2.start; }
816    ;
817
818 guess_instantiation_named_error:
819     guess_declaration_specifiers identifier '{' members_initialization_list_error
820       { $$ = 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++; }
821 |   guess_declaration_specifiers identifier '{' members_initialization_list error
822       { $$ = 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++; }
823 |   guess_declaration_specifiers identifier '{' members_initialization_list
824       { $$ = 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++; }
825 |   guess_declaration_specifiers identifier '{'
826       { $$ = 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++; }
827 |   guess_declaration_specifiers identifier '{' error
828       { $$ = 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++; }
829    ;
830
831 /*
832 guess_instantiation_named:
833      guess_declaration_specifiers identifier '{' members_initialization_list '}'
834       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4);$$.exp.loc = @2;  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
835    | guess_declaration_specifiers identifier '{' members_initialization_list_error '}'
836       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
837    | guess_declaration_specifiers identifier '{' '}'
838       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), MkList());  $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.start;}
839    ;
840
841 guess_instantiation_named_error:
842     guess_declaration_specifiers identifier '{' members_initialization_list_error
843       { $$ = 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++; }
844 |   guess_declaration_specifiers identifier '{' members_initialization_list error
845       { $$ = 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++; }
846 |   guess_declaration_specifiers identifier '{' members_initialization_list
847       { $$ = 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++; }
848 |   guess_declaration_specifiers identifier '{'
849       { $$ = 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++; }
850 |   guess_declaration_specifiers identifier '{' error
851       { $$ = 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++; }
852    ;
853 */
854
855 external_guess_instantiation_named:
856      external_guess_declaration_specifiers identifier '{' members_initialization_list '}'
857       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
858    | external_guess_declaration_specifiers identifier '{' members_initialization_list_error '}'
859       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
860    | external_guess_declaration_specifiers identifier '{' '}'
861       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), MkList());  $$.exp.loc = @2; $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.start;}
862    ;
863
864 instantiation_unnamed:
865      instantiation_unnamed_error '}'
866       { $$.loc = @$; $$.insideLoc.end = @2.start; $$ = $1; }
867     | instantiation_unnamed_error error '}'
868       { $$.loc = @$; $$.insideLoc.end = @2.start; $$ = $1; }
869    ;
870
871 instantiation_unnamed_error:
872      strict_type '{' members_initialization_list
873       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
874 |    identifier '{' members_initialization_list
875       { Location tmpLoc = yylloc; yylloc = @1;
876       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end; FreeIdentifier($1); }
877
878 |    strict_type '{' members_initialization_list_error
879       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
880 |    strict_type '{'
881       { $$ = MkInstantiation($1, null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
882 |    strict_type '{' members_initialization_list error
883       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
884 |    strict_type '{' error
885       { $$ = MkInstantiation($1, null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end; $$.loc.end.charPos++; $$.loc.end.pos++;  }
886
887    // Undeclared class
888
889 |    identifier '{' members_initialization_list_error
890       { Location tmpLoc = yylloc; yylloc = @1;
891       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; FreeIdentifier($1); }
892 |    identifier '{'
893       { Location tmpLoc = yylloc; yylloc = @1;
894       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; FreeIdentifier($1); }
895 |    identifier '{' members_initialization_list error
896       { Location tmpLoc = yylloc; yylloc = @1;
897       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); }
898 |    identifier '{' error
899       { Location tmpLoc = yylloc; yylloc = @1;
900       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); }
901    ;
902
903 /*
904 instantiation_unnamed:
905      strict_type '{' members_initialization_list '}'
906       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; }
907    | strict_type '{' members_initialization_list error '}'
908       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @5.start; }
909    | strict_type '{' members_initialization_list_error '}'
910       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; }
911    | strict_type '{' '}'
912       { $$ = MkInstantiation($1, null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.start;}
913    | strict_type '{' error '}'
914       { $$ = MkInstantiation($1, null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start;}
915
916    // Undeclared class
917    | identifier '{' members_initialization_list '}'
918       { Location tmpLoc = yylloc; yylloc = @1;
919       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; FreeIdentifier($1); }
920    | identifier '{' members_initialization_list_error '}'
921       { Location tmpLoc = yylloc; yylloc = @1;
922       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; FreeIdentifier($1); }
923    | identifier '{' members_initialization_list error '}'
924       { yyloc = @1;
925       $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @5.start; FreeIdentifier($1); }
926    | identifier '{' '}'
927       { Location tmpLoc = yylloc; yylloc = @1;
928       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.start; FreeIdentifier($1);}
929    | identifier '{' error '}'
930       { Location tmpLoc = yylloc; yylloc = @1;
931       yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; FreeIdentifier($1); }
932    ;
933
934
935 instantiation_unnamed_error:
936      strict_type '{' members_initialization_list_error
937       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
938 |    strict_type '{'
939       { $$ = MkInstantiation($1, null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
940 |    strict_type '{' members_initialization_list error
941       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
942 |    strict_type '{' error
943       { $$ = MkInstantiation($1, null, null);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @2.end; $$.loc.end.charPos++; $$.loc.end.pos++;  }
944
945    // Undeclared class
946
947 |    identifier '{' members_initialization_list_error
948       { Location tmpLoc = yylloc; yylloc = @1;
949       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); }
950 |    identifier '{'
951       { Location tmpLoc = yylloc; yylloc = @1;
952       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); }
953 |    identifier '{' members_initialization_list error
954       { Location tmpLoc = yylloc; yylloc = @1;
955       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); }
956 |    identifier '{' error
957       { Location tmpLoc = yylloc; yylloc = @1;
958       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); }
959    ;
960 */
961
962 instantiation_anon:
963      instantiation_anon_error '}'
964       { $$.loc = @$; $$.insideLoc.end = @2.start; }
965     | instantiation_anon_error error '}'
966       { $$.loc = @$; $$.insideLoc.end = @2.start; }
967    ;
968
969 instantiation_anon_error:
970      '{' members_initialization_list_error
971       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
972 |    '{' members_initialization_list error
973       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
974 |    '{' error
975       { $$ = MkInstantiation(null, null, null);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @1.end; $$.loc.end.charPos++; $$.loc.end.pos++;  }
976 |    '{'
977       { $$ = MkInstantiation(null, null, null);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @1.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
978 |    '{' members_initialization_list
979       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.end; $$.loc.end.charPos++; $$.loc.end.pos++; }
980    ;
981
982 /*
983 instantiation_anon:
984      '{' members_initialization_list '}'
985       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @3.start; }
986    | '{' members_initialization_list error '}'
987       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @4.start; }
988    | '{' members_initialization_list_error '}'
989       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @3.start; }
990    | '{' '}'
991       { $$ = MkInstantiation(null, null, MkList());  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.start;}
992    | '{' error '}'
993       { $$ = MkInstantiation(null, null, MkList());  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @3.start;}
994    ;
995
996 instantiation_anon_error:
997      '{' members_initialization_list_error
998       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
999 |    '{'
1000       { $$ = MkInstantiation(null, null, null);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @1.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
1001 |    '{' members_initialization_list error
1002       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.end;  $$.loc.end.charPos++; $$.loc.end.pos++; }
1003 |    '{' error
1004       { $$ = MkInstantiation(null, null, null);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @1.end; $$.loc.end.charPos++; $$.loc.end.pos++;  }
1005    ;
1006 */
1007
1008 default_property:
1009      postfix_expression '=' initializer_condition { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; }
1010    ;
1011
1012 default_property_error:
1013      postfix_expression '=' initializer_condition_error { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = @2.end; }
1014    | postfix_expression '=' error { $$ = MkMemberInitExp($1, MkInitializerAssignment(MkExpDummy())); $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = @2.end; $$.initializer.loc.end = @2.end; }
1015    | postfix_expression error { $$ = MkMemberInitExp($1, null); $$.loc = @$; $$.realLoc = @$; }
1016    ;
1017
1018 default_property_list:
1019      default_property        { $$ = MkList(); ListAdd($$, $1); ((MemberInit)$$->last).loc = @$; }
1020    | default_property_list ',' default_property      { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
1021    | default_property_list_error ',' default_property      { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
1022    ;
1023
1024 default_property_list_error:
1025       default_property_error      { $$ = MkList(); ListAdd($$, $1); ((MemberInit)$$->last).loc = @$; }
1026    | default_property_list ',' default_property_error      { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
1027    | default_property_list_error ',' default_property_error      { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
1028    | default_property_list error
1029    ;
1030
1031 property_start:
1032      PROPERTY property_specifiers identifier '{'
1033       { $$ = MkProperty($2, null, $3, null, null); $$.loc = @$; }
1034
1035    | PROPERTY property_specifiers abstract_declarator identifier '{'
1036       { $$ = MkProperty($2, $3, $4, null, null); $$.loc = @$; }
1037
1038    | PROPERTY property_specifiers '{'
1039       { $$ = MkProperty($2, null, null, null, null); $$.loc = @$; }
1040
1041    | PROPERTY property_specifiers abstract_declarator '{'
1042       { $$ = MkProperty($2, $3, null, null, null); $$.loc = @$; }
1043
1044    | PROPERTY error '{'
1045       { $$ = MkProperty(null, null, null, null, null); $$.loc = @$; }
1046    ;
1047
1048 property_body:
1049      property_start
1050    | property_body SETPROP compound_statement
1051       { $1.setStmt = $3; }
1052    | property_body GETPROP compound_statement
1053       { $1.getStmt = $3; }
1054    | property_body ISPROPSET compound_statement
1055       { $1.issetStmt = $3; }
1056    | property_body WATCHABLE
1057       { $1.isWatchable = true; }
1058    | property_body PROPERTY_CATEGORY i18n_string
1059       { $1.category = $3; }
1060         ;
1061
1062 property:
1063    property_body '}' { $1.loc.end = @2.end; $$ = $1; }
1064    ;
1065
1066 class_property_start:
1067      CLASS_PROPERTY property_specifiers identifier '{'
1068       { $$ = MkProperty($2, null, $3, null, null); $$.loc = @$; }
1069
1070    | CLASS_PROPERTY property_specifiers abstract_declarator identifier '{'
1071       { $$ = MkProperty($2, $3, $4, null, null); $$.loc = @$; }
1072
1073    | CLASS_PROPERTY property_specifiers '{'
1074       { $$ = MkProperty($2, null, null, null, null); $$.loc = @$; }
1075
1076    | CLASS_PROPERTY property_specifiers abstract_declarator '{'
1077       { $$ = MkProperty($2, $3, null, null, null); $$.loc = @$; }
1078
1079    | CLASS_PROPERTY error '{'
1080       { $$ = MkProperty(null, null, null, null, null); $$.loc = @$; }
1081    ;
1082
1083 class_property_body:
1084      class_property_start
1085    | class_property_body SETPROP compound_statement
1086       { $1.setStmt = $3; }
1087    | class_property_body GETPROP compound_statement
1088       { $1.getStmt = $3; }
1089         ;
1090
1091 class_property:
1092    class_property_body '}' { $1.loc.end = @2.end; }
1093    ;
1094
1095 watch_property_list:
1096           identifier
1097       { $$ = MkListOne($1); }
1098         | watch_property_list identifier
1099       { ListAdd($1, $2); }
1100         ;
1101
1102 property_watch:
1103           watch_property_list compound_statement
1104       { $$ = MkPropertyWatch($1, $2); }
1105         | DELETE compound_statement
1106       { $$ = MkDeleteWatch($2); }
1107         ;
1108
1109 property_watch_list:
1110           property_watch
1111       { $$ = MkListOne($1); }
1112         | property_watch_list property_watch
1113       { ListAdd($1, $2); }
1114         ;
1115
1116 self_watch_definition:
1117         WATCH '(' watch_property_list ')' compound_statement
1118       { $$ = MkPropertyWatch($3, $5); }
1119         ;
1120
1121 watch_definition:
1122           WATCH '(' assignment_expression ')' '{' property_watch_list '}'
1123         { $$ = MkWatchStmt(null, $3, $6); }
1124         | assignment_expression '.' WATCH '(' assignment_expression ')' '{' property_watch_list '}'
1125         { $$ = MkWatchStmt($1, $5, $8); }
1126         ;
1127
1128 stopwatching:
1129           STOPWATCHING '(' assignment_expression ',' watch_property_list ')'
1130         { $$ = MkStopWatchingStmt(null, $3, $5); }
1131         | assignment_expression '.' STOPWATCHING '(' assignment_expression ',' watch_property_list ')'
1132         { $$ = MkStopWatchingStmt($1, $5, $7); }
1133         | STOPWATCHING '(' assignment_expression ')'
1134         { $$ = MkStopWatchingStmt(null, $3, null); }
1135         | assignment_expression '.' STOPWATCHING '(' assignment_expression ')'
1136         { $$ = MkStopWatchingStmt($1, $5, null); }
1137         ;
1138
1139 firewatchers:
1140           FIREWATCHERS
1141         { $$ = MkFireWatchersStmt(null, null); }
1142         | FIREWATCHERS watch_property_list
1143         { $$ = MkFireWatchersStmt(null, $2); }
1144         | postfix_expression '.' FIREWATCHERS
1145         { $$ = MkFireWatchersStmt($1, null); }
1146         | assignment_expression '.' FIREWATCHERS watch_property_list
1147         { $$ = MkFireWatchersStmt($1, $4); }
1148         ;
1149
1150 struct_declaration:
1151      struct_declaration_error ';' { $$ = $1; $$.loc.end = @2.end; }
1152    | default_property_list ';'     { $$ = MkClassDefDefaultProperty($1); if($1->last) ((MemberInit)$1->last).loc.end = @2.start; $$.loc = @$; }
1153    | class_function_definition                                       { $$ = MkClassDefFunction($1); $$.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1154    | property                       { $$ = MkClassDefProperty($1); $$.loc = @$; globalContext.nextID++; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1155    | member_access class_function_definition                                       { $$ = MkClassDefFunction($2); $$.loc = @$; $$.memberAccess = $1; }
1156    | member_access property                       { $$ = MkClassDefProperty($2); $$.loc = @$; globalContext.nextID++; $$.memberAccess = $1; }
1157    | class_property                 { $$ = MkClassDefClassProperty($1); $$.loc = @$; globalContext.nextID++; }
1158    | WATCHABLE { $$ = null; deleteWatchable = true; }
1159    | CLASS_NO_EXPANSION             { $$ = MkClassDefNoExpansion(); }
1160    | CLASS_FIXED                    { $$ = MkClassDefFixed(); }
1161    | CLASS_PROPERTY '(' identifier ')' '=' initializer_condition ';' { $$ = MkClassDefClassPropertyValue($3, $6); $$.loc = @$; }
1162
1163    | ';' { $$ = null; }
1164    | member_access ':' { memberAccessStack[defaultMemberAccess] = $1; if(defaultMemberAccess == 0) { $$ = MkClassDefMemberAccess(); $$.memberAccess = $1; $$.loc = @$; } else $$ = null; }
1165
1166    | member_access '(' identifier ')'     { $$ = MkClassDefAccessOverride($1, $3); $$.loc = @$; }
1167         ;
1168
1169 struct_declaration_error:
1170      class_function_definition_error { $$ = MkClassDefFunction($1); $$.loc = $1.loc;  $$.loc.end.charPos++; $$.loc.end.pos++; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1171
1172 // Moved all these in here without the ';'
1173    | guess_declaration_specifiers                                { $$ = MkClassDefDeclaration(MkStructDeclaration($1, null, null)); $$.decl.loc = @$; $$.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1174         | guess_declaration_specifiers struct_declarator_list          { $$ = MkClassDefDeclaration(MkStructDeclaration($1, $2, null)); $$.decl.loc = @$; $$.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1175         | member_access guess_declaration_specifiers struct_declarator_list         { $$ = MkClassDefDeclaration(MkStructDeclaration($2, $3, null)); $$.decl.loc = @$; $$.loc = @$; $$.memberAccess = $1; }
1176    | member_access guess_declaration_specifiers                                { $$ = MkClassDefDeclaration(MkStructDeclaration($2, null, null)); $$.decl.loc = @$; $$.loc = @$; $$.memberAccess = $1; }
1177    | member_access instantiation_unnamed                                       { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = @$; $$.memberAccess = $1; }
1178    | member_access guess_instantiation_named                                   { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = @$; $$.memberAccess = $1; }
1179    | CLASS_DATA guess_declaration_specifiers struct_declarator_list { $$ = MkClassDefClassData(MkStructDeclaration($2, $3, null)); $$.decl.loc = @$; $$.loc = @$; }
1180    | self_watch_definition      { $$ = MkClassDefPropertyWatch($1); $$.loc = @$; globalContext.nextID++; }
1181    | CLASS_DESIGNER identifier { $$ = MkClassDefDesigner($2.string); FreeIdentifier($2); }
1182    | CLASS_DESIGNER strict_type { $$ = MkClassDefDesigner($2.name); FreeSpecifier($2); }
1183    | CLASS_DEFAULT_PROPERTY identifier { $$ = MkClassDefDesignerDefaultProperty($2); }
1184    | instantiation_unnamed                                       { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = @$; $$.decl.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1185    | guess_instantiation_named                                   { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = @$; $$.decl.loc = @$; $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1186    | default_property_list     { $$ = MkClassDefDefaultProperty($1); if($1->last) ((MemberInit)$1->last).loc.end = @1.end; $$.loc = @$; }
1187
1188    | guess_instantiation_named_error error { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = $1.loc; $$.decl.loc = $$.loc;  $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1189    | instantiation_unnamed_error error { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = $1.loc; $$.decl.loc = $$.loc;  $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1190 //   | guess_instantiation_named { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = $1.loc; $$.decl.loc = $$.loc;  $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1191 //   | instantiation_unnamed { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = $1.loc; $$.decl.loc = $$.loc;  $$.memberAccess = memberAccessStack[defaultMemberAccess]; }
1192
1193    | member_access class_function_definition_error { $$ = MkClassDefFunction($2); $$.loc = @$;  $$.loc.end.charPos++; $$.loc.end.pos++; $$.memberAccess = $1; }
1194    | member_access guess_instantiation_named_error error { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = $$.loc; $$.memberAccess = $1; }
1195    | member_access instantiation_unnamed_error error { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = $$.loc; $$.memberAccess = $1; }
1196 //   | member_access guess_instantiation_named { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = $$.loc; $$.memberAccess = $1; }
1197 //   | member_access instantiation_unnamed { $$ = MkClassDefDeclaration(MkDeclarationClassInst($2)); $$.loc = @$; $$.decl.loc = $$.loc; $$.memberAccess = $1; }
1198
1199    | default_property_list_error { $$ = MkClassDefDefaultProperty($1); $$.loc = @$;  $$.loc.end.charPos++; $$.loc.end.pos++; }
1200    ;
1201
1202 struct_declaration_list:
1203           struct_declaration { $$ = MkList(); ListAdd($$, $1); }
1204         | struct_declaration_list struct_declaration   { $$ = $1; ListAdd($1, $2); }
1205    | struct_declaration_list_error struct_declaration   { $$ = $1; ListAdd($1, $2); }
1206         ;
1207
1208 struct_declaration_list_error:
1209      struct_declaration_error { yyerror(); $$ = MkList(); ListAdd($$, $1); }
1210    | struct_declaration_list error
1211    | struct_declaration_list_error error
1212    | struct_declaration_list struct_declaration_error { yyerror(); $$ = $1; ListAdd($$, $2); }
1213    | struct_declaration_list_error struct_declaration_error { $$ = $1; ListAdd($$, $2); }
1214         ;
1215
1216 template_datatype:
1217      guess_declaration_specifiers { $$ = MkTemplateDatatype($1, null); }
1218    | guess_declaration_specifiers abstract_declarator { $$ = MkTemplateDatatype($1, $2); }
1219 //   | identifier { $$ = MkTemplateDatatype(MkListOne(MkSpecifierName($1.string)), null); FreeIdentifier($1); }
1220    ;
1221
1222 template_type_argument:
1223 //     template_datatype { $$ = MkTemplateTypeArgument($1); }
1224
1225 //    Explicitly copied the rules here to handle:
1226 //      ast.ec:  Map<List<Location>> intlStrings { };
1227 //          vs
1228 //      LinkList.ec:   class LinkList<bool circ = false>
1229
1230      guess_declaration_specifiers { $$ = MkTemplateTypeArgument(MkTemplateDatatype($1, null)); }
1231    | guess_declaration_specifiers abstract_declarator { $$ = MkTemplateTypeArgument(MkTemplateDatatype($1, $2)); }
1232    ;
1233
1234 template_type_parameter:
1235      CLASS identifier { $$ = MkTypeTemplateParameter($2, null, null); }
1236    | CLASS identifier '=' template_type_argument { $$ = MkTypeTemplateParameter($2, null, $4); }
1237    | CLASS identifier ':' template_datatype { $$ = MkTypeTemplateParameter($2, $4, null); }
1238    | CLASS identifier ':' template_datatype '=' template_type_argument { $$ = MkTypeTemplateParameter($2, $4, $6); }
1239    | CLASS base_strict_type_name { $$ = MkTypeTemplateParameter(MkIdentifier($2), null, null); delete $2; }
1240    | CLASS base_strict_type_name '=' template_type_argument { $$ = MkTypeTemplateParameter(MkIdentifier($2), null, $4); }
1241    | CLASS base_strict_type_name ':' template_datatype { $$ = MkTypeTemplateParameter(MkIdentifier($2), $4, null); }
1242    | CLASS base_strict_type_name ':' template_datatype '=' template_type_argument { $$ = MkTypeTemplateParameter(MkIdentifier($2), $4, $6); }
1243    ;
1244
1245 template_identifier_argument:
1246      identifier { $$ = MkTemplateIdentifierArgument($1); }
1247    ;
1248
1249 template_identifier_parameter:
1250      identifier                                  { $$ = MkIdentifierTemplateParameter($1, dataMember, null); }
1251    | identifier '=' template_identifier_argument { $$ = MkIdentifierTemplateParameter($1, dataMember, $3); }
1252    ;
1253
1254 template_expression_argument:
1255      shift_expression /*constant_expression*/ { $$ = MkTemplateExpressionArgument($1); }
1256    ;
1257
1258 template_expression_parameter:
1259 /*
1260      template_datatype identifier     { $$ = MkExpressionTemplateParameter($2, $1, null); }
1261    | template_datatype identifier '=' template_expression_argument    { $$ = MkExpressionTemplateParameter($2, $1, $4); }
1262 */
1263      guess_declaration_specifiers identifier '=' template_expression_argument    { $$ = MkExpressionTemplateParameter($2, MkTemplateDatatype($1, null), $4); }
1264    | guess_declaration_specifiers abstract_declarator identifier '=' template_expression_argument    { $$ = MkExpressionTemplateParameter($3, MkTemplateDatatype($1, $2), $5); }
1265    ;
1266
1267 template_parameter:
1268      template_type_parameter
1269    | template_identifier_parameter
1270    | template_expression_parameter
1271    ;
1272
1273 template_parameters_list:
1274      template_parameter                               { $$ = MkList(); ListAdd($$, $1); }
1275    | template_parameters_list ',' template_parameter  { $$ = $1; ListAdd($1, $3); }
1276    ;
1277
1278 template_argument:
1279      template_expression_argument
1280    | template_identifier_argument
1281    | template_type_argument
1282    | identifier '=' template_expression_argument   { $$ = $3; $$.name = $1; $$.loc = @$; }
1283    | identifier '=' template_identifier_argument   { $$ = $3; $$.name = $1; $$.loc = @$; }
1284    | identifier '=' template_type_argument         { $$ = $3; $$.name = $1; $$.loc = @$; }
1285    /*| template_datatype '=' template_expression_argument
1286    {
1287       $$ = $3;
1288       if($1.specifiers && $1.specifiers->first)
1289       {
1290          Specifier spec = $1.specifiers->first;
1291          if(spec.type == nameSpecifier)
1292             $$.name = MkIdentifier(spec.name);
1293       }
1294       FreeTemplateDataType($1);
1295       $$.loc = @$;
1296    }
1297    | template_datatype '=' template_identifier_argument
1298    {
1299       $$ = $3;
1300       if($1.specifiers && $1.specifiers->first)
1301       {
1302          Specifier spec = $1.specifiers->first;
1303          if(spec.type == nameSpecifier)
1304             $$.name = MkIdentifier(spec.name);
1305       }
1306       FreeTemplateDataType($1);
1307       $$.loc = @$;
1308    }
1309    | template_datatype '=' template_type_argument
1310    {
1311       $$ = $3;
1312       if($1.specifiers && $1.specifiers->first)
1313       {
1314          Specifier spec = $1.specifiers->first;
1315          if(spec.type == nameSpecifier)
1316             $$.name = MkIdentifier(spec.name);
1317       }
1318       FreeTemplateDataType($1);
1319       $$.loc = @$;
1320    }*/
1321    ;
1322
1323 template_arguments_list:
1324      template_argument                                { $$ = MkList(); ListAdd($$, $1); }
1325    | template_arguments_list ',' template_argument    { $$ = $1; ListAdd($1, $3); }
1326    ;
1327
1328 class_entry:
1329    CLASS
1330    {
1331       if(curContext != globalContext)
1332          PopContext(curContext);
1333       $$ = PushContext();
1334    };
1335
1336 class_decl:
1337      class_entry identifier { $1; $$ = DeclClassAddNameSpace(globalContext.nextID++, $2.string); FreeIdentifier($2); $$.nameLoc = @2; memberAccessStack[++defaultMemberAccess] = privateAccess; }
1338    | class_entry base_strict_type
1339    {
1340       $1; $$ = DeclClass(globalContext.nextID++, $2.name);
1341       $$.nameLoc = @2;
1342       FreeSpecifier($2);
1343       ++defaultMemberAccess;
1344       memberAccessStack[defaultMemberAccess] = privateAccess;
1345    }
1346    | identifier class_entry identifier { $2; $$ = DeclClassAddNameSpace(globalContext.nextID++, $3.string); FreeIdentifier($1); FreeIdentifier($3); $$.nameLoc = @3; $$.isRemote = true; memberAccessStack[++defaultMemberAccess] = privateAccess; }
1347    | identifier class_entry base_strict_type { $2; $$ = DeclClass(globalContext.nextID++, $3.name); FreeIdentifier($1); $$.nameLoc = @3; $$.isRemote = true; FreeSpecifier($3); memberAccessStack[++defaultMemberAccess] = privateAccess; }
1348
1349    | class_entry identifier '<' template_parameters_list '>' { $1; $$ = DeclClassAddNameSpace(globalContext.nextID++, $2.string); $$.templateParams = $4; FreeIdentifier($2); $$.nameLoc = @2; memberAccessStack[++defaultMemberAccess] = privateAccess; }
1350    | class_entry base_strict_type '<' template_parameters_list '>'
1351    {
1352       $1; $$ = DeclClass(globalContext.nextID++, $2.name);
1353       $$.templateParams = $4;
1354       $$.nameLoc = @2;
1355       FreeSpecifier($2);
1356       ++defaultMemberAccess;
1357       memberAccessStack[defaultMemberAccess] = privateAccess;
1358    }
1359    | 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; }
1360    | 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; }
1361    ;
1362
1363 class:
1364      class_error '}'
1365       {
1366          $$.loc = @$;
1367          $$ = $1;
1368       }
1369
1370    // Added this for unit classes...
1371         | class_head ';'
1372       {
1373          $$ = $1; $$.definitions = MkList(); $$.blockStart = @2;  $$.loc = @$; $$.endid = globalContext.nextID++;
1374          POP_DEFAULT_ACCESS
1375          PopContext(curContext);
1376       }
1377
1378         | class_decl '{' '}'
1379       {
1380          $$ = MkClass($1, null, MkList()); $$.blockStart = @2;  $$.loc = @$; $$.endid = globalContext.nextID++;
1381          POP_DEFAULT_ACCESS
1382          PopContext(curContext);
1383       }
1384         | class_head '{' '}'
1385       {
1386          $$ = $1; $$.definitions = MkList(); $$.blockStart = @2;  $$.loc = @$; $$.endid = globalContext.nextID++;
1387          POP_DEFAULT_ACCESS
1388          PopContext(curContext);
1389       }
1390
1391         | class_entry identifier ';'
1392       {
1393          $1; $$ = MkClass(DeclClassAddNameSpace(0, $2.string), null, null); FreeIdentifier($2);
1394          POP_DEFAULT_ACCESS
1395          PopContext(curContext);
1396       }
1397         | class_entry type ';'
1398       {
1399          $1; $$ = MkClass(DeclClass(0, $2.name), null, null); FreeSpecifier($2);
1400          POP_DEFAULT_ACCESS
1401          PopContext(curContext);
1402       }
1403    ;
1404
1405 class_head:
1406         class_decl ':' inheritance_specifiers
1407       {
1408          $$ = MkClass($1, $3, null);
1409       }
1410    ;
1411
1412 class_error:
1413          class_decl '{' struct_declaration_list_error
1414       {
1415          $$ = MkClass($1, null, $3); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2; $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1416          POP_DEFAULT_ACCESS
1417          PopContext(curContext);
1418       }
1419         | class_head '{' struct_declaration_list_error
1420       {
1421          $$ = $1; $$.definitions = $3; $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1422          POP_DEFAULT_ACCESS
1423          PopContext(curContext);
1424       }
1425         | class_decl '{' struct_declaration_list
1426       {
1427          $$ = MkClass($1, null, $3); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2; $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1428          POP_DEFAULT_ACCESS
1429          PopContext(curContext);
1430       }
1431         | class_head '{' struct_declaration_list
1432       {
1433          $$ = $1; $$.definitions = $3; $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1434          POP_DEFAULT_ACCESS
1435          PopContext(curContext);
1436       }
1437         | class_decl '{' error
1438       {
1439          $$ = MkClass($1, null, MkList()); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1440          POP_DEFAULT_ACCESS
1441          PopContext(curContext);
1442       }
1443         | class_head '{' error
1444       {
1445          $$ = $1; $$.definitions = MkList(); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1446          POP_DEFAULT_ACCESS
1447          PopContext(curContext);
1448       }
1449    ;
1450
1451 /**** EXPRESSIONS ********************************************************************/
1452
1453 identifier:
1454    IDENTIFIER
1455       { $$ = MkIdentifier(yytext); $$.loc = @1; }
1456    ;
1457
1458 primary_expression:
1459      simple_primary_expression
1460         | '(' expression ')'
1461       { $$ = MkExpBrackets($2); $$.loc = @$; }
1462    ;
1463
1464 i18n_string:
1465           string_literal     { $$ = MkExpString($1); delete $1; $$.loc = @$; }
1466    | '$' string_literal     { $$ = MkExpIntlString($2, null); delete $2; $$.loc = @$; }
1467    | '$' string_literal '.' string_literal     { $$ = MkExpIntlString($4, $2); delete $2; delete $4; $$.loc = @$; }
1468    ;
1469
1470 constant:
1471    CONSTANT { $$ = MkExpConstant(yytext); $$.loc = @$; }
1472    ;
1473
1474 simple_primary_expression:
1475           identifier         { $$ = MkExpIdentifier($1); $$.loc = @$; }
1476    | instantiation_unnamed      { $$ = MkExpInstance($1); $$.loc = @$; }
1477    | EXTENSION '(' compound_statement ')'    { $$ = MkExpExtensionCompound($3); $$.loc = @$; }
1478    | EXTENSION '(' expression ')'    { $$ = MkExpExtensionExpression($3); $$.loc = @$; }
1479    | EXTENSION '(' type_name ')' initializer     { $$ = MkExpExtensionInitializer($3, $5); $$.loc = @$; }
1480    | EXTENSION '(' type_name ')' '(' type_name ')' initializer     { $$ = MkExpExtensionInitializer($3, MkInitializerAssignment(MkExpExtensionInitializer($6, $8))); $$.loc = @$; }
1481    | constant identifier
1482    {
1483       char * constant = $1.constant;
1484       int len = strlen(constant);
1485       if(constant[len-1] == '.')
1486       {
1487          constant[len-1] = 0;
1488          $$ = MkExpMember($1, $2);
1489          $$.loc = @$;
1490       }
1491       else
1492          yyerror();
1493    }
1494         | constant { $$ = $1; }
1495    | i18n_string
1496    | '(' ')' { Expression exp = MkExpDummy(); exp.loc.start = @1.end; exp.loc.end = @2.start; $$ = MkExpBrackets(MkListOne(exp)); $$.loc = @$; yyerror(); }
1497    | NEWOP new_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpNew(MkTypeName($2,$3), $5); $$.loc = @$; }
1498    | NEWOP new_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpNew(MkTypeName($2,$3), $5); $$.loc = @$; }
1499    | NEWOP new_specifiers '[' constant_expression ']' { $$ = MkExpNew(MkTypeName($2,null), $4); $$.loc = @$; }
1500    | NEWOP new_specifiers '[' constant_expression_error ']' { $$ = MkExpNew(MkTypeName($2,null), $4); $$.loc = @$; }
1501    | NEW0OP new_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpNew0(MkTypeName($2,$3), $5); $$.loc = @$; }
1502    | NEW0OP new_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpNew0(MkTypeName($2,$3), $5); $$.loc = @$; }
1503    | NEW0OP new_specifiers '[' constant_expression ']' { $$ = MkExpNew0(MkTypeName($2,null), $4); $$.loc = @$; }
1504    | NEW0OP new_specifiers '[' constant_expression_error ']' { $$ = MkExpNew0(MkTypeName($2,null), $4); $$.loc = @$; }
1505    | RENEW constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpRenew($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1506    | RENEW constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpRenew($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1507    | RENEW constant_expression renew_specifiers '[' constant_expression ']' { $$ = MkExpRenew($2, MkTypeName($3,null), $5); $$.loc = @$; }
1508    | RENEW constant_expression renew_specifiers '[' constant_expression_error ']' { $$ = MkExpRenew($2, MkTypeName($3,null), $5); $$.loc = @$; }
1509    | RENEW0 constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpRenew0($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1510    | RENEW0 constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpRenew0($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1511    | RENEW0 constant_expression renew_specifiers '[' constant_expression ']' { $$ = MkExpRenew0($2, MkTypeName($3,null), $5); $$.loc = @$; }
1512    | RENEW0 constant_expression renew_specifiers '[' constant_expression_error ']' { $$ = MkExpRenew0($2, MkTypeName($3,null), $5); $$.loc = @$; }
1513    | CLASS '(' declaration_specifiers ')' { $$ = MkExpClass($3, null); $$.loc = @$; }
1514    | CLASS '(' declaration_specifiers abstract_declarator ')' { $$ = MkExpClass($3, $4); $$.loc = @$; }
1515    | CLASS '(' identifier ')' { $$ = MkExpClass(MkListOne(MkSpecifierName($3.string)), null); FreeIdentifier($3); $$.loc = @$; }
1516    | VAARG '(' assignment_expression ',' type_name ')' { $$ = MkExpVaArg($3, $5); $$.loc = @$; }
1517
1518    | CLASS_DATA '(' identifier ')' { $$ = MkExpClassData($3); $$.loc = @$; }
1519    | database_open
1520    | dbfield
1521    | dbindex
1522    | dbtable
1523
1524    | '[' argument_expression_list /*expression*/ ']' { $$ = MkExpArray($2); $$.loc = @$; }
1525    | '[' ']' { $$ = MkExpArray(null); $$.loc = @$; }
1526    ;
1527
1528 anon_instantiation_expression:
1529    instantiation_anon            { $$ = MkExpInstance($1); $$.loc = @$; }
1530    ;
1531
1532 anon_instantiation_expression_error:
1533    instantiation_anon_error error           { $$ = MkExpInstance($1); $$.loc = @$; }
1534    ;
1535
1536 primary_expression_error:
1537           '(' expression  { yyerror(); $$ = MkExpBrackets($2); $$.loc = @$; }
1538    | '(' expression_error { $$ = MkExpBrackets($2); $$.loc = @$; }
1539    ;
1540
1541 postfix_expression:
1542           primary_expression
1543
1544    | postfix_expression '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1545    | postfix_expression '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1546         | postfix_expression '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1547         | postfix_expression '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; }
1548    | 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; }
1549         | postfix_expression '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1550         | postfix_expression PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1551         | postfix_expression INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1552         | postfix_expression DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1553
1554    | postfix_expression_error '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1555    | postfix_expression_error '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1556         | postfix_expression_error '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1557         | postfix_expression_error '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end;$$.loc = @$; }
1558         | postfix_expression_error '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1559         | postfix_expression_error PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1560         | postfix_expression_error INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1561         | postfix_expression_error DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1562 ;
1563
1564 simple_postfix_expression:
1565           simple_primary_expression
1566
1567    | simple_postfix_expression '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1568    | simple_postfix_expression '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1569         | simple_postfix_expression '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1570         | simple_postfix_expression '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; }
1571    | 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; }
1572         | simple_postfix_expression '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1573         | simple_postfix_expression PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1574         | simple_postfix_expression INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1575         | simple_postfix_expression DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1576
1577    | simple_postfix_expression_error '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1578    | simple_postfix_expression_error '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1579         | simple_postfix_expression_error '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1580         | simple_postfix_expression_error '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end;$$.loc = @$; }
1581         | simple_postfix_expression_error '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1582         | simple_postfix_expression_error PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1583         | simple_postfix_expression_error INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1584         | simple_postfix_expression_error DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1585 ;
1586
1587 argument_expression_list:
1588           assignment_expression          { $$ = MkList(); ListAdd($$, $1); }
1589    | anon_instantiation_expression  { $$ = MkList(); ListAdd($$, $1); }
1590         | argument_expression_list ',' assignment_expression   { $$ = $1; ListAdd($1, $3);  }
1591    | argument_expression_list ',' anon_instantiation_expression   { $$ = $1; ListAdd($1, $3);  }
1592         ;
1593
1594 argument_expression_list_error:
1595      assignment_expression_error    { $$ = MkList(); ListAdd($$, $1); }
1596    | anon_instantiation_expression_error    { $$ = MkList(); ListAdd($$, $1); }
1597    | argument_expression_list ',' assignment_expression_error  { $$ = $1; ListAdd($1, $3);  }
1598    | argument_expression_list ',' anon_instantiation_expression_error  { $$ = $1; ListAdd($1, $3);  }
1599    | argument_expression_list ',' { Expression exp = MkExpDummy(); yyerror(); exp.loc.start = @2.end; exp.loc.end = @2.end; $$ = $1; ListAdd($1, exp); }
1600         ;
1601
1602 common_unary_expression:
1603           INC_OP unary_expression           { $$ = MkExpOp(null, INC_OP, $2); $$.loc = @$; }
1604         | DEC_OP unary_expression           { $$ = MkExpOp(null, DEC_OP, $2); $$.loc = @$; }
1605         | unary_operator cast_expression    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1606    | unary_operator anon_instantiation_expression    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1607         | SIZEOF '(' unary_expression ')'         { $$ = MkExpOp(null, SIZEOF, $3); $$.loc = @$; }
1608    | SIZEOF simple_unary_expression           { $$ = MkExpOp(null, SIZEOF, $2); $$.loc = @$; }
1609    | SIZEOF '(' guess_type_name ')'          { $$ = MkExpTypeSize($3); $$.loc = @$; }
1610    | SIZEOF '(' CLASS type ')'          { $$ = MkExpClassSize($4); $$.loc = @$; }
1611    | SIZEOF '(' CLASS guess_type ')'          { $$ = MkExpClassSize($4); $$.loc = @$; }
1612
1613         | ALIGNOF '(' unary_expression ')'         { $$ = MkExpOp(null, ALIGNOF, $3); $$.loc = @$; }
1614    | ALIGNOF simple_unary_expression           { $$ = MkExpOp(null, ALIGNOF, $2); $$.loc = @$; }
1615    | ALIGNOF '(' guess_type_name ')'          { $$ = MkExpTypeAlign($3); $$.loc = @$; }
1616         ;
1617
1618 unary_expression:
1619        common_unary_expression
1620           | postfix_expression
1621         ;
1622
1623 simple_unary_expression:
1624      common_unary_expression
1625         | simple_postfix_expression
1626         ;
1627
1628 unary_operator:
1629           '&'     { $$ = '&'; }
1630         | '*'     { $$ = '*'; }
1631         | '+'     { $$ = '+'; }
1632         | '-'     { $$ = '-'; }
1633         | '~'     { $$ = '~'; }
1634         | '!'     { $$ = '!'; }
1635    | DELETE  { $$ = DELETE; }
1636    | _INCREF  { $$ = _INCREF; }
1637         ;
1638
1639 cast_expression:
1640        unary_expression
1641         | '(' type_name ')' cast_expression    { $$ = MkExpCast($2, $4); $$.loc = @$; }
1642         ;
1643
1644 multiplicative_expression:
1645           cast_expression
1646         | multiplicative_expression '*' cast_expression { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
1647         | multiplicative_expression '/' cast_expression { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
1648         | multiplicative_expression '%' cast_expression { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
1649         | multiplicative_expression_error '*' 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         ;
1653
1654 additive_expression:
1655           multiplicative_expression
1656         | additive_expression '+' multiplicative_expression  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
1657         | additive_expression '-' multiplicative_expression  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
1658         | additive_expression_error '+' multiplicative_expression  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
1659         | additive_expression_error '-' multiplicative_expression  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
1660         ;
1661
1662 shift_expression:
1663           additive_expression
1664         | shift_expression LEFT_OP additive_expression  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
1665         | shift_expression RIGHT_OP additive_expression { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
1666         | shift_expression_error LEFT_OP additive_expression  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
1667         | shift_expression_error RIGHT_OP additive_expression { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
1668         ;
1669
1670 relational_expression_smaller_than:
1671    relational_expression '<'
1672    {
1673       $$ = $1;
1674       skipErrors = true;
1675    }
1676    ;
1677
1678 relational_expression:
1679           shift_expression
1680         | relational_expression_smaller_than /*relational_expression '<' */ shift_expression    { skipErrors = false; $$ = MkExpOp($1, '<', $2/*$3*/); $$.loc = @$; }
1681         | relational_expression '>' shift_expression    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
1682         | relational_expression LE_OP shift_expression  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
1683         | relational_expression GE_OP shift_expression  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
1684         | relational_expression_error '<' shift_expression    { $$ = MkExpOp($1, '<', $3); $$.loc = @$; }
1685         | relational_expression_error '>' shift_expression    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
1686         | relational_expression_error LE_OP shift_expression  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
1687         | relational_expression_error GE_OP shift_expression  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
1688         ;
1689
1690 equality_expression
1691         : relational_expression
1692         | equality_expression EQ_OP relational_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1693         | equality_expression NE_OP relational_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1694         | equality_expression_error EQ_OP relational_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1695         | equality_expression_error NE_OP relational_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1696
1697         | equality_expression EQ_OP anon_instantiation_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1698         | equality_expression NE_OP anon_instantiation_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1699         | equality_expression_error EQ_OP anon_instantiation_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1700         | equality_expression_error NE_OP anon_instantiation_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1701         ;
1702
1703 and_expression
1704         : equality_expression
1705         | and_expression '&' equality_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1706         | and_expression_error '&' equality_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1707
1708         | and_expression '&' anon_instantiation_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1709         | and_expression_error '&' anon_instantiation_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1710         ;
1711
1712 exclusive_or_expression
1713         : and_expression
1714         | exclusive_or_expression '^' and_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1715         | exclusive_or_expression_error '^' and_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1716
1717         | exclusive_or_expression '^' anon_instantiation_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1718         | exclusive_or_expression_error '^' anon_instantiation_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1719         ;
1720
1721 inclusive_or_expression
1722         : exclusive_or_expression
1723         | inclusive_or_expression '|' exclusive_or_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1724         | inclusive_or_expression_error '|' exclusive_or_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1725
1726         | inclusive_or_expression '|' anon_instantiation_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1727         | inclusive_or_expression_error '|' anon_instantiation_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1728         ;
1729
1730 logical_and_expression
1731         : inclusive_or_expression
1732         | logical_and_expression AND_OP inclusive_or_expression  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
1733         | logical_and_expression_error AND_OP inclusive_or_expression  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
1734         ;
1735
1736 logical_or_expression
1737         : logical_and_expression
1738         | logical_or_expression OR_OP logical_and_expression     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
1739         | logical_or_expression_error OR_OP logical_and_expression     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
1740         ;
1741
1742 conditional_expression
1743         : logical_or_expression
1744         | logical_or_expression '?' expression ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1745    | logical_or_expression '?' expression_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1746         | logical_or_expression_error '?' expression ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1747    | logical_or_expression_error '?' expression_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1748
1749         | logical_or_expression '?' expression_anon_inst ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1750    | logical_or_expression '?' expression_anon_inst_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1751         | logical_or_expression_error '?' expression_anon_inst ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1752    | logical_or_expression_error '?' expression_anon_inst_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1753
1754         | logical_or_expression '?' expression ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1755    | logical_or_expression '?' expression_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1756         | logical_or_expression_error '?' expression ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1757    | logical_or_expression_error '?' expression_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1758
1759         | logical_or_expression '?' expression_anon_inst ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1760    | logical_or_expression '?' expression_anon_inst_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1761         | logical_or_expression_error '?' expression_anon_inst ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1762    | logical_or_expression_error '?' expression_anon_inst_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1763         ;
1764
1765 assignment_expression:
1766           conditional_expression
1767         | unary_expression assignment_operator assignment_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1768    | unary_expression_error assignment_operator assignment_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1769         | conditional_expression assignment_operator assignment_expression   { Compiler_Error($"l-value expected\n"); $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1770    | conditional_expression_error assignment_operator assignment_expression   { Compiler_Error($"l-value expected\n"); $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1771
1772         | unary_expression assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1773    | unary_expression_error assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1774         | conditional_expression assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1775    | conditional_expression_error assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1776         ;
1777
1778 assignment_operator:
1779           '='                   { $$ = '='; }
1780         | MUL_ASSIGN            { $$ = MUL_ASSIGN; }
1781         | DIV_ASSIGN            { $$ = DIV_ASSIGN; }
1782         | MOD_ASSIGN            { $$ = MOD_ASSIGN; }
1783         | ADD_ASSIGN            { $$ = ADD_ASSIGN; }
1784         | SUB_ASSIGN            { $$ = SUB_ASSIGN; }
1785         | LEFT_ASSIGN           { $$ = LEFT_ASSIGN; }
1786         | RIGHT_ASSIGN          { $$ = RIGHT_ASSIGN; }
1787         | AND_ASSIGN            { $$ = AND_ASSIGN; }
1788         | XOR_ASSIGN            { $$ = XOR_ASSIGN; }
1789         | OR_ASSIGN             { $$ = OR_ASSIGN; }
1790         ;
1791
1792 expression:
1793    assignment_expression                 { $$ = MkList(); ListAdd($$, $1); }
1794         | expression ',' assignment_expression  { $$ = $1; ListAdd($1, $3); }
1795    | expression_error ',' assignment_expression  { $$ = $1; ListAdd($1, $3); }
1796    | expression_error  ')'
1797         ;
1798
1799 expression_anon_inst:
1800      anon_instantiation_expression                 { $$ = MkList(); ListAdd($$, $1); }
1801    | expression ',' anon_instantiation_expression  { $$ = $1; ListAdd($1, $3); }
1802         | expression_error ',' anon_instantiation_expression  { $$ = $1; ListAdd($1, $3); }
1803    ;
1804
1805 postfix_expression_error:
1806    primary_expression_error
1807    | error { $$ = MkExpDummy(); $$.loc = @$; /*printf("Sorry, didn't mean that syntax error\n");*/ }
1808    | postfix_expression error
1809    | instantiation_unnamed_error error { $$ = MkExpInstance($1); $$.loc = @$; }
1810
1811    | postfix_expression PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1812    | postfix_expression_error PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1813
1814    | postfix_expression '(' argument_expression_list { yyerror(); $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; $$.call.argLoc.end.charPos++;}
1815         | postfix_expression '(' argument_expression_list_error { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; $$.call.argLoc.end.charPos++;}
1816    /* Useless rules due to conflicts
1817    | postfix_expression '(' argument_expression_list ',' error { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end;$$.loc = @$; $$.call.argLoc.end.charPos++;}
1818    | postfix_expression '(' error { $$ = MkExpCall($1, MkList() ); @$.end = yylloc.start; $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = yylloc.start; }
1819    */
1820    | postfix_expression '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1821
1822         | 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++;}
1823    /* Useless rules due to conflicts
1824    | 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++;}
1825    | postfix_expression_error '(' error { $$ = MkExpCall($1, MkList() ); $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @2.end; $$.call.argLoc.end.charPos++;}
1826    */
1827    | postfix_expression_error '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1828         ;
1829
1830 simple_postfix_expression_error:
1831       error { $$ = MkExpDummy(); $$.loc = @$; }
1832    | simple_postfix_expression error
1833    | instantiation_unnamed_error error { $$ = MkExpInstance($1); $$.loc = @$; }
1834
1835    | simple_postfix_expression PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1836    | simple_postfix_expression_error PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1837
1838    | 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++;}
1839         | 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++;}
1840    /* Useless rules due to conflicts
1841    | 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++;}
1842    | simple_postfix_expression '(' error { $$ = MkExpCall($1, MkList() ); @$.end = yylloc.start; $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = yylloc.start; }
1843    */
1844    | simple_postfix_expression '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1845
1846         | 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++;}
1847    /* Useless rules due to conflicts
1848    | 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++;}
1849    | simple_postfix_expression_error '(' error { $$ = MkExpCall($1, MkList() ); $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @2.end; $$.call.argLoc.end.charPos++;}
1850    */
1851    | simple_postfix_expression_error '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1852         ;
1853
1854 common_unary_expression_error:
1855            INC_OP unary_expression_error           { $$ = MkExpOp(null, INC_OP, $2); $$.loc = @$; }
1856          | DEC_OP unary_expression_error           { $$ = MkExpOp(null, DEC_OP, $2); $$.loc = @$; }
1857          | unary_operator cast_expression_error    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1858     | unary_operator anon_instantiation_expression_error    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1859     | SIZEOF '(' unary_expression_error           { $$ = MkExpOp(null, SIZEOF, $3); $$.loc = @$; }
1860          | SIZEOF simple_unary_expression_error           { $$ = MkExpOp(null, SIZEOF, $2); $$.loc = @$; }
1861          | SIZEOF '(' guess_type_name ')' error          { $$ = MkExpTypeSize($3); $$.loc = @$; }
1862     | SIZEOF '(' CLASS type ')' error   { $$ = MkExpClassSize($4); $$.loc = @$; }
1863     | SIZEOF '(' CLASS guess_type ')' error   { $$ = MkExpClassSize($4); $$.loc = @$; }
1864     | ALIGNOF '(' unary_expression_error           { $$ = MkExpOp(null, ALIGNOF, $3); $$.loc = @$; }
1865          | ALIGNOF simple_unary_expression_error           { $$ = MkExpOp(null, ALIGNOF, $2); $$.loc = @$; }
1866          | ALIGNOF '(' guess_type_name ')' error          { $$ = MkExpTypeAlign($3); $$.loc = @$; }
1867         ;
1868
1869 unary_expression_error:
1870      common_unary_expression_error
1871         | postfix_expression_error
1872    ;
1873
1874 simple_unary_expression_error:
1875      common_unary_expression_error
1876         | simple_postfix_expression_error
1877    ;
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 %%