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