wip II
[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      guess_declaration_specifiers { $$ = MkTemplateDatatype($1, null); }
1184    | guess_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 //    Explicitly copied the rules here to handle:
1192 //      ast.ec:  Map<List<Location>> intlStrings { };
1193 //          vs
1194 //      LinkList.ec:   class LinkList<bool circ = false>
1195
1196      guess_declaration_specifiers { $$ = MkTemplateTypeArgument(MkTemplateDatatype($1, null)); }
1197    | guess_declaration_specifiers abstract_declarator { $$ = MkTemplateTypeArgument(MkTemplateDatatype($1, $2)); }
1198    ;
1199
1200 template_type_parameter:
1201      CLASS identifier { $$ = MkTypeTemplateParameter($2, null, null); }
1202    | CLASS identifier '=' template_type_argument { $$ = MkTypeTemplateParameter($2, null, $4); }
1203    | CLASS identifier ':' template_datatype { $$ = MkTypeTemplateParameter($2, $4, null); }
1204    | CLASS identifier ':' template_datatype '=' template_type_argument { $$ = MkTypeTemplateParameter($2, $4, $6); }
1205    | CLASS base_strict_type_name { $$ = MkTypeTemplateParameter(MkIdentifier($2), null, null); delete $2; }
1206    | CLASS base_strict_type_name '=' template_type_argument { $$ = MkTypeTemplateParameter(MkIdentifier($2), null, $4); }
1207    | CLASS base_strict_type_name ':' template_datatype { $$ = MkTypeTemplateParameter(MkIdentifier($2), $4, null); }
1208    | CLASS base_strict_type_name ':' template_datatype '=' template_type_argument { $$ = MkTypeTemplateParameter(MkIdentifier($2), $4, $6); }
1209    ;
1210
1211 template_identifier_argument:
1212      identifier { $$ = MkTemplateIdentifierArgument($1); }
1213    ;
1214
1215 template_identifier_parameter:
1216      identifier                                  { $$ = MkIdentifierTemplateParameter($1, dataMember, null); }
1217    | identifier '=' template_identifier_argument { $$ = MkIdentifierTemplateParameter($1, dataMember, $3); }
1218    ;
1219
1220 template_expression_argument:
1221      shift_expression /*constant_expression*/ { $$ = MkTemplateExpressionArgument($1); }
1222    ;
1223
1224 template_expression_parameter:
1225 /*
1226      template_datatype identifier     { $$ = MkExpressionTemplateParameter($2, $1, null); }
1227    | template_datatype identifier '=' template_expression_argument    { $$ = MkExpressionTemplateParameter($2, $1, $4); }
1228 */
1229      guess_declaration_specifiers identifier '=' template_expression_argument    { $$ = MkExpressionTemplateParameter($2, MkTemplateDatatype($1, null), $4); }
1230    | guess_declaration_specifiers abstract_declarator identifier '=' template_expression_argument    { $$ = MkExpressionTemplateParameter($3, MkTemplateDatatype($1, $2), $5); }
1231    ;
1232
1233 template_parameter:
1234      template_type_parameter
1235    | template_identifier_parameter
1236    | template_expression_parameter
1237    ;
1238
1239 template_parameters_list:
1240      template_parameter                               { $$ = MkList(); ListAdd($$, $1); }
1241    | template_parameters_list ',' template_parameter  { $$ = $1; ListAdd($1, $3); }
1242    ;
1243
1244 template_argument:
1245      template_expression_argument
1246    | template_identifier_argument
1247    | template_type_argument
1248    | identifier '=' template_expression_argument   { $$ = $3; $$.name = $1; $$.loc = @$; }
1249    | identifier '=' template_identifier_argument   { $$ = $3; $$.name = $1; $$.loc = @$; }
1250    | identifier '=' template_type_argument         { $$ = $3; $$.name = $1; $$.loc = @$; }
1251    /*| template_datatype '=' template_expression_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_identifier_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    | template_datatype '=' template_type_argument
1276    {
1277       $$ = $3; 
1278       if($1.specifiers && $1.specifiers->first)
1279       {
1280          Specifier spec = $1.specifiers->first;
1281          if(spec.type == nameSpecifier)
1282             $$.name = MkIdentifier(spec.name);
1283       }
1284       FreeTemplateDataType($1);
1285       $$.loc = @$;
1286    }*/
1287    ;
1288
1289 template_arguments_list:
1290      template_argument                                { $$ = MkList(); ListAdd($$, $1); }
1291    | template_arguments_list ',' template_argument    { $$ = $1; ListAdd($1, $3); }
1292    ;
1293
1294 class_entry:
1295    CLASS
1296    {
1297       if(curContext != globalContext)
1298          PopContext(curContext);
1299       $$ = PushContext();
1300    };
1301
1302 class_decl:
1303      class_entry identifier { $1; $$ = DeclClassAddNameSpace(globalContext.nextID++, $2.string); FreeIdentifier($2); $$.nameLoc = @2; memberAccessStack[++defaultMemberAccess] = privateAccess; }
1304    | class_entry base_strict_type 
1305    { 
1306       $1; $$ = DeclClass(globalContext.nextID++, $2.name); 
1307       $$.nameLoc = @2; 
1308       FreeSpecifier($2); 
1309       ++defaultMemberAccess;
1310       memberAccessStack[defaultMemberAccess] = privateAccess;
1311    }
1312    | identifier class_entry identifier { $2; $$ = DeclClassAddNameSpace(globalContext.nextID++, $3.string); FreeIdentifier($1); FreeIdentifier($3); $$.nameLoc = @3; $$.isRemote = true; memberAccessStack[++defaultMemberAccess] = privateAccess; }
1313    | identifier class_entry base_strict_type { $2; $$ = DeclClass(globalContext.nextID++, $3.name); FreeIdentifier($1); $$.nameLoc = @3; $$.isRemote = true; FreeSpecifier($3); memberAccessStack[++defaultMemberAccess] = privateAccess; }
1314
1315    | class_entry identifier '<' template_parameters_list '>' { $1; $$ = DeclClassAddNameSpace(globalContext.nextID++, $2.string); $$.templateParams = $4; FreeIdentifier($2); $$.nameLoc = @2; memberAccessStack[++defaultMemberAccess] = privateAccess; }
1316    | class_entry base_strict_type '<' template_parameters_list '>' 
1317    { 
1318       $1; $$ = DeclClass(globalContext.nextID++, $2.name);
1319       $$.templateParams = $4; 
1320       $$.nameLoc = @2; 
1321       FreeSpecifier($2); 
1322       ++defaultMemberAccess;
1323       memberAccessStack[defaultMemberAccess] = privateAccess;
1324    }
1325    | 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; }
1326    | 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; }
1327
1328    ;
1329
1330 class:
1331      class_error '}'
1332       {
1333          $$.loc = @$;
1334          $$ = $1; 
1335       }
1336
1337    // Added this for unit classes...
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_decl '{' '}'
1346       {
1347          $$ = MkClass($1, null, MkList()); $$.blockStart = @2;  $$.loc = @$; $$.endid = globalContext.nextID++;
1348          POP_DEFAULT_ACCESS
1349          PopContext(curContext);
1350       }
1351         | class_head '{' '}'
1352       {
1353          $$ = $1; $$.definitions = MkList(); $$.blockStart = @2;  $$.loc = @$; $$.endid = globalContext.nextID++;
1354          POP_DEFAULT_ACCESS
1355          PopContext(curContext);
1356       }
1357
1358         | class_entry identifier ';'
1359       {
1360          $1; $$ = MkClass(DeclClassAddNameSpace(0, $2.string), null, null); FreeIdentifier($2);
1361          POP_DEFAULT_ACCESS
1362          PopContext(curContext);
1363       }
1364         | class_entry type ';'
1365       {
1366          $1; $$ = MkClass(DeclClass(0, $2.name), null, null); FreeSpecifier($2);
1367          POP_DEFAULT_ACCESS
1368          PopContext(curContext);
1369       }
1370    ;
1371
1372 class_head:
1373         class_decl ':' inheritance_specifiers
1374       {
1375          $$ = MkClass($1, $3, null);
1376       }
1377    ;
1378
1379 class_error:
1380          class_decl '{' struct_declaration_list_error 
1381       {
1382          $$ = MkClass($1, null, $3); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2; $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1383          POP_DEFAULT_ACCESS
1384          PopContext(curContext);
1385       }
1386         | class_head '{' struct_declaration_list_error 
1387       {
1388          $$ = $1; $$.definitions = $3; $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1389          POP_DEFAULT_ACCESS
1390          PopContext(curContext);
1391       }
1392         | class_decl '{' struct_declaration_list
1393       {
1394          $$ = MkClass($1, null, $3); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2; $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1395          POP_DEFAULT_ACCESS
1396          PopContext(curContext);
1397       }
1398         | class_head '{' struct_declaration_list
1399       {
1400          $$ = $1; $$.definitions = $3; $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1401          POP_DEFAULT_ACCESS
1402          PopContext(curContext);
1403       }
1404         | class_decl '{' error
1405       {
1406          $$ = MkClass($1, null, MkList()); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1407          POP_DEFAULT_ACCESS
1408          PopContext(curContext);
1409       }
1410         | class_head '{' error
1411       {
1412          $$ = $1; $$.definitions = MkList(); $$.deleteWatchable = deleteWatchable; deleteWatchable = false; $$.blockStart = @2;  $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; $$.endid = globalContext.nextID++;
1413          POP_DEFAULT_ACCESS
1414          PopContext(curContext);
1415       }
1416    ;
1417
1418 /**** EXPRESSIONS ********************************************************************/
1419
1420 identifier:
1421    IDENTIFIER
1422       { $$ = MkIdentifier(yytext); $$.loc = @1; }
1423    ;
1424
1425 primary_expression:
1426      simple_primary_expression
1427         | '(' expression ')'
1428       { $$ = MkExpBrackets($2); $$.loc = @$; }
1429    ;
1430
1431 i18n_string:
1432           string_literal     { $$ = MkExpString($1); delete $1; $$.loc = @$; }
1433    | '$' string_literal     { $$ = MkExpIntlString($2, null); delete $2; $$.loc = @$; }
1434    | '$' string_literal '.' string_literal     { $$ = MkExpIntlString($4, $2); delete $2; delete $4; $$.loc = @$; }
1435    ;
1436
1437 simple_primary_expression:
1438           identifier         { $$ = MkExpIdentifier($1); $$.loc = @$; }
1439    | instantiation_unnamed      { $$ = MkExpInstance($1); $$.loc = @$; }
1440    | EXTENSION '(' compound_statement ')'    { $$ = MkExpExtensionCompound($3); $$.loc = @$; }
1441    | EXTENSION '(' expression ')'    { $$ = MkExpExtensionExpression($3); $$.loc = @$; }
1442    | EXTENSION '(' type_name ')' initializer     { $$ = MkExpExtensionInitializer($3, $5); $$.loc = @$; }
1443    | EXTENSION '(' type_name ')' '(' type_name ')' initializer     { $$ = MkExpExtensionInitializer($3, MkInitializerAssignment(MkExpExtensionInitializer($6, $8))); $$.loc = @$; }
1444         | CONSTANT           { $$ = MkExpConstant(yytext); $$.loc = @$; }
1445    | i18n_string
1446    | '(' ')' { Expression exp = MkExpDummy(); exp.loc.start = @1.end; exp.loc.end = @2.start; $$ = MkExpBrackets(MkListOne(exp)); $$.loc = @$; yyerror(); }
1447    | NEWOP new_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpNew(MkTypeName($2,$3), $5); $$.loc = @$; }
1448    | NEWOP new_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpNew(MkTypeName($2,$3), $5); $$.loc = @$; }
1449    | NEWOP new_specifiers '[' constant_expression ']' { $$ = MkExpNew(MkTypeName($2,null), $4); $$.loc = @$; }
1450    | NEWOP new_specifiers '[' constant_expression_error ']' { $$ = MkExpNew(MkTypeName($2,null), $4); $$.loc = @$; }
1451    | NEW0OP new_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpNew0(MkTypeName($2,$3), $5); $$.loc = @$; }
1452    | NEW0OP new_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpNew0(MkTypeName($2,$3), $5); $$.loc = @$; }
1453    | NEW0OP new_specifiers '[' constant_expression ']' { $$ = MkExpNew0(MkTypeName($2,null), $4); $$.loc = @$; }
1454    | NEW0OP new_specifiers '[' constant_expression_error ']' { $$ = MkExpNew0(MkTypeName($2,null), $4); $$.loc = @$; }
1455    | RENEW constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpRenew($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1456    | RENEW constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpRenew($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1457    | RENEW constant_expression renew_specifiers '[' constant_expression ']' { $$ = MkExpRenew($2, MkTypeName($3,null), $5); $$.loc = @$; }
1458    | RENEW constant_expression renew_specifiers '[' constant_expression_error ']' { $$ = MkExpRenew($2, MkTypeName($3,null), $5); $$.loc = @$; }
1459    | RENEW0 constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpRenew0($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1460    | RENEW0 constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression_error ']' { $$ = MkExpRenew0($2, MkTypeName($3,$4), $6); $$.loc = @$; }
1461    | RENEW0 constant_expression renew_specifiers '[' constant_expression ']' { $$ = MkExpRenew0($2, MkTypeName($3,null), $5); $$.loc = @$; }
1462    | RENEW0 constant_expression renew_specifiers '[' constant_expression_error ']' { $$ = MkExpRenew0($2, MkTypeName($3,null), $5); $$.loc = @$; }
1463    | CLASS '(' declaration_specifiers ')' { $$ = MkExpClass($3, null); $$.loc = @$; }
1464    | CLASS '(' declaration_specifiers abstract_declarator ')' { $$ = MkExpClass($3, $4); $$.loc = @$; }
1465    | CLASS '(' identifier ')' { $$ = MkExpClass(MkListOne(MkSpecifierName($3.string)), null); FreeIdentifier($3); $$.loc = @$; }
1466    | VAARG '(' assignment_expression ',' type_name ')' { $$ = MkExpVaArg($3, $5); $$.loc = @$; }
1467    
1468    | CLASS_DATA '(' identifier ')' { $$ = MkExpClassData($3); $$.loc = @$; }
1469    | database_open
1470    | dbfield
1471    | dbindex
1472    | dbtable
1473
1474    | '[' argument_expression_list /*expression*/ ']' { $$ = MkExpArray($2); $$.loc = @$; }
1475    ;
1476
1477 anon_instantiation_expression:
1478    instantiation_anon            { $$ = MkExpInstance($1); $$.loc = @$; }
1479    ;
1480
1481 anon_instantiation_expression_error:
1482    instantiation_anon_error error           { $$ = MkExpInstance($1); $$.loc = @$; }
1483    ;
1484
1485 primary_expression_error:
1486           '(' expression  { $$ = MkExpBrackets($2); $$.loc = @$; }
1487    | '(' expression_error { $$ = MkExpBrackets($2); $$.loc = @$; }
1488    ;
1489
1490 postfix_expression:
1491           primary_expression
1492
1493    | postfix_expression '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1494    | postfix_expression '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1495         | postfix_expression '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1496         | postfix_expression '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; }
1497    | 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; }
1498         | postfix_expression '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1499         | postfix_expression PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1500         | postfix_expression INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1501         | postfix_expression DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1502
1503    | postfix_expression_error '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1504    | postfix_expression_error '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1505         | postfix_expression_error '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1506         | postfix_expression_error '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end;$$.loc = @$; }
1507         | postfix_expression_error '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1508         | postfix_expression_error PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1509         | postfix_expression_error INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1510         | postfix_expression_error DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1511 ;
1512
1513 simple_postfix_expression:
1514           simple_primary_expression
1515
1516    | simple_postfix_expression '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1517    | simple_postfix_expression '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1518         | simple_postfix_expression '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1519         | simple_postfix_expression '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; }
1520    | 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; }
1521         | simple_postfix_expression '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1522         | simple_postfix_expression PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1523         | simple_postfix_expression INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1524         | simple_postfix_expression DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1525
1526    | simple_postfix_expression_error '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1527    | simple_postfix_expression_error '[' expression_error ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
1528         | simple_postfix_expression_error '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
1529         | simple_postfix_expression_error '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end;$$.loc = @$; }
1530         | simple_postfix_expression_error '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
1531         | simple_postfix_expression_error PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
1532         | simple_postfix_expression_error INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
1533         | simple_postfix_expression_error DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
1534 ;
1535
1536 argument_expression_list:
1537           assignment_expression          { $$ = MkList(); ListAdd($$, $1); }
1538    | anon_instantiation_expression  { $$ = MkList(); ListAdd($$, $1); }
1539         | argument_expression_list ',' assignment_expression   { $$ = $1; ListAdd($1, $3);  }
1540    | argument_expression_list ',' anon_instantiation_expression   { $$ = $1; ListAdd($1, $3);  }
1541         ;
1542
1543 argument_expression_list_error:
1544      assignment_expression_error    { $$ = MkList(); ListAdd($$, $1); }
1545    | anon_instantiation_expression_error    { $$ = MkList(); ListAdd($$, $1); }
1546    | argument_expression_list ',' assignment_expression_error  { $$ = $1; ListAdd($1, $3);  }
1547    | argument_expression_list ',' anon_instantiation_expression_error  { $$ = $1; ListAdd($1, $3);  }
1548    | argument_expression_list ',' { Expression exp = MkExpDummy(); exp.loc.start = @2.end; exp.loc.end = @2.end; $$ = $1; ListAdd($1, exp); }
1549         ;
1550
1551 common_unary_expression:
1552           INC_OP unary_expression           { $$ = MkExpOp(null, INC_OP, $2); $$.loc = @$; }
1553         | DEC_OP unary_expression           { $$ = MkExpOp(null, DEC_OP, $2); $$.loc = @$; }
1554         | unary_operator cast_expression    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1555    | unary_operator anon_instantiation_expression    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1556         | SIZEOF '(' unary_expression ')'         { $$ = MkExpOp(null, SIZEOF, $3); $$.loc = @$; }
1557    | SIZEOF simple_unary_expression           { $$ = MkExpOp(null, SIZEOF, $2); $$.loc = @$; }
1558    | SIZEOF '(' guess_type_name ')'          { $$ = MkExpTypeSize($3); $$.loc = @$; }
1559    | SIZEOF '(' CLASS type ')'          { $$ = MkExpClassSize($4); $$.loc = @$; }
1560    | SIZEOF '(' CLASS guess_type ')'          { $$ = MkExpClassSize($4); $$.loc = @$; }
1561
1562         | ALIGNOF '(' unary_expression ')'         { $$ = MkExpOp(null, ALIGNOF, $3); $$.loc = @$; }
1563    | ALIGNOF simple_unary_expression           { $$ = MkExpOp(null, ALIGNOF, $2); $$.loc = @$; }
1564    | ALIGNOF '(' guess_type_name ')'          { $$ = MkExpTypeAlign($3); $$.loc = @$; }
1565         ;
1566
1567 unary_expression:
1568        common_unary_expression
1569           | postfix_expression
1570         ;
1571
1572 simple_unary_expression:
1573      common_unary_expression
1574         | simple_postfix_expression
1575         ;
1576
1577 unary_operator:
1578           '&'     { $$ = '&'; }
1579         | '*'     { $$ = '*'; }
1580         | '+'     { $$ = '+'; }
1581         | '-'     { $$ = '-'; }
1582         | '~'     { $$ = '~'; }
1583         | '!'     { $$ = '!'; }
1584    | DELETE  { $$ = DELETE; }
1585    | _INCREF  { $$ = _INCREF; }
1586         ;
1587
1588 cast_expression:
1589        unary_expression
1590         | '(' type_name ')' cast_expression    { $$ = MkExpCast($2, $4); $$.loc = @$; }
1591         ;
1592
1593 multiplicative_expression:
1594           cast_expression
1595         | multiplicative_expression '*' cast_expression { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
1596         | multiplicative_expression '/' cast_expression { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
1597         | multiplicative_expression '%' cast_expression { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
1598         | multiplicative_expression_error '*' cast_expression { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
1599         | multiplicative_expression_error '/' cast_expression { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
1600         | multiplicative_expression_error '%' cast_expression { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
1601         ;
1602
1603 additive_expression:
1604           multiplicative_expression
1605         | additive_expression '+' multiplicative_expression  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
1606         | additive_expression '-' multiplicative_expression  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
1607         | additive_expression_error '+' multiplicative_expression  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
1608         | additive_expression_error '-' multiplicative_expression  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
1609         ;
1610
1611 shift_expression:
1612           additive_expression
1613         | shift_expression LEFT_OP additive_expression  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
1614         | shift_expression RIGHT_OP additive_expression { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
1615         | shift_expression_error LEFT_OP additive_expression  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
1616         | shift_expression_error RIGHT_OP additive_expression { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
1617         ;
1618
1619 relational_expression_smaller_than:
1620    relational_expression '<'
1621    {
1622       $$ = $1;
1623       skipErrors = true;
1624    }
1625    ;
1626
1627 relational_expression:
1628           shift_expression
1629         | relational_expression_smaller_than /*relational_expression '<' */ shift_expression    { skipErrors = false; $$ = MkExpOp($1, '<', $2/*$3*/); $$.loc = @$; }
1630         | relational_expression '>' shift_expression    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
1631         | relational_expression LE_OP shift_expression  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
1632         | relational_expression GE_OP shift_expression  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
1633         | relational_expression_error '<' shift_expression    { $$ = MkExpOp($1, '<', $3); $$.loc = @$; }
1634         | relational_expression_error '>' shift_expression    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
1635         | relational_expression_error LE_OP shift_expression  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
1636         | relational_expression_error GE_OP shift_expression  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
1637         ;
1638
1639 equality_expression
1640         : relational_expression
1641         | equality_expression EQ_OP relational_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1642         | equality_expression NE_OP relational_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1643         | equality_expression_error EQ_OP relational_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1644         | equality_expression_error NE_OP relational_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1645
1646         | equality_expression EQ_OP anon_instantiation_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1647         | equality_expression NE_OP anon_instantiation_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1648         | equality_expression_error EQ_OP anon_instantiation_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1649         | equality_expression_error NE_OP anon_instantiation_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1650         ;
1651
1652 and_expression
1653         : equality_expression
1654         | and_expression '&' equality_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1655         | and_expression_error '&' equality_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1656
1657         | and_expression '&' anon_instantiation_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1658         | and_expression_error '&' anon_instantiation_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1659         ;
1660
1661 exclusive_or_expression
1662         : and_expression
1663         | exclusive_or_expression '^' and_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1664         | exclusive_or_expression_error '^' and_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1665
1666         | exclusive_or_expression '^' anon_instantiation_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1667         | exclusive_or_expression_error '^' anon_instantiation_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1668         ;
1669
1670 inclusive_or_expression
1671         : exclusive_or_expression
1672         | inclusive_or_expression '|' exclusive_or_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1673         | inclusive_or_expression_error '|' exclusive_or_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1674
1675         | inclusive_or_expression '|' anon_instantiation_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1676         | inclusive_or_expression_error '|' anon_instantiation_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1677         ;
1678
1679 logical_and_expression
1680         : inclusive_or_expression
1681         | logical_and_expression AND_OP inclusive_or_expression  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
1682         | logical_and_expression_error AND_OP inclusive_or_expression  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
1683         ;
1684
1685 logical_or_expression
1686         : logical_and_expression
1687         | logical_or_expression OR_OP logical_and_expression     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
1688         | logical_or_expression_error OR_OP logical_and_expression     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
1689         ;
1690
1691 conditional_expression
1692         : logical_or_expression
1693         | logical_or_expression '?' expression ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1694    | logical_or_expression '?' expression_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1695         | logical_or_expression_error '?' expression ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1696    | logical_or_expression_error '?' expression_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1697
1698         | logical_or_expression '?' expression_anon_inst ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1699    | logical_or_expression '?' expression_anon_inst_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1700         | logical_or_expression_error '?' expression_anon_inst ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1701    | logical_or_expression_error '?' expression_anon_inst_error ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1702
1703         | logical_or_expression '?' expression ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1704    | logical_or_expression '?' expression_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1705         | logical_or_expression_error '?' expression ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1706    | logical_or_expression_error '?' expression_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1707
1708         | logical_or_expression '?' expression_anon_inst ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1709    | logical_or_expression '?' expression_anon_inst_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1710         | logical_or_expression_error '?' expression_anon_inst ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1711    | logical_or_expression_error '?' expression_anon_inst_error ':' anon_instantiation_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1712         ;
1713
1714 assignment_expression:
1715           conditional_expression
1716         | unary_expression assignment_operator assignment_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1717    | unary_expression_error assignment_operator assignment_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1718         | conditional_expression assignment_operator assignment_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }           // TODO: Generate error here:
1719    | conditional_expression_error assignment_operator assignment_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }     // TODO: Generate error here:
1720
1721         | unary_expression assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1722    | unary_expression_error assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1723         | conditional_expression assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1724    | conditional_expression_error assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
1725         ;
1726
1727 assignment_operator:
1728           '='                   { $$ = '='; }
1729         | MUL_ASSIGN            { $$ = MUL_ASSIGN; }
1730         | DIV_ASSIGN            { $$ = DIV_ASSIGN; }
1731         | MOD_ASSIGN            { $$ = MOD_ASSIGN; }
1732         | ADD_ASSIGN            { $$ = ADD_ASSIGN; }
1733         | SUB_ASSIGN            { $$ = SUB_ASSIGN; }
1734         | LEFT_ASSIGN           { $$ = LEFT_ASSIGN; }
1735         | RIGHT_ASSIGN          { $$ = RIGHT_ASSIGN; }
1736         | AND_ASSIGN            { $$ = AND_ASSIGN; }
1737         | XOR_ASSIGN            { $$ = XOR_ASSIGN; }
1738         | OR_ASSIGN             { $$ = OR_ASSIGN; }
1739         ;
1740
1741 expression: 
1742    assignment_expression                 { $$ = MkList(); ListAdd($$, $1); }
1743         | expression ',' assignment_expression  { $$ = $1; ListAdd($1, $3); }
1744    | expression_error ',' assignment_expression  { $$ = $1; ListAdd($1, $3); }
1745    | expression_error  ')'
1746         ;
1747
1748 expression_anon_inst: 
1749      anon_instantiation_expression                 { $$ = MkList(); ListAdd($$, $1); }
1750    | expression ',' anon_instantiation_expression  { $$ = $1; ListAdd($1, $3); }
1751         | expression_error ',' anon_instantiation_expression  { $$ = $1; ListAdd($1, $3); }
1752    ;
1753
1754 postfix_expression_error:
1755    primary_expression_error
1756    | error { $$ = MkExpDummy(); $$.loc = @$; /*printf("Sorry, didn't mean that syntax error\n");*/ }
1757    | postfix_expression error
1758    | instantiation_unnamed_error error { $$ = MkExpInstance($1); $$.loc = @$; }
1759
1760    | postfix_expression PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1761    | postfix_expression_error PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1762
1763    | postfix_expression '(' argument_expression_list { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; $$.call.argLoc.end.charPos++;} 
1764         | postfix_expression '(' argument_expression_list_error { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; $$.call.argLoc.end.charPos++;} 
1765    /* Useless rules due to conflicts
1766    | postfix_expression '(' argument_expression_list ',' error { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end;$$.loc = @$; $$.call.argLoc.end.charPos++;}
1767    | postfix_expression '(' error { $$ = MkExpCall($1, MkList() ); @$.end = yylloc.start; $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = yylloc.start; }
1768    */
1769    | postfix_expression '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1770
1771         | 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++;} 
1772    /* Useless rules due to conflicts
1773    | 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++;}
1774    | postfix_expression_error '(' error { $$ = MkExpCall($1, MkList() ); $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @2.end; $$.call.argLoc.end.charPos++;}
1775    */
1776    | postfix_expression_error '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1777         ;
1778
1779 simple_postfix_expression_error:
1780       error { $$ = MkExpDummy(); $$.loc = @$; }
1781    | simple_postfix_expression error
1782    | instantiation_unnamed_error error { $$ = MkExpInstance($1); $$.loc = @$; }
1783
1784    | simple_postfix_expression PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1785    | simple_postfix_expression_error PTR_OP error                { $$ = MkExpPointer($1, null); $$.loc = @$; }
1786
1787    | simple_postfix_expression '(' argument_expression_list { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; $$.call.argLoc.end.charPos++;} 
1788         | 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++;} 
1789    /* Useless rules due to conflicts
1790    | 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++;}
1791    | simple_postfix_expression '(' error { $$ = MkExpCall($1, MkList() ); @$.end = yylloc.start; $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = yylloc.start; }
1792    */
1793    | simple_postfix_expression '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1794
1795         | 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++;}
1796    /* Useless rules due to conflicts
1797    | 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++;}
1798    | simple_postfix_expression_error '(' error { $$ = MkExpCall($1, MkList() ); $$.loc = @$; $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @2.end; $$.call.argLoc.end.charPos++;}
1799    */
1800    | simple_postfix_expression_error '.' error                   { $$ = MkExpMember($1, null); $$.loc = @$; }
1801         ;
1802
1803 common_unary_expression_error:
1804            INC_OP unary_expression_error           { $$ = MkExpOp(null, INC_OP, $2); $$.loc = @$; }
1805          | DEC_OP unary_expression_error           { $$ = MkExpOp(null, DEC_OP, $2); $$.loc = @$; }
1806          | unary_operator cast_expression_error    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1807     | unary_operator anon_instantiation_expression_error    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
1808     | SIZEOF '(' unary_expression_error           { $$ = MkExpOp(null, SIZEOF, $3); $$.loc = @$; }
1809          | SIZEOF simple_unary_expression_error           { $$ = MkExpOp(null, SIZEOF, $2); $$.loc = @$; }
1810          | SIZEOF '(' guess_type_name ')' error          { $$ = MkExpTypeSize($3); $$.loc = @$; }
1811     | SIZEOF '(' CLASS type ')' error   { $$ = MkExpClassSize($4); $$.loc = @$; }
1812     | SIZEOF '(' CLASS guess_type ')' error   { $$ = MkExpClassSize($4); $$.loc = @$; }
1813     | ALIGNOF '(' unary_expression_error           { $$ = MkExpOp(null, ALIGNOF, $3); $$.loc = @$; }
1814          | ALIGNOF simple_unary_expression_error           { $$ = MkExpOp(null, ALIGNOF, $2); $$.loc = @$; }
1815          | ALIGNOF '(' guess_type_name ')' error          { $$ = MkExpTypeAlign($3); $$.loc = @$; }
1816         ;
1817
1818 unary_expression_error:
1819      common_unary_expression_error
1820         | postfix_expression_error
1821    ;
1822
1823 simple_unary_expression_error:
1824      common_unary_expression_error
1825         | simple_postfix_expression_error
1826    ;
1827
1828
1829 cast_expression_error:
1830      unary_expression_error
1831         | '(' type_name ')' cast_expression_error    { $$ = MkExpCast($2, $4); $$.loc = @$; }
1832         ;
1833
1834 multiplicative_expression_error: 
1835      cast_expression_error
1836         | multiplicative_expression '*' cast_expression_error { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
1837         | multiplicative_expression '/' cast_expression_error { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
1838         | multiplicative_expression '%' cast_expression_error { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
1839         | multiplicative_expression_error '*' cast_expression_error { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
1840         | multiplicative_expression_error '/' cast_expression_error { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
1841         | multiplicative_expression_error '%' cast_expression_error { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
1842         ;
1843
1844 additive_expression_error:
1845     multiplicative_expression_error
1846         | additive_expression '+' multiplicative_expression_error  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
1847    /* Useless rules due to conflicts
1848         | additive_expression '+' error { $$ = MkExpOp($1, '+', null); $$.loc = @$; }
1849    */
1850         | additive_expression '-' multiplicative_expression_error  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
1851    /* Useless rules due to conflicts
1852    | additive_expression '-' error { $$ = MkExpOp($1, '-', null); $$.loc = @$; }
1853    */
1854         | additive_expression_error '+' multiplicative_expression_error  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
1855    /* Useless rules due to conflicts
1856         | additive_expression_error '+' error { $$ = MkExpOp($1, '+', null); $$.loc = @$; }
1857    */
1858         | additive_expression_error '-' multiplicative_expression_error  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
1859    /* Useless rules due to conflicts
1860    | additive_expression_error '-' error { $$ = MkExpOp($1, '-', null); $$.loc = @$; }
1861    */
1862         ;
1863
1864 shift_expression_error:
1865      additive_expression_error
1866         | shift_expression LEFT_OP additive_expression_error  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
1867         | shift_expression RIGHT_OP additive_expression_error { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
1868         | shift_expression_error LEFT_OP additive_expression_error  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
1869         | shift_expression_error RIGHT_OP additive_expression_error { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
1870         ;
1871
1872 relational_expression_error:
1873      shift_expression_error
1874         | relational_expression_smaller_than /*relational_expression '<' */ shift_expression_error
1875    {
1876       if($1.type == identifierExp)
1877       {
1878          if($1.identifier._class && !$1.identifier._class.name)
1879          {
1880             char name[1024];
1881             strcpy(name, "::");
1882             strcat(name, $1.identifier.string);
1883             _DeclClass(0, name);
1884          }
1885          else
1886             _DeclClass(0, $1.identifier.string);
1887
1888          // printf("Declaring Class %s\n", $1.identifier.string);
1889          skipErrors = false;
1890
1891          FreeExpression($1);
1892          FreeExpression($2);
1893          
1894          fileInput.Seek(@1.start.pos, start); 
1895          resetScannerPos(&@1.start);
1896          yyclearin;
1897
1898          YYPOPSTACK(1);
1899          yystate = *yyssp;
1900          YY_STACK_PRINT (yyss, yyssp);
1901
1902          YYPOPSTACK(1);
1903          yystate = *yyssp;
1904          YY_STACK_PRINT (yyss, yyssp);
1905 /*         
1906          YYPOPSTACK(1);
1907          yystate = *yyssp;
1908          YY_STACK_PRINT (yyss, yyssp);
1909
1910          YYPOPSTACK(1);
1911          yystate = *yyssp;
1912          YY_STACK_PRINT (yyss, yyssp);
1913 */
1914          yyerrok;
1915
1916          goto yysetstate;
1917       }
1918       else
1919       {
1920          $$ = MkExpOp($1, '<', $2);
1921          $$.loc = @$;
1922       } 
1923       skipErrors = false;
1924    }
1925         | relational_expression '>' shift_expression_error    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
1926         | relational_expression LE_OP shift_expression_error  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
1927         | relational_expression GE_OP shift_expression_error  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
1928         | relational_expression_error '<' shift_expression_error    { $$ = MkExpOp($1, '<', $3); $$.loc = @$; }
1929         | relational_expression_error '>' shift_expression_error    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
1930         | relational_expression_error LE_OP shift_expression_error  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
1931         | relational_expression_error GE_OP shift_expression_error  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
1932         ;
1933
1934 equality_expression_error:
1935        relational_expression_error
1936      | equality_expression EQ_OP relational_expression_error  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1937           | equality_expression NE_OP relational_expression_error  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1938      | equality_expression_error EQ_OP relational_expression_error  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1939           | equality_expression_error NE_OP relational_expression_error  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1940      /* Useless rules due to conflicts
1941      | equality_expression EQ_OP error        { $$ = MkExpOp($1, EQ_OP, MkExpDummy()); $$.loc = @$; }
1942           | equality_expression NE_OP error        { $$ = MkExpOp($1, NE_OP, MkExpDummy()); $$.loc = @$; }
1943      | equality_expression_error EQ_OP error  { $$ = MkExpOp($1, EQ_OP, MkExpDummy()); $$.loc = @$; }
1944           | equality_expression_error NE_OP error  { $$ = MkExpOp($1, NE_OP, MkExpDummy()); $$.loc = @$; }
1945      */
1946      | equality_expression EQ_OP anon_instantiation_expression_error  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1947           | equality_expression NE_OP anon_instantiation_expression_error  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1948      | equality_expression_error EQ_OP anon_instantiation_expression_error  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
1949           | equality_expression_error NE_OP anon_instantiation_expression_error  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
1950         ;
1951
1952 and_expression_error:
1953    equality_expression_error
1954         | and_expression '&' equality_expression_error  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1955    | and_expression_error '&' equality_expression_error  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1956
1957         | and_expression '&' anon_instantiation_expression_error  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1958    | and_expression_error '&' anon_instantiation_expression_error  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
1959         ;
1960
1961 exclusive_or_expression_error:
1962    and_expression_error
1963         | exclusive_or_expression '^' and_expression_error { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1964    | exclusive_or_expression_error '^' and_expression_error { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1965
1966         | exclusive_or_expression '^' anon_instantiation_expression_error { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1967    | exclusive_or_expression_error '^' anon_instantiation_expression_error { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
1968         ;
1969
1970 inclusive_or_expression_error:
1971      exclusive_or_expression_error
1972         | inclusive_or_expression '|' exclusive_or_expression_error { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1973    | inclusive_or_expression_error '|' exclusive_or_expression_error { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1974
1975         | inclusive_or_expression '|' anon_instantiation_expression_error { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1976    | inclusive_or_expression_error '|' anon_instantiation_expression_error { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
1977         ;
1978
1979 logical_and_expression_error:
1980    inclusive_or_expression_error
1981         | logical_and_expression AND_OP inclusive_or_expression_error  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
1982    | logical_and_expression_error AND_OP inclusive_or_expression_error  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
1983         ;
1984
1985 logical_or_expression_error:
1986      logical_and_expression_error
1987    | logical_or_expression OR_OP logical_and_expression_error     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
1988         | logical_or_expression_error OR_OP logical_and_expression_error     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
1989         ;
1990
1991 conditional_expression_error:
1992     logical_or_expression_error
1993         | logical_or_expression '?' expression ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1994    | logical_or_expression '?' expression_error ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1995         | logical_or_expression_error '?' expression ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1996    | logical_or_expression_error '?' expression_error ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
1997         | logical_or_expression '?' expression ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
1998    | logical_or_expression '?' expression_error ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
1999         | logical_or_expression_error '?' expression ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
2000    | logical_or_expression_error '?' expression_error ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
2001
2002         | logical_or_expression '?' expression_anon_inst ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2003    | logical_or_expression '?' expression_anon_inst_error ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2004         | logical_or_expression_error '?' expression_anon_inst ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2005    | logical_or_expression_error '?' expression_anon_inst_error ':' logical_or_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2006         | logical_or_expression '?' expression_anon_inst ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
2007    | logical_or_expression '?' expression_anon_inst_error ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
2008         | logical_or_expression_error '?' expression_anon_inst ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
2009    | logical_or_expression_error '?' expression_anon_inst_error ':' { $$ = MkExpCondition($1, $3, MkExpDummy()); $$.loc = @$; $$.cond.elseExp.loc = @3; }
2010
2011         | logical_or_expression '?' expression ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2012    | logical_or_expression '?' expression_error ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2013         | logical_or_expression_error '?' expression ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2014    | logical_or_expression_error '?' expression_error ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2015
2016         | logical_or_expression '?' expression_anon_inst ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2017    | logical_or_expression '?' expression_anon_inst_error ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2018         | logical_or_expression_error '?' expression_anon_inst ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2019    | logical_or_expression_error '?' expression_anon_inst_error ':' anon_instantiation_expression_error { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
2020
2021         | logical_or_expression '?' ':' 
2022       { 
2023          $$ = MkExpCondition($1, MkListOne(MkExpDummy()), MkExpDummy()); 
2024          $$.loc = @$; 
2025          ((Expression)$$.cond.exp->last).loc = @2; 
2026          $$.cond.elseExp.loc = @3; 
2027       }
2028    | logical_or_expression_error '?' ':'
2029       {
2030          $$ = MkExpCondition($1, MkListOne(MkExpDummy()), MkExpDummy()); $$.loc = @$; ((Expression)$$.cond.exp->last).loc = @2; $$.cond.elseExp.loc = @3;
2031       }
2032    | logical_or_expression '?'
2033       {
2034          $$ = MkExpCondition($1, MkListOne(MkExpDummy()), MkExpDummy()); $$.loc = @$; ((Expression)$$.cond.exp->last).loc = @2; $$.cond.elseExp.loc = @2;
2035       }
2036    | logical_or_expression_error '?'
2037       {
2038          $$ = MkExpCondition($1, MkListOne(MkExpDummy()), MkExpDummy()); $$.loc = @$; ((Expression)$$.cond.exp->last).loc = @2; $$.cond.elseExp.loc = @2;
2039       }
2040    ;
2041
2042 assignment_expression_error:
2043      conditional_expression_error
2044    | unary_expression assignment_operator assignment_expression_error   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
2045    /* Useless rules due to conflicts
2046    | unary_expression assignment_operator error   { $$ = MkExpOp($1, $2, MkExpDummy()); $$.loc = @$; $$.op.exp2.loc = @2; }
2047    */
2048    | unary_expression_error assignment_operator assignment_expression_error   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
2049    /* Useless rules due to conflicts
2050    | unary_expression_error assignment_operator error   { $$ = MkExpOp($1, $2, MkExpDummy()); $$.loc = @$; $$.op.exp2.loc = @2; }
2051    */
2052
2053    | unary_expression assignment_operator anon_instantiation_expression_error   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
2054    | unary_expression_error assignment_operator anon_instantiation_expression_error   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
2055         ;
2056
2057 expression_error: 
2058      assignment_expression_error                 { $$ = MkList(); ListAdd($$, $1); }
2059    | assignment_expression error                 { $$ = MkList(); ListAdd($$, $1); }
2060    | expression ',' assignment_expression_error  { $$ = $1; ListAdd($1, $3); }
2061         | expression_error ',' assignment_expression_error  { $$ = $1; ListAdd($1, $3); }
2062    /* Useless rules due to conflicts
2063    | expression ',' error 
2064    | expression_error ',' error 
2065    | expression error
2066    */
2067    | expression expression                      { $$ = $1; FreeList($2, FreeExpression); }
2068    | expression_error expression                { $$ = $1; FreeList($2, FreeExpression); }
2069    | expression expression_error                { $$ = $1; FreeList($2, FreeExpression); }
2070    ;
2071
2072 expression_anon_inst_error: 
2073      anon_instantiation_expression_error                 { $$ = MkList(); ListAdd($$, $1); }
2074    | anon_instantiation_expression error                 { $$ = MkList(); ListAdd($$, $1); }
2075    | expression ',' anon_instantiation_expression_error  { $$ = $1; ListAdd($1, $3); }
2076         | expression_error ',' anon_instantiation_expression_error  { $$ = $1; ListAdd($1, $3); }
2077    ;
2078
2079
2080 constant_expression: conditional_expression;
2081
2082 constant_expression_error: conditional_expression_error;
2083
2084 /**** TYPES **************************************************************************/
2085 storage_class_specifier:
2086           TYPEDEF       { $$ = MkSpecifier(TYPEDEF); }
2087         | EXTERN        { $$ = MkSpecifier(EXTERN); }
2088         | STATIC        { $$ = MkSpecifier(STATIC); }
2089         | AUTO          { $$ = MkSpecifier(AUTO); }
2090         | REGISTER      { $$ = MkSpecifier(REGISTER); }
2091         ;
2092
2093 external_storage_class_specifier:
2094           TYPEDEF       { $$ = MkSpecifier(TYPEDEF); declMode = defaultAccess; }
2095         | EXTERN        { $$ = MkSpecifier(EXTERN); }
2096         | STATIC        { $$ = MkSpecifier(STATIC); declMode = staticAccess; }
2097         | AUTO          { $$ = MkSpecifier(AUTO); }
2098         | REGISTER      { $$ = MkSpecifier(REGISTER); }
2099         ;
2100
2101 enumerator:
2102           identifier                           { $$ = MkEnumerator($1, null); }
2103         | identifier '=' constant_expression   { $$ = MkEnumerator($1, $3); }
2104    | identifier '=' constant_expression_error   { $$ = MkEnumerator($1, $3); }
2105         ;
2106
2107 enumerator_list:
2108           enumerator                        { $$ = MkList(); ListAdd($$, $1); }
2109         | enumerator_list ',' enumerator    { $$ = $1; ListAdd($1, $3); }
2110    | enumerator_list ','
2111         ;
2112
2113 enum_specifier:
2114      ENUM  { memberAccessStack[++defaultMemberAccess] = publicAccess; }
2115    ;
2116
2117 enum_specifier_nocompound:
2118      enum_specifier identifier                            { $$ = MkEnum($2, null); POP_DEFAULT_ACCESS }
2119    | enum_specifier strict_type                           { $$ = MkEnum(MkIdentifier($2.name), null); POP_DEFAULT_ACCESS }
2120    ;
2121
2122 enum_specifier_compound:
2123           enum_specifier_compound_error '}' { $$.loc = @$; POP_DEFAULT_ACCESS $$ = $1; }
2124         | enum_specifier identifier '{' '}'    { $$ = MkEnum($2, null); $$.loc = @$; POP_DEFAULT_ACCESS }
2125    | enum_specifier strict_type '{' '}'          { $$ = MkEnum(MkIdentifier($2.name), null); FreeSpecifier($2); $$.loc = @$; POP_DEFAULT_ACCESS }
2126         ;
2127
2128 enum_specifier_compound_error:
2129           enum_specifier '{' enumerator_list       { $$ = MkEnum(null, $3); $$.loc = @$; POP_DEFAULT_ACCESS }
2130    | enum_specifier '{' error                 { $$ = MkEnum(null, null); $$.loc = @$; POP_DEFAULT_ACCESS }
2131
2132         | enum_specifier identifier '{' enumerator_list          { $$ = MkEnum($2, $4); $$.loc = @$; POP_DEFAULT_ACCESS }
2133    | enum_specifier identifier '{' enumerator_list error    { $$ = MkEnum($2, $4);  $$.loc = @$; POP_DEFAULT_ACCESS }
2134    | enum_specifier identifier '{' error    { $$ = MkEnum($2, null);  $$.loc = @$; POP_DEFAULT_ACCESS }
2135    | enum_specifier identifier '{' enumerator_list ';' struct_declaration_list     { $$ = MkEnum($2, $4); $$.loc = @$; $$.definitions = $6;  POP_DEFAULT_ACCESS }
2136    | enum_specifier identifier '{' enumerator_list ';' struct_declaration_list_error     { $$ = MkEnum($2, $4); $$.loc = @$; $$.definitions = $6;  POP_DEFAULT_ACCESS }
2137
2138    | enum_specifier strict_type '{' enumerator_list           { $$ = MkEnum(MkIdentifier($2.name), $4); $$.loc = @$; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2139    | enum_specifier strict_type '{' enumerator_list error          { $$ = MkEnum(MkIdentifier($2.name), $4); $$.loc = @$; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2140    | enum_specifier strict_type '{' error                          { $$ = MkEnum(MkIdentifier($2.name), null); $$.loc = @$; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2141         | enum_specifier strict_type '{' enumerator_list ';' struct_declaration_list           { $$ = MkEnum(MkIdentifier($2.name), $4); $$.loc = @$; $$.definitions = $6; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2142         | enum_specifier strict_type '{' enumerator_list ';' struct_declaration_list_error           { $$ = MkEnum(MkIdentifier($2.name), $4); $$.loc = @$; $$.definitions = $6; FreeSpecifier($2); POP_DEFAULT_ACCESS }
2143         ;
2144
2145 enum_decl:
2146      enum_specifier identifier  { $$ = $2; if(declMode) DeclClassAddNameSpace(globalContext.nextID++, $2.string); }
2147    | enum_specifier strict_type { $$ = MkIdentifier($2.name); if(declMode) DeclClass(globalContext.nextID++, $2.name); FreeSpecifier($2); }
2148    ;
2149
2150 enum_class:
2151      enum_class_error '}'  { $$ = $1; $$.loc = @$; }
2152    | enum_decl ':' inheritance_specifiers '{' '}' { $$ = MkEnum($1, null); $$.baseSpecs = $3; $$.loc = @$; POP_DEFAULT_ACCESS }
2153    | enum_decl '{' '}'    { $$ = MkEnum($1, null); POP_DEFAULT_ACCESS }
2154    ;
2155
2156 enum_class_error:
2157      enum_decl ':' inheritance_specifiers '{' enumerator_list           { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.loc = @$; POP_DEFAULT_ACCESS }
2158    | enum_decl ':' inheritance_specifiers '{' enumerator_list error          { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.loc = @$; POP_DEFAULT_ACCESS }
2159    | enum_decl ':' inheritance_specifiers '{' error          { $$ = MkEnum($1, null); $$.baseSpecs = $3; $$.loc = @$; POP_DEFAULT_ACCESS }
2160    | enum_decl ':' inheritance_specifiers '{' enumerator_list ';' struct_declaration_list           { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.definitions = $7; $$.loc = @$; POP_DEFAULT_ACCESS }
2161    | enum_decl ':' inheritance_specifiers '{' enumerator_list ';' struct_declaration_list_error           { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.definitions = $7; $$.loc = @$; POP_DEFAULT_ACCESS }
2162    | enum_decl ':' inheritance_specifiers '{' enumerator_list error ';' struct_declaration_list           { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.definitions = $8; $$.loc = @$; POP_DEFAULT_ACCESS }
2163    | enum_decl ':' inheritance_specifiers '{' enumerator_list error ';' struct_declaration_list_error           { $$ = MkEnum($1, $5); $$.baseSpecs = $3; $$.definitions = $8; $$.loc = @$; POP_DEFAULT_ACCESS }
2164    | enum_decl ':' inheritance_specifiers '{' error ';' struct_declaration_list           { $$ = MkEnum($1, null); $$.baseSpecs = $3; $$.definitions = $7; $$.loc = @$; POP_DEFAULT_ACCESS }
2165    | enum_decl ':' inheritance_specifiers '{' error ';' struct_declaration_list_error           { $$ = MkEnum($1, null); $$.baseSpecs = $3; $$.definitions = $7; $$.loc = @$; POP_DEFAULT_ACCESS }
2166
2167         | enum_specifier '{' enumerator_list       { $$ = MkEnum(null, $3); $$.loc = @$; POP_DEFAULT_ACCESS }
2168    | enum_specifier '{' error                 { $$ = MkEnum(null, null); $$.loc = @$; POP_DEFAULT_ACCESS }
2169
2170         | enum_decl '{' enumerator_list          { $$ = MkEnum($1, $3); $$.loc = @$; POP_DEFAULT_ACCESS }
2171    | enum_decl '{' enumerator_list error    { $$ = MkEnum($1, $3); $$.loc = @$; POP_DEFAULT_ACCESS }
2172    | enum_decl '{' error    { $$ = MkEnum($1, null); $$.loc = @$; POP_DEFAULT_ACCESS }
2173    | enum_decl '{' enumerator_list ';' struct_declaration_list     { $$ = MkEnum($1, $3); $$.definitions = $5; $$.loc = @$; POP_DEFAULT_ACCESS }
2174    | enum_decl '{' enumerator_list ';' struct_declaration_list_error     { $$ = MkEnum($1, $3); $$.definitions = $5; $$.loc = @$; POP_DEFAULT_ACCESS }
2175    ;
2176
2177 class_specifier:
2178      enum_class
2179    | struct_class
2180    ;
2181
2182 class_specifier_error:
2183      enum_class_error
2184    | struct_class_error
2185    ;
2186
2187 ext_storage:
2188    ext_decl   { $$ = MkSpecifierExtended($1); }
2189    ;
2190
2191 type_qualifier:
2192           CONST        { $$ = MkSpecifier(CONST); }
2193         | VOLATILE     { $$ = MkSpecifier(VOLATILE); }
2194    | ext_storage  { $$ = $1; }
2195         ;
2196
2197
2198 type_qualifier_list:
2199           type_qualifier                          { $$ = MkList(); ListAdd($$, $1); }
2200         | type_qualifier_list type_qualifier      { $$ = $1; ListAdd($1, $2);  }
2201         ;
2202
2203 type_specifier:
2204           VOID            { $$ = MkSpecifier(VOID); }  
2205         | CHAR            { $$ = MkSpecifier(CHAR); }
2206         | SHORT           { $$ = MkSpecifier(SHORT); }
2207         | INT             { $$ = MkSpecifier(INT); }
2208    | UINT            { $$ = MkSpecifier(UINT); }
2209    | INT64           { $$ = MkSpecifier(INT64); }
2210    | VALIST          { $$ = MkSpecifier(VALIST); }
2211         | LONG            { $$ = MkSpecifier(LONG); }
2212         | FLOAT           { $$ = MkSpecifier(FLOAT); }
2213         | DOUBLE          { $$ = MkSpecifier(DOUBLE); }
2214         | SIGNED          { $$ = MkSpecifier(SIGNED); }
2215         | UNSIGNED        { $$ = MkSpecifier(UNSIGNED); }
2216    | EXTENSION       { $$ = MkSpecifier(EXTENSION); }
2217         | struct_or_union_specifier_nocompound
2218         | enum_specifier_nocompound
2219         | type
2220    | TYPEOF '(' assignment_expression ')' { $$ = MkSpecifierTypeOf($3); }
2221    | SUBCLASS '(' type ')'                { $$ = MkSpecifierSubClass($3); }
2222    | SUBCLASS '(' identifier ')'          { _DeclClass(0, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
2223    | THISCLASS       { $$ = MkSpecifier(THISCLASS); }
2224    | TYPED_OBJECT    { $$ = MkSpecifier(TYPED_OBJECT); }
2225    | ANY_OBJECT      { $$ = MkSpecifier(ANY_OBJECT); }
2226         ;
2227
2228 strict_type_specifier:
2229           VOID            { $$ = MkSpecifier(VOID); }  
2230         | CHAR            { $$ = MkSpecifier(CHAR); }
2231         | SHORT           { $$ = MkSpecifier(SHORT); }
2232         | INT             { $$ = MkSpecifier(INT); }
2233    | UINT            { $$ = MkSpecifier(UINT); }
2234    | INT64           { $$ = MkSpecifier(INT64); }
2235    | VALIST          { $$ = MkSpecifier(VALIST); }
2236         | LONG            { $$ = MkSpecifier(LONG); }
2237         | FLOAT           { $$ = MkSpecifier(FLOAT); }
2238         | DOUBLE          { $$ = MkSpecifier(DOUBLE); }
2239         | SIGNED          { $$ = MkSpecifier(SIGNED); }
2240         | UNSIGNED        { $$ = MkSpecifier(UNSIGNED); }
2241    | EXTENSION       { $$ = MkSpecifier(EXTENSION); }
2242         | struct_or_union_specifier_nocompound
2243         | enum_specifier_nocompound
2244         | strict_type
2245    | TYPEOF '(' assignment_expression ')' { $$ = MkSpecifierTypeOf($3); }
2246    | SUBCLASS '(' type ')'                { $$ = MkSpecifierSubClass($3); }
2247    | SUBCLASS '(' identifier ')'          { _DeclClass(0, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
2248    | THISCLASS       { $$ = MkSpecifier(THISCLASS); }
2249         ;
2250
2251 // TESTING declarator_nofunction here... For function declarations
2252
2253 struct_declarator:
2254           declarator_nofunction_type_ok
2255       { $$ = MkStructDeclarator($1, null); $$.loc = @$; }
2256         | declarator_nofunction_type_ok attrib
2257       { $$ = MkStructDeclarator($1, null); $$.structDecl.attrib = $2; $$.loc = @$; }  
2258         | ':' constant_expression
2259       { $$ = MkStructDeclarator(null, $2);  $$.loc = @$; }
2260         | declarator_nofunction_type_ok ':' constant_expression
2261       { $$ = MkStructDeclarator($1, $3);  $$.loc = @$; }
2262    | declarator_nofunction_type_ok ':' constant_expression ':' constant_expression
2263       { $$ = MkStructDeclarator($1, $3); $$.structDecl.posExp = $5; $$.loc = @$; }
2264         | ':' constant_expression_error
2265       { $$ = MkStructDeclarator(null, $2);  $$.loc = @$; }
2266         | declarator_nofunction_type_ok ':' constant_expression_error
2267       { $$ = MkStructDeclarator($1, $3);  $$.loc = @$; }
2268    | declarator_nofunction_type_ok ':' constant_expression ':' constant_expression_error
2269       { $$ = MkStructDeclarator($1, $3); $$.structDecl.posExp = $5; $$.loc = @$; }
2270    | declarator_nofunction_type_ok ':' constant_expression_error ':' constant_expression_error
2271       { $$ = MkStructDeclarator($1, $3); $$.structDecl.posExp = $5; $$.loc = @$; }
2272    | declarator_nofunction_type_ok ':' constant_expression_error ':' constant_expression
2273       { $$ = MkStructDeclarator($1, $3); $$.structDecl.posExp = $5; $$.loc = @$; }
2274    ;
2275
2276 struct_declarator_list:
2277           struct_declarator                                { $$ = MkList(); ListAdd($$, $1); }
2278         | struct_declarator_list ',' struct_declarator     { $$ = $1; ListAdd($1, $3); }
2279         ;
2280
2281 struct_entry:
2282      struct_or_union identifier 
2283       {
2284          $$ = MkStructOrUnion($1, $2, null);
2285          $$.addNameSpace = true;
2286          $$.ctx = PushContext();
2287       }
2288    | struct_or_union base_strict_type
2289       {
2290          $$ = MkStructOrUnion($1, MkIdentifier($2.name), null);
2291          $$.ctx = PushContext();
2292          FreeSpecifier($2);
2293       }
2294    | struct_or_union ext_decl identifier 
2295       {
2296          $$ = MkStructOrUnion($1, $3, null);
2297          $$.extDeclStruct = $2;
2298          $$.addNameSpace = true;
2299          $$.ctx = PushContext();
2300       }
2301    | struct_or_union ext_decl base_strict_type
2302       {
2303          $$ = MkStructOrUnion($1, MkIdentifier($3.name), null);
2304          $$.extDeclStruct = $2;
2305          $$.ctx = PushContext();
2306          FreeSpecifier($3);
2307       }
2308    ;
2309
2310 struct_or_union_specifier_compound:
2311      struct_or_union_specifier_compound_error '}' { $$ = $1; $$.loc = @$; }
2312    | struct_entry '{' '}'                 { $$ = $1; $$.loc = @$; POP_DEFAULT_ACCESS PopContext(curContext); }
2313    | struct_or_union '{' '}'              { $$ = MkStructOrUnion($1, null, null); $$.loc = @$; POP_DEFAULT_ACCESS }
2314    | struct_or_union ext_decl '{' '}'              { $$ = MkStructOrUnion($1, null, null); $$.extDeclStruct = $2; $$.loc = @$; POP_DEFAULT_ACCESS }
2315         ;
2316
2317 struct_or_union_specifier_compound_error:
2318      struct_entry '{' struct_declaration_list        { $$ = $1; AddStructDefinitions($1, $3);  POP_DEFAULT_ACCESS PopContext(curContext); }
2319    | struct_entry '{' struct_declaration_list_error   { $$ = $1; AddStructDefinitions($1, $3);  POP_DEFAULT_ACCESS PopContext(curContext); }
2320    | struct_entry '{' error   { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext); }
2321
2322         | struct_or_union '{' struct_declaration_list               { $$ = MkStructOrUnion($1, null, $3); POP_DEFAULT_ACCESS }
2323    | struct_or_union '{' struct_declaration_list_error               { $$ = MkStructOrUnion($1, null, $3); POP_DEFAULT_ACCESS }
2324    | struct_or_union '{' error              { $$ = MkStructOrUnion($1, null, null); POP_DEFAULT_ACCESS }
2325
2326         | struct_or_union ext_decl '{' struct_declaration_list               { $$ = MkStructOrUnion($1, null, $4); $$.extDeclStruct = $2; POP_DEFAULT_ACCESS }
2327    | struct_or_union ext_decl '{' struct_declaration_list_error               { $$ = MkStructOrUnion($1, null, $4); $$.extDeclStruct = $2; POP_DEFAULT_ACCESS }
2328    | struct_or_union ext_decl '{' error              { $$ = MkStructOrUnion($1, null, null); $$.extDeclStruct = $2; POP_DEFAULT_ACCESS }
2329         ;
2330
2331 struct_or_union_specifier_nocompound:
2332           struct_entry { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext); }
2333         ;
2334
2335 struct_decl:
2336      struct_entry
2337      {
2338         $$ = $1;
2339         if(declMode)
2340         {
2341            ($1.addNameSpace ? DeclClassAddNameSpace : DeclClass)(globalContext.nextID++, $1.id.string);
2342         }
2343      }
2344    | struct_entry '<' template_parameters_list '>' 
2345    {
2346       Symbol symbol = ($1.addNameSpace ? DeclClassAddNameSpace : DeclClass)(globalContext.nextID++, $1.id.string);
2347       $$ = $1;
2348       symbol.templateParams = $3;
2349    }
2350    ;
2351
2352 struct_head:
2353    struct_decl ':' inheritance_specifiers
2354    {
2355       $$ = $1;
2356       $$.baseSpecs = $3;
2357       SetupBaseSpecs(null, $3);
2358    }
2359    ;
2360
2361 struct_class:
2362      struct_class_error '}' { $$ = $1; $$.loc = @$; }
2363    | struct_head '{' '}'
2364       { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext); }
2365    | struct_decl '{' '}'   { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext); }
2366    | struct_or_union '{' '}' { $$ = MkStructOrUnion($1, null, null); POP_DEFAULT_ACCESS }
2367    ;
2368
2369 struct_class_error:
2370         struct_head '{' struct_declaration_list
2371    {
2372       $$ = $1;
2373       $$.definitions = $3;
2374       POP_DEFAULT_ACCESS
2375       PopContext(curContext);
2376    }
2377         | struct_head '{' struct_declaration_list_error
2378    {
2379       $$ = $1;
2380       $$.definitions = $3;
2381       POP_DEFAULT_ACCESS
2382       PopContext(curContext);
2383    }
2384         | struct_head '{' error
2385    { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext);}
2386
2387         | struct_decl '{' struct_declaration_list
2388      {
2389         PopContext(curContext);
2390         if(!declMode)
2391         {
2392            $$ = MkStructOrUnion($1.type, $1.id, $3);
2393            $1.id = null;
2394            FreeSpecifier($1);
2395         }
2396         else
2397            $$.definitions = $3;
2398         POP_DEFAULT_ACCESS
2399      }
2400         | struct_decl '{' struct_declaration_list_error
2401      {
2402         PopContext(curContext);
2403
2404         if(!declMode)
2405         {
2406            $$ = MkStructOrUnion($1.type, $1.id, $3);
2407            $1.id = null;
2408            FreeSpecifier($1);
2409         }
2410         else
2411            $$.definitions = $3;
2412         POP_DEFAULT_ACCESS
2413      }
2414    | struct_decl '{' error
2415       { $$ = $1; POP_DEFAULT_ACCESS PopContext(curContext); }
2416
2417         | struct_or_union '{' struct_declaration_list
2418       { $$ = MkStructOrUnion($1, null, $3); POP_DEFAULT_ACCESS  }
2419    | struct_or_union '{' struct_declaration_list_error
2420       { $$ = MkStructOrUnion($1, null, $3); POP_DEFAULT_ACCESS }
2421    | struct_or_union '{' error
2422       { $$ = MkStructOrUnion($1, null, null); POP_DEFAULT_ACCESS }
2423    ;
2424
2425 struct_or_union:
2426           STRUCT    { $$ = structSpecifier; memberAccessStack[++defaultMemberAccess] = publicAccess; }
2427         | UNION     { $$ = unionSpecifier; memberAccessStack[++defaultMemberAccess] = publicAccess; }
2428         ;
2429
2430 specifier_qualifier_list:
2431      type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2432    | specifier_qualifier_list  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2433    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2434    | specifier_qualifier_list  type_specifier            { $$ = $1; ListAdd($1, $2); }
2435    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2436         | specifier_qualifier_list enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2437    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2438         | specifier_qualifier_list struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2439    ;
2440
2441 guess_specifier_qualifier_list:
2442      type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2443    | guess_specifier_qualifier_list  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2444    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2445    | guess_specifier_qualifier_list  type_specifier            { $$ = $1; ListAdd($1, $2); }
2446    | guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
2447    | guess_specifier_qualifier_list  guess_type            { $$ = $1; ListAdd($1, $2); }
2448    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2449         | guess_specifier_qualifier_list enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2450    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2451         | guess_specifier_qualifier_list struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2452    ;
2453
2454 declaration_specifiers:
2455      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2456    | declaration_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
2457    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2458    | declaration_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2459    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2460    | declaration_specifiers  strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
2461    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2462         | declaration_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2463    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2464         | declaration_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2465    ;
2466
2467 guess_declaration_specifiers:
2468      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2469    | guess_declaration_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
2470    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2471    | guess_declaration_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2472    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2473    | guess_declaration_specifiers  type_specifier            { $$ = $1; ListAdd($1, $2); }
2474    | guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
2475         | guess_declaration_specifiers guess_type          { $$ = $1; ListAdd($1, $2); }
2476    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2477         | guess_declaration_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2478    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2479         | guess_declaration_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2480    ;
2481
2482 external_guess_declaration_specifiers:
2483      external_storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2484    | external_guess_declaration_specifiers external_storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
2485    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2486    | external_guess_declaration_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2487    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2488    | external_guess_declaration_specifiers  type_specifier            { $$ = $1; ListAdd($1, $2); }
2489    | guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
2490         | external_guess_declaration_specifiers guess_type          { $$ = $1; ListAdd($1, $2); }
2491    | class_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2492    | external_guess_declaration_specifiers class_specifier            { $$ = $1; ListAdd($1, $2); }
2493    ;
2494
2495 external_guess_declaration_specifiers_error:
2496      class_specifier_error                             { $$ = MkList(); ListAdd($$, $1); }
2497    | external_guess_declaration_specifiers class_specifier_error      { $$ = $1; ListAdd($1, $2); }
2498    ;
2499
2500 _inheritance_specifiers:
2501      PRIVATE                                          { $$ = MkList(); ListAdd($$, MkSpecifier(PRIVATE)); }
2502    | PUBLIC                                           { $$ = MkList(); ListAdd($$, MkSpecifier(PUBLIC)); }
2503    | storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2504    | _inheritance_specifiers storage_class_specifier   { $$ = $1; ListAdd($1, $2); }
2505    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2506    | _inheritance_specifiers type_qualifier            { $$ = $1; ListAdd($1, $2); }
2507    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2508    | _inheritance_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
2509    | identifier                                       
2510       { _DeclClass(0, $1.string); $$ = MkListOne(MkSpecifierName($1.string)); FreeIdentifier($1); }
2511         | _inheritance_specifiers identifier                { $$ = $1; _DeclClass(0, $2.string); ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2); }
2512
2513    | identifier '<' template_arguments_list '>'
2514       {
2515          // if($1._class && !$1._class.name)
2516          if($1._class)
2517          {
2518             char name[1024];
2519             strcpy(name,  $1._class.name ? $1._class.name : "");
2520             strcat(name, "::");
2521             strcat(name, $1.string);
2522             _DeclClass(0, name);
2523          }
2524          else
2525             _DeclClass(0, $1.string);
2526
2527          $$ = MkList();
2528          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
2529          FreeIdentifier($1);
2530       }
2531    | _inheritance_specifiers identifier '<' template_arguments_list '>'
2532       {
2533          $$ = $1;
2534          if($2._class && !$2._class.name)
2535          {
2536             char name[1024];
2537             strcpy(name, "::");
2538             strcat(name, $2.string);
2539             _DeclClass(0, name);
2540          }
2541          else
2542             _DeclClass(0, $2.string);
2543          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
2544          FreeIdentifier($2);
2545       }
2546    ;
2547
2548 inheritance_specifiers:
2549      _inheritance_specifiers
2550    | struct_or_union    { $$ = MkListOne(MkStructOrUnion($1, null, null)); POP_DEFAULT_ACCESS }
2551    ;
2552
2553 property_specifiers:
2554      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2555    | property_specifiers storage_class_specifier     { $$ = $1; ListAdd($1, $2); }
2556    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2557    | property_specifiers type_qualifier            { $$ = $1; ListAdd($1, $2); }
2558    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2559    | property_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
2560    | identifier                        { $$ = MkList(); ListAdd($$, MkSpecifierName($1.string)); FreeIdentifier($1)}
2561    | property_specifiers identifier          { $$ = $1; ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2)}
2562    | identifier '<' template_arguments_list '>'
2563       {
2564          // if($1._class && !$1._class.name)
2565          if($1._class)
2566          {
2567             char name[1024];
2568             strcpy(name,  $1._class.name ? $1._class.name : "");
2569             strcat(name, "::");
2570             strcat(name, $1.string);
2571             _DeclClass(0, name);
2572          }
2573          else
2574             _DeclClass(0, $1.string);
2575
2576          $$ = MkList();
2577          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
2578          FreeIdentifier($1);
2579       }
2580    | property_specifiers identifier '<' template_arguments_list '>'
2581       {
2582          if($2._class && !$2._class.name)
2583          {
2584             char name[1024];
2585             strcpy(name, "::");
2586             strcat(name, $2.string);
2587             _DeclClass(0, name);
2588          }
2589          else
2590             _DeclClass(0, $2.string);
2591          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
2592          FreeIdentifier($2);
2593       }
2594    ;
2595
2596 renew_specifiers:
2597      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2598    | renew_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
2599    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2600    | renew_specifiers type_qualifier            { $$ = $1; ListAdd($1, $2); }
2601    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2602    | renew_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
2603    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2604         | renew_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2605    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2606         | renew_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2607    | identifier                        { $$ = MkList(); ListAdd($$, MkSpecifierName($1.string)); FreeIdentifier($1)}
2608    | renew_specifiers identifier          { $$ = $1; ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2)}
2609    | identifier '<' template_arguments_list '>'
2610       {
2611          // if($1._class && !$1._class.name)
2612          if($1._class)
2613          {
2614             char name[1024];
2615             strcpy(name,  $1._class.name ? $1._class.name : "");
2616             strcat(name, "::");
2617             strcat(name, $1.string);
2618             _DeclClass(0, name);
2619          }
2620          else
2621             _DeclClass(0, $1.string);
2622
2623          $$ = MkList();
2624          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
2625          FreeIdentifier($1);
2626       }
2627    | renew_specifiers identifier '<' template_arguments_list '>'
2628       {
2629          if($2._class && !$2._class.name)
2630          {
2631             char name[1024];
2632             strcpy(name, "::");
2633             strcat(name, $2.string);
2634             _DeclClass(0, name);
2635          }
2636          else
2637             _DeclClass(0, $2.string);
2638          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
2639          FreeIdentifier($2);
2640       }
2641    ;
2642
2643 new_specifiers:
2644      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
2645    | new_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
2646    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
2647    | new_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
2648    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
2649    | new_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
2650    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2651         | new_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2652    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
2653         | new_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
2654    | identifier                        { $$ = MkList(); ListAdd($$, MkSpecifierName($1.string)); FreeIdentifier($1)}
2655    | new_specifiers identifier          { $$ = $1; ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2)}
2656    | identifier '<' template_arguments_list '>'
2657       {
2658          // if($1._class && !$1._class.name)
2659          if($1._class)
2660          {
2661             char name[1024];
2662             strcpy(name,  $1._class.name ? $1._class.name : "");
2663             strcat(name, "::");
2664             strcat(name, $1.string);
2665             _DeclClass(0, name);
2666          }
2667          else
2668             _DeclClass(0, $1.string);
2669
2670          $$ = MkList();
2671          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
2672          FreeIdentifier($1);
2673       }
2674    | new_specifiers identifier '<' template_arguments_list '>'
2675       {
2676          if($2._class && !$2._class.name)
2677          {
2678             char name[1024];
2679             strcpy(name, "::");
2680             strcat(name, $2.string);
2681             _DeclClass(0, name);
2682          }
2683          else
2684             _DeclClass(0, $2.string);
2685          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
2686          FreeIdentifier($2);
2687       }
2688    ;
2689
2690 identifier_list_error:
2691      identifier_list ',' error         { $$ = $1; ListAdd($1, null); }
2692    | identifier_list_error ',' error         { $$ = $1; ListAdd($1, null); }
2693    ;
2694
2695 identifier_list:
2696           identifier                        { $$ = MkList(); ListAdd($$, MkTypeName(null, MkDeclaratorIdentifier($1))); }
2697         | identifier_list ',' identifier    { $$ = $1; ListAdd($1, MkTypeName(null, MkDeclaratorIdentifier($3))); }
2698    | identifier_list_error ',' identifier    { $$ = $1; ListAdd($1, MkTypeName(null, MkDeclaratorIdentifier($3))); }
2699         | parameter_list ',' identifier    { $$ = $1; ListAdd($1, MkTypeName(null, MkDeclaratorIdentifier($3))); }
2700    | parameter_list_error ',' identifier    { $$ = $1; ListAdd($1, MkTypeName(null, MkDeclaratorIdentifier($3))); }
2701         ;
2702
2703 direct_declarator_nofunction_type_ok:
2704      direct_declarator_nofunction
2705    | base_strict_type
2706    {
2707       char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
2708       String s = colon ? colon + 2 : $1.name;
2709       $$ = MkDeclaratorIdentifier(MkIdentifier(s));
2710       FreeSpecifier($1);
2711    }
2712    | UINT { $$ = MkDeclaratorIdentifier(MkIdentifier("uint")); }
2713    // These rules need to be reviewed in lights of prototypes with types only...
2714         | base_strict_type '[' constant_expression ']'
2715       {
2716          Declarator decl;
2717          char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
2718          String s = colon ? colon + 2 : $1.name;
2719          decl = MkDeclaratorIdentifier(MkIdentifier(s));
2720          FreeSpecifier($1);
2721          $$ = MkDeclaratorArray(decl, $3);
2722       }
2723    | base_strict_type '[' constant_expression_error ']'
2724       {
2725          Declarator decl;
2726          char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
2727          String s = colon ? colon + 2 : $1.name;
2728          decl = MkDeclaratorIdentifier(MkIdentifier(s));
2729          FreeSpecifier($1);
2730          $$ = MkDeclaratorArray(decl, $3);
2731       }
2732         | base_strict_type '[' type ']'
2733       {
2734          Declarator decl;
2735          char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
2736          String s = colon ? colon + 2 : $1.name;
2737          decl = MkDeclaratorIdentifier(MkIdentifier(s));
2738          FreeSpecifier($1);
2739          $$ = MkDeclaratorEnumArray(decl, $3);
2740       }
2741         | base_strict_type '[' ']'
2742       {
2743          Declarator decl;
2744          char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
2745          String s = colon ? colon + 2 : $1.name;
2746          decl = MkDeclaratorIdentifier(MkIdentifier(s));
2747          FreeSpecifier($1);
2748          $$ = MkDeclaratorEnumArray(decl, null);
2749       }
2750         | direct_declarator_nofunction_type_ok '[' constant_expression ']' { $$ = MkDeclaratorArray($1, $3); }
2751    | direct_declarator_nofunction_type_ok '[' constant_expression_error ']' { $$ = MkDeclaratorArray($1, $3); }
2752         | direct_declarator_nofunction_type_ok '[' type ']' { $$ = MkDeclaratorEnumArray($1, $3); }
2753         | direct_declarator_nofunction_type_ok '[' ']'                     { $$ = MkDeclaratorArray($1, null); }
2754         ;
2755
2756 direct_declarator_nofunction:
2757           identifier                                                   { $$ = MkDeclaratorIdentifier($1); }
2758         | '(' declarator ')'                            { $$ = MkDeclaratorBrackets($2); }
2759    | '(' ext_decl declarator ')'                            { $$ = MkDeclaratorBrackets(MkDeclaratorExtended($2, $3)); }
2760         | '(' declarator_type_ok ')'                            { $$ = MkDeclaratorBrackets($2); }
2761    | '(' ext_decl declarator_type_ok ')'                            { $$ = MkDeclaratorBrackets(MkDeclaratorExtended($2, $3)); }
2762         | direct_declarator_nofunction '[' constant_expression ']' { $$ = MkDeclaratorArray($1, $3); }
2763    | direct_declarator_nofunction '[' constant_expression_error ']' { $$ = MkDeclaratorArray($1, $3); }
2764         | direct_declarator_nofunction '[' type ']' { $$ = MkDeclaratorEnumArray($1, $3); }
2765         | direct_declarator_nofunction '[' ']'                     { $$ = MkDeclaratorArray($1, null); }
2766         ;
2767
2768 direct_declarator_function_start:
2769      direct_declarator_nofunction '('
2770    ;
2771
2772 direct_declarator_function:
2773           direct_declarator_function_start parameter_type_list ')' { $$ = MkDeclaratorFunction($1, $2); }
2774    | direct_declarator_function_start parameter_type_list_error ')' { $$ = MkDeclaratorFunction($1, $2); }
2775         | direct_declarator_function_start identifier_list ')'     { $$ = MkDeclaratorFunction($1, $2); }
2776    | direct_declarator_function_start identifier_list_error ')'     { $$ = MkDeclaratorFunction($1, $2); }
2777         | direct_declarator_function_start ')'                     { $$ = MkDeclaratorFunction($1, null); }
2778         ;
2779
2780 // Tricky stuff here for overriding...
2781 direct_declarator_function_error:
2782    direct_declarator_function_start identifier_list_error
2783       {
2784          $$ = MkDeclaratorFunction($1, $2); 
2785          fileInput.Seek(@1.end.pos, start); 
2786          yyclearin;
2787          resetScannerPos(&@1.end);
2788          @$.start = @1.start;
2789          @$.end = @1.end;
2790       }
2791    | direct_declarator_function_start error
2792       { 
2793          $$ = MkDeclaratorFunction($1, null); 
2794          fileInput.Seek(@1.end.pos, start); 
2795          yyclearin;
2796          resetScannerPos(&@1.end);
2797          @$.start = @1.start;
2798          @$.end = @1.end;
2799       }
2800    | direct_declarator_function_start parameter_list '('
2801       { 
2802          $$ = MkDeclaratorFunction($1, $2); 
2803          fileInput.Seek(@1.end.pos, start); 
2804          yyclearin;
2805          resetScannerPos(&@1.end);
2806          @$.start = @1.start;
2807          @$.end = @1.end;
2808       }
2809    | direct_declarator_function_start guess_declaration_specifiers identifier '('
2810       { 
2811          $$ = MkDeclaratorFunction($1, null); 
2812          fileInput.Seek(@1.end.pos, start); 
2813          yyclearin;
2814          resetScannerPos(&@1.end);
2815          @$.start = @1.start;
2816          @$.end = @1.end;
2817          FreeList($2, FreeSpecifier);
2818          FreeIdentifier($3);
2819       }
2820         ;
2821
2822 direct_declarator:
2823      direct_declarator_function
2824    | direct_declarator_nofunction
2825    ;
2826
2827
2828 direct_declarator_function_start_type_ok:
2829      direct_declarator_nofunction_type_ok '('
2830    ;
2831
2832 direct_declarator_function_type_ok:
2833           direct_declarator_function_start_type_ok parameter_type_list ')' { $$ = MkDeclaratorFunction($1, $2); }
2834    | direct_declarator_function_start_type_ok parameter_type_list_error ')' { $$ = MkDeclaratorFunction($1, $2); }
2835         | direct_declarator_function_start_type_ok identifier_list ')'     { $$ = MkDeclaratorFunction($1, $2); }
2836    | direct_declarator_function_start_type_ok identifier_list_error ')'     { $$ = MkDeclaratorFunction($1, $2); }
2837         | direct_declarator_function_start_type_ok ')'                     { $$ = MkDeclaratorFunction($1, null); }
2838         ;
2839
2840 // Tricky stuff here for overriding...
2841 direct_declarator_function_error_type_ok:
2842    direct_declarator_function_start_type_ok identifier_list_error
2843       {
2844          $$ = MkDeclaratorFunction($1, $2); 
2845          fileInput.Seek(@1.end.pos, start); 
2846          yyclearin;
2847          resetScannerPos(&@1.end);
2848          @$.start = @1.start;
2849          @$.end = @1.end;
2850       }
2851    | direct_declarator_function_start_type_ok error
2852       { 
2853          $$ = MkDeclaratorFunction($1, null); 
2854          fileInput.Seek(@1.end.pos, start); 
2855          yyclearin;
2856          resetScannerPos(&@1.end);
2857          @$.start = @1.start;
2858          @$.end = @1.end;
2859       }
2860    | direct_declarator_function_start_type_ok parameter_list '('
2861       { 
2862          $$ = MkDeclaratorFunction($1, $2); 
2863          fileInput.Seek(@1.end.pos, start); 
2864          yyclearin;
2865          resetScannerPos(&@1.end);
2866          @$.start = @1.start;
2867          @$.end = @1.end;
2868       }
2869    | direct_declarator_function_start_type_ok guess_declaration_specifiers identifier '('
2870       { 
2871          $$ = MkDeclaratorFunction($1, null); 
2872          fileInput.Seek(@1.end.pos, start); 
2873          yyclearin;
2874          resetScannerPos(&@1.end);
2875          @$.start = @1.start;
2876          @$.end = @1.end;
2877          FreeList($2, FreeSpecifier);
2878          FreeIdentifier($3);
2879       }
2880         ;
2881
2882 direct_declarator_type_ok:
2883      direct_declarator_function_type_ok
2884    | direct_declarator_nofunction_type_ok
2885 /*
2886    | ext_decl direct_declarator_function_type_ok
2887       { $$ = MkDeclaratorExtended($1, $2); }
2888    | ext_decl direct_declarator_nofunction_type_ok
2889       { $$ = MkDeclaratorExtended($1, $2); }
2890 */
2891    ;
2892 /*
2893 asm_start:
2894     ASM '(' STRING_LITERAL { $<string>$ = CopyString(yytext); } STRING_LITERAL { $<string>$ = CopyString(yytext); }
2895       {
2896          char temp[1024];
2897          strcpy(temp, "__asm__(");
2898          strcat(temp, $<string>4);
2899          strcat(temp, " ");
2900          strcat(temp, $<string>6);
2901          delete $<string>4;
2902          delete $<string>6;
2903          $<string>$ = CopyString(temp);
2904       } 
2905    ;  
2906
2907 ext_decl:
2908      EXT_DECL { $$ = MkExtDeclString(CopyString(yytext)); }
2909    | attrib { $$ = MkExtDeclAttrib($1);
2910    | asm_start ')'
2911       {
2912          char temp[1024];
2913          strcpy(temp, $<string>1);
2914          strcat(temp, ")");
2915          delete $<string>1;
2916          $$ = MkExtDeclString(CopyString(temp));
2917       }
2918    | asm_start STRING_LITERAL { $$ = CopyString(yytext); } ')'
2919       {
2920          char temp[1024];
2921          strcpy(temp, $<string>1);
2922          strcat(temp, " ");
2923          strcat(temp, $<string>3);
2924          strcat(temp, ")");
2925          delete $<string>1;
2926          delete $<string>3;
2927          $$ = MkExtDeclString(CopyString(temp));
2928       }
2929    ;
2930 */
2931
2932 ext_decl:
2933      EXT_DECL { $$ = MkExtDeclString(CopyString(yytext)); }
2934    | EXT_STORAGE  { $$ = MkExtDeclString(CopyString(yytext)); }
2935    | attrib { $$ = MkExtDeclAttrib($1); }
2936    | ASM '(' string_literal ')'
2937       {
2938          char temp[1024];
2939          strcpy(temp, "__asm__(");
2940          strcat(temp, $3);
2941          strcat(temp, ")");
2942          $$ = MkExtDeclString(CopyString(temp));
2943          delete $3;
2944       }
2945    ;
2946
2947 _attrib:
2948    ATTRIB      { $<i>$ = ATTRIB; }
2949  | ATTRIB_DEP  { $<i>$ = ATTRIB_DEP; }
2950  | __ATTRIB    { $<i>$ = __ATTRIB; }
2951  ;
2952
2953
2954 attribute_word:
2955      IDENTIFIER   { $$  = CopyString(yytext); }
2956    | TYPE_NAME    { $$  = CopyString(yytext); }
2957    | EXT_STORAGE  { $$  = CopyString(yytext); }
2958    | EXT_DECL     { $$  = CopyString(yytext); }
2959    | CONST        { $$  = CopyString(yytext); }
2960    ;
2961
2962 attribute:
2963      attribute_word  { $$ = MkAttribute($1, null); $$.loc = @$; }
2964    | attribute_word '(' expression ')'  { $$ = MkAttribute($1, MkExpBrackets($3)); $$.loc = @$; }
2965    ;
2966
2967 attribs_list:
2968      attribute { $$ = MkListOne($1); }
2969    | attribs_list attribute { ListAdd($1, $2); $$ = $1; }
2970    | attribs_list ',' attribute { ListAdd($1, $3); $$ = $1; }
2971    ;
2972
2973 attrib:
2974      _attrib '(' '(' attribs_list ')' ')' { $$ = MkAttrib($<i>1, $4); $$.loc = @$; }
2975    | _attrib '(' '('              ')' ')'  { $$ = MkAttrib($<i>1, null); $$.loc = @$; }
2976    ;
2977
2978 direct_abstract_declarator:
2979           '(' abstract_declarator ')'               { $$ = MkDeclaratorBrackets($2); }
2980         | '(' ext_decl abstract_declarator ')'               { $$ = MkDeclaratorBrackets(MkDeclaratorExtended($2, $3)); }
2981         | '[' ']'                                   { $$ = MkDeclaratorArray(null, null); }
2982    | '[' constant_expression ']'               { $$ = MkDeclaratorArray(null, $2); }
2983         | '[' constant_expression_error ']'         { $$ = MkDeclaratorArray(null, $2); }
2984    | '[' type ']'                              { $$ = MkDeclaratorEnumArray(null, $2); }
2985         | direct_abstract_declarator '[' ']'        { $$ = MkDeclaratorArray($1, null); }
2986         | direct_abstract_declarator '[' constant_expression ']'        { $$ = MkDeclaratorArray($1, $3); }
2987         | direct_abstract_declarator '[' type']'                        { $$ = MkDeclaratorEnumArray($1, $3); }
2988         | direct_abstract_declarator '[' constant_expression_error ']'  { $$ = MkDeclaratorArray($1, $3); }
2989         | '(' ')'                                   { $$ = MkDeclaratorFunction(null, null); }
2990         | '(' parameter_type_list ')'               { $$ = MkDeclaratorFunction(null, $2); }
2991         | '(' parameter_type_list_error ')'         { $$ = MkDeclaratorFunction(null, $2); }
2992         | direct_abstract_declarator '(' ')'        { $$ = MkDeclaratorFunction($1, null); }
2993         | direct_abstract_declarator '(' parameter_type_list ')'         { $$ = MkDeclaratorFunction($1, $3); }
2994         | direct_abstract_declarator '(' parameter_type_list_error ')'   { $$ = MkDeclaratorFunction($1, $3); }
2995         ;
2996
2997 direct_abstract_declarator_noarray:
2998           '(' abstract_declarator_noarray ')'          { $$ = MkDeclaratorBrackets($2); }
2999         | '(' ext_decl abstract_declarator_noarray ')' { $$ = MkDeclaratorBrackets(MkDeclaratorExtended($2, $3)); }
3000         | '(' ')'                                      { $$ = MkDeclaratorFunction(null, null); }
3001         | '(' parameter_type_list ')'                  { $$ = MkDeclaratorFunction(null, $2); }
3002         | '(' parameter_type_list_error ')'         { $$ = MkDeclaratorFunction(null, $2); }
3003         | direct_abstract_declarator_noarray '(' ')'   { $$ = MkDeclaratorFunction($1, null); }
3004         | direct_abstract_declarator_noarray '(' parameter_type_list ')'       { $$ = MkDeclaratorFunction($1, $3); }
3005         | direct_abstract_declarator_noarray '(' parameter_type_list_error ')' { $$ = MkDeclaratorFunction($1, $3); }
3006         ;
3007
3008 pointer:
3009           '*'                               { $$ = MkPointer(null, null); }
3010         | '*' type_qualifier_list           { $$ = MkPointer($2, null); }
3011         | '*' pointer                       { $$ = MkPointer(null, $2); }
3012         | '*' type_qualifier_list pointer   { $$ = MkPointer($2, $3); }
3013         ;
3014
3015 abstract_declarator:
3016           pointer                              { $$ = MkDeclaratorPointer($1, null); }
3017         | direct_abstract_declarator
3018         | pointer direct_abstract_declarator   { $$ = MkDeclaratorPointer($1, $2); }
3019    | ext_decl pointer { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, null)); }
3020         | ext_decl pointer direct_abstract_declarator { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3021         ;
3022
3023 abstract_declarator_noarray:
3024           pointer                              { $$ = MkDeclaratorPointer($1, null); }
3025         | direct_abstract_declarator_noarray
3026         | pointer direct_abstract_declarator_noarray   { $$ = MkDeclaratorPointer($1, $2); }
3027    | ext_decl pointer { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, null)); }
3028    | ext_decl pointer direct_abstract_declarator_noarray { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3029         ;
3030
3031 declarator:
3032           direct_declarator
3033         | pointer direct_declarator
3034       { $$ = MkDeclaratorPointer($1, $2); }
3035    | ext_decl pointer direct_declarator
3036       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3037    | declarator ext_decl
3038       { $$ = MkDeclaratorExtendedEnd($2, $1); }  
3039    | declarator_nofunction_type_ok ext_decl
3040       { $$ = MkDeclaratorExtendedEnd($2, $1); }  
3041    ;
3042
3043 declarator_type_ok:
3044           direct_declarator_type_ok
3045         | pointer direct_declarator_type_ok
3046       { $$ = MkDeclaratorPointer($1, $2); }
3047   | ext_decl pointer direct_declarator_type_ok
3048       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3049    | declarator_type_ok ext_decl
3050       { $$ = MkDeclaratorExtendedEnd($2, $1); }  
3051    ;
3052
3053 declarator_function:
3054      direct_declarator_function
3055         | pointer direct_declarator_function      { $$ = MkDeclaratorPointer($1, $2); }
3056         | ext_decl pointer direct_declarator_function { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3057         | pointer ext_decl direct_declarator_function { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
3058    ;
3059
3060 declarator_function_error:
3061           direct_declarator_function_error
3062         | pointer direct_declarator_function_error      { $$ = MkDeclaratorPointer($1, $2); }
3063         | ext_decl pointer direct_declarator_function_error { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3064         | pointer ext_decl direct_declarator_function_error { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
3065    ;
3066
3067 declarator_function_type_ok:
3068      direct_declarator_function_type_ok
3069         | pointer direct_declarator_function_type_ok      { $$ = MkDeclaratorPointer($1, $2); }
3070         | ext_decl pointer direct_declarator_function_type_ok { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3071         | pointer ext_decl direct_declarator_function_type_ok { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
3072    ;
3073
3074 declarator_function_error_type_ok:
3075           direct_declarator_function_error_type_ok
3076         | pointer direct_declarator_function_error_type_ok      { $$ = MkDeclaratorPointer($1, $2); }
3077         | ext_decl pointer direct_declarator_function_error_type_ok { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3078         | pointer ext_decl direct_declarator_function_error_type_ok { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
3079    ;
3080
3081 declarator_nofunction_type_ok:
3082           direct_declarator_nofunction_type_ok
3083         | pointer direct_declarator_nofunction_type_ok      { $$ = MkDeclaratorPointer($1, $2); }
3084         | ext_decl pointer direct_declarator_nofunction_type_ok { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
3085         | pointer ext_decl direct_declarator_nofunction_type_ok { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
3086    ;
3087
3088 initializer:
3089           assignment_expression          { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3090         | '{' initializer_list '}'       { $$ = MkInitializerList($2); $$.loc = @$; }
3091         | '{' initializer_list ',' '}'   
3092       { 
3093          $$ = MkInitializerList($2); 
3094          $$.loc = @$; 
3095
3096          {
3097             Expression exp = MkExpDummy();
3098             Initializer init = MkInitializerAssignment(exp);
3099             init.loc = @3;
3100             exp.loc = @3;
3101             ListAdd($2, init); 
3102          }
3103       }
3104         ;
3105
3106 initializer_error:
3107      assignment_expression_error    { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3108         | '{' initializer_list '}' error      { $$ = MkInitializerList($2); $$.loc = @$; }
3109    | '{' initializer_list                 { $$ = MkInitializerList($2); $$.loc = @$; }
3110         | '{' initializer_list ',' '}' error  
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         | '{' initializer_list ','
3124       { 
3125          $$ = MkInitializerList($2); 
3126          $$.loc = @$;
3127
3128          {
3129             Expression exp = MkExpDummy();
3130             Initializer init = MkInitializerAssignment(exp);
3131             init.loc = @3;
3132             exp.loc = @3;
3133             ListAdd($2, init); 
3134          }
3135       }
3136         ;
3137
3138 initializer_condition:
3139           conditional_expression          { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3140    | anon_instantiation_expression
3141       { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3142         ;
3143
3144 initializer_condition_error:
3145      conditional_expression_error    { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3146    | anon_instantiation_expression_error  { $$ = MkInitializerAssignment($1); $$.loc = @$; }
3147         ;
3148
3149 initializer_list:
3150           initializer                       { $$ = MkList(); ListAdd($$, $1); }
3151    | initializer_error                 { $$ = MkList(); ListAdd($$, $1); }
3152         | initializer_list ',' initializer  { $$ = $1; ListAdd($1, $3); }
3153    | initializer_list ',' initializer_error  { $$ = $1; ListAdd($1, $3); }
3154
3155    // Errors
3156         | initializer_list initializer  { $$ = $1; ListAdd($1, $2); }
3157    | initializer_list initializer_error  { $$ = $1; ListAdd($1, $2); }
3158         ;
3159
3160 init_declarator:
3161           declarator                     { $$ = MkInitDeclarator($1, null); $$.loc = @$; }
3162    | declarator_type_ok             { $$ = MkInitDeclarator($1, null); $$.loc = @$; }
3163         | declarator '=' initializer     { $$ = MkInitDeclarator($1, $3); $$.loc = @$; $$.initializer.loc.start = @2.end; }
3164         ;
3165
3166 init_declarator_error:
3167           declarator error                 { $$ = MkInitDeclarator($1, null); $$.loc = @$; }
3168    /* Useless rules due to conflicts
3169    | declarator '=' error                 { $$ = MkInitDeclarator($1, MkInitializerAssignment(MkExpDummy())); $$.loc = @$; $$.initializer.loc = @2; $$.initializer.exp.loc = @2; }
3170    */
3171         | declarator '=' initializer_error     { $$ = MkInitDeclarator($1, $3); $$.loc = @$; $$.initializer.loc.start = @2.end; }
3172         ;
3173
3174 init_declarator_list:
3175           init_declarator                            { $$ = MkList(); ListAdd($$, $1); }
3176         | init_declarator_list ',' init_declarator   { $$ = $1; ListAdd($1, $3); }
3177         | UINT ',' init_declarator                  { $$ = MkList(); ListAdd($$, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("uint")), null)); ListAdd($$, $3); }
3178    | INT64 ',' init_declarator                  { $$ = MkList(); ListAdd($$, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("int64")), null)); ListAdd($$, $3); }
3179         | base_strict_type ',' init_declarator
3180    {
3181       char * colon = RSearchString($1.name, "::", strlen($1.name), true, false);
3182       String s = colon ? colon + 2 : $1.name;
3183       $$ = MkList();
3184       ListAdd($$, MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier(s)), null));
3185       ListAdd($$, $3);
3186       FreeSpecifier($1);
3187    }
3188    | init_declarator_list_error ',' init_declarator   { $$ = $1; ListAdd($1, $3); }
3189    /*| base_strict_type ',' init_declarator
3190       {
3191          $$ = MkList();
3192          ListAdd($1, $3);
3193       }*/
3194         ;
3195
3196 init_declarator_list_error:
3197           init_declarator_error                            { $$ = MkList(); ListAdd($$, $1); }
3198    | init_declarator error                            { $$ = MkList(); ListAdd($$, $1); }
3199         | init_declarator_list ',' init_declarator_error   { $$ = $1; ListAdd($1, $3); }
3200    | init_declarator_list_error ',' init_declarator_error   { $$ = $1; ListAdd($1, $3); }
3201         ;
3202
3203 type_name:
3204           specifier_qualifier_list                      { $$ = MkTypeName($1, null); }
3205         | specifier_qualifier_list abstract_declarator  { $$ = MkTypeName($1, $2); }
3206         ;
3207
3208 guess_type_name:
3209           guess_specifier_qualifier_list                         { $$ = MkTypeName($1, null); }
3210         | guess_specifier_qualifier_list abstract_declarator     { $$ = MkTypeName($1, $2); }
3211         ;
3212
3213 /*** PARAMETERS **********************************************************************/
3214 parameter_declaration:
3215      guess_declaration_specifiers declarator_type_ok          { $$ = MkTypeName($1, $2); }
3216    | guess_declaration_specifiers abstract_declarator { $$ = MkTypeName($1, $2); }
3217    | guess_declaration_specifiers '&'                 { $$ = MkTypeName($1, MkDeclaratorPointer(MkPointer(null,null), null)); }
3218    | guess_declaration_specifiers '&' declarator_type_ok      { $$ = MkTypeName($1, MkDeclaratorPointer(MkPointer(null,null), $3)); }
3219         | guess_declaration_specifiers                     { $$ = MkTypeNameGuessDecl($1, null); }
3220    | CLASS
3221       { $$ = MkTypeName(MkListOne(MkSpecifier(CLASS)), null); }
3222 /*
3223    | TYPED_OBJECT                                            
3224       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), null); }
3225    | TYPED_OBJECT '&'
3226       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), MkDeclaratorPointer(MkPointer(null,null), null)); }
3227    | TYPED_OBJECT declarator                                           
3228       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), $2);  }
3229    | TYPED_OBJECT '&' declarator                                       
3230       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), MkDeclaratorPointer(MkPointer(null,null), $3)); }
3231    | ANY_OBJECT
3232       { $$ = MkTypeName(MkListOne(MkSpecifier(ANY_OBJECT)), null); }
3233    | ANY_OBJECT declarator
3234       { $$ = MkTypeName(MkListOne(MkSpecifier(ANY_OBJECT)), $2); }
3235 */
3236         ;
3237
3238 parameter_declaration_error:
3239           guess_declaration_specifiers declarator_type_ok error          { $$ = MkTypeName($1, $2); }
3240         | guess_declaration_specifiers abstract_declarator error { $$ = MkTypeName($1, $2); }
3241         ;
3242
3243 parameter_list:
3244           parameter_declaration                      { $$ = MkList(); ListAdd($$, $1); }
3245         | parameter_list ',' parameter_declaration   { $$ = $1; ListAdd($1, $3); }
3246    | parameter_list error ',' parameter_declaration   { $$ = $1; ListAdd($1, $4); }
3247    | parameter_list_error ',' parameter_declaration   { $$ = $1; ListAdd($1, $3); }
3248    | parameter_list_error error ',' parameter_declaration   { $$ = $1; ListAdd($1, $4); }
3249    | error ',' parameter_declaration   { $$ = MkList(); ListAdd($$, MkTypeName(MkList(), null)); ListAdd($$, $3); }
3250
3251         | identifier_list ',' parameter_declaration   { $$ = $1; ListAdd($1, $3); }
3252    | identifier_list error ',' parameter_declaration   { $$ = $1; ListAdd($1, $4); }
3253    | identifier_list_error ',' parameter_declaration   { $$ = $1; ListAdd($1, $3); }
3254    | identifier_list_error error ',' parameter_declaration   { $$ = $1; ListAdd($1, $4); }
3255 ;
3256
3257 parameter_list_error:
3258           parameter_declaration_error                      { $$ = MkList(); ListAdd($$, $1); }
3259         | parameter_list ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $3); }
3260    | parameter_list_error ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $3); }
3261    | parameter_list_error error ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $4); }
3262    | error ',' parameter_declaration_error   { $$ = MkList(); ListAdd($$, MkTypeName(MkList(), null)); ListAdd($$, $3); }
3263
3264         | identifier_list ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $3); }
3265    | identifier_list_error ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $3); }
3266    | identifier_list_error error ',' parameter_declaration_error   { $$ = $1; ListAdd($1, $4); }
3267         ;   
3268
3269 parameter_type_list:
3270           parameter_list
3271         | parameter_list ',' ELLIPSIS                { $$ = $1; ListAdd($1, MkTypeName(null, null)); }
3272    | parameter_list_error ',' ELLIPSIS                { $$ = $1; ListAdd($1, MkTypeName(null, null)); }
3273         | identifier_list ',' ELLIPSIS                { $$ = $1; ListAdd($1, MkTypeName(null, null)); }
3274    | identifier_list_error ',' ELLIPSIS                { $$ = $1; ListAdd($1, MkTypeName(null, null)); }
3275    | error ',' ELLIPSIS                { $$ = MkList(); ListAdd($$, MkTypeName(null, null)); }
3276         ;
3277
3278 parameter_type_list_error: 
3279     parameter_list_error
3280    | parameter_list ',' error                { $$ = $1; ListAdd($1, null); }
3281    | parameter_list_error error
3282         ;
3283
3284 /****** STATEMENTS *******************************************************************/
3285 statement:
3286           labeled_statement
3287    | attrib { $$ = MkExpressionStmt(null); FreeAttrib($1); }   // Ignoring this for now... ( For __attribute__ ((__unused__)) )
3288         | compound_statement
3289    | ';' { $$ = MkExpressionStmt(null); }
3290    | ':' { $$ = MkExpressionStmt(null); }
3291         | expression ';'              { $$ = MkExpressionStmt($1); $$.loc = @$; }
3292         | selection_statement
3293         | iteration_statement
3294         | jump_statement
3295    | asm_statement
3296    | firewatchers ';'
3297    | stopwatching ';'
3298    | watch_definition ';'
3299         ;
3300
3301 statement_error:
3302         labeled_statement_error          { $$ = $1; Compiler_Error($"syntax error\n"); } 
3303    | iteration_statement_error      { $$ = $1; Compiler_Error($"syntax error\n"); } 
3304    | compound_statement_error       { $$ = $1; Compiler_Error($"syntax error\n"); } 
3305         | selection_statement_error      { $$ = $1; Compiler_Error($"syntax error\n"); } 
3306    | jump_statement_error           { $$ = $1; Compiler_Error($"syntax error\n"); } 
3307         | jump_statement error           { $$ = $1; Compiler_Error($"syntax error\n"); } 
3308    | expression_error { $$ = MkExpressionStmt($1); Compiler_Error($"syntax error\n"); $$.loc = @1; }
3309    ;
3310
3311 asm_field:
3312      string_literal { $$ = MkAsmField($1, null); $$.loc = @1; }
3313    | string_literal '(' assignment_expression ')' { $$ = MkAsmField($1, $3); $$.loc = @$; }
3314    ;
3315
3316 asm_field_list:
3317      asm_field { $$ = MkListOne($1); }
3318    | asm_field_list ',' asm_field { ListAdd($$, $3); }
3319    | { $$ = null; }
3320    ;
3321
3322 asm_statement:
3323      ASM type_qualifier '(' string_literal ')' ';'                                                          { $$ = MkAsmStmt($2, $4, null, null, null); $$.loc = @$; }
3324    | ASM type_qualifier '(' string_literal ':' asm_field_list ')' ';'                                       { $$ = MkAsmStmt($2, $4, $6, null, null); $$.loc = @$; }
3325    | ASM type_qualifier '(' string_literal ':' asm_field_list ':' asm_field_list ')' ';'                    { $$ = MkAsmStmt($2, $4, $6, $8, null); $$.loc = @$; }
3326    | ASM type_qualifier '(' string_literal ':' asm_field_list ':' asm_field_list ':' asm_field_list ')' ';' { $$ = MkAsmStmt($2, $4, $6, $8, $10); $$.loc = @$; }
3327    
3328    | ASM type_qualifier '(' string_literal IDENTIFIER asm_field_list ')' ';'                                { $$ = MkAsmStmt($2, $4, null, $6, null); $$.loc = @$; }
3329    | ASM type_qualifier '(' string_literal IDENTIFIER asm_field_list ':' asm_field_list ')' ';'             { $$ = MkAsmStmt($2, $4, null, $6, $8); $$.loc = @$; }
3330    | ASM type_qualifier '(' string_literal ':' asm_field_list IDENTIFIER asm_field_list ')' ';'             { $$ = MkAsmStmt($2, $4, $6, null, $8); $$.loc = @$; }
3331
3332    | ASM '(' string_literal ')' ';'                                                                         { $$ = MkAsmStmt(null, $3, null, null, null); $$.loc = @$; }
3333    | ASM '(' string_literal ':' asm_field_list ')' ';'                                                      { $$ = MkAsmStmt(null, $3, $5, null, null); $$.loc = @$; }
3334    | ASM '(' string_literal ':' asm_field_list ':' asm_field_list ')' ';'                                   { $$ = MkAsmStmt(null, $3, $5, $7, null); $$.loc = @$; }
3335    | ASM '(' string_literal ':' asm_field_list ':' asm_field_list ':' asm_field_list ')' ';'                { $$ = MkAsmStmt(null, $3, $5, $7, $9); $$.loc = @$; }
3336
3337    | ASM '(' string_literal IDENTIFIER asm_field_list ')' ';'                                               { $$ = MkAsmStmt(null, $3, null, $5, null); $$.loc = @$; }
3338    | ASM '(' string_literal IDENTIFIER asm_field_list ':' asm_field_list ')' ';'                            { $$ = MkAsmStmt(null, $3, null, $5, $7); $$.loc = @$; }
3339    | ASM '(' string_literal ':' asm_field_list IDENTIFIER asm_field_list ')' ';'                            { $$ = MkAsmStmt(null, $3, $5, null, $7); $$.loc = @$; }
3340    ;
3341
3342 labeled_statement:
3343           identifier ':' statement                { $$ = MkLabeledStmt($1, $3); $$.loc = @$; }
3344    | CASE constant_expression ':' statement  { $$ = MkCaseStmt($2, $4); $$.loc = @$; $2.loc.start = @1.end; }
3345    | CASE constant_expression_error ':' statement  { $$ = MkCaseStmt($2, $4); $$.loc = @$; $2.loc.start = @1.end; }
3346    | CASE ':' statement  { $$ = MkCaseStmt(MkExpDummy(), $3); $$.caseStmt.exp.loc = @2; $$.loc = @$; $$.caseStmt.exp.loc.start = @1.end; }
3347         | DEFAULT ':' statement                   { $$ = MkCaseStmt(null, $3); $$.loc = @$; }
3348         ;
3349
3350 labeled_statement_error
3351         : identifier ':' statement_error                { $$ = MkLabeledStmt($1, $3); $$.loc = @$; }
3352    | CASE constant_expression ':' statement_error  { $$ = MkCaseStmt($2, $4); $$.loc = @$; $2.loc.start = @1.end; }
3353    | CASE constant_expression_error ':' statement_error  { $$ = MkCaseStmt($2, $4); $$.loc = @$; $2.loc.start = @1.end; }
3354    | CASE ':' statement_error  { $$ = MkCaseStmt(MkExpDummy(), $3); $$.caseStmt.exp.loc = @2; $$.loc = @$; $$.caseStmt.exp.loc.start = @1.end; }
3355    | CASE ':' { $$ = MkCaseStmt(MkExpDummy(), null); $$.caseStmt.exp.loc = @2; $$.loc = @$; $$.caseStmt.exp.loc.start = @1.end; }
3356         | DEFAULT ':' statement_error                   { $$ = MkCaseStmt(null, $3); $$.loc = @$; }
3357    | DEFAULT ':'  { $$ = MkCaseStmt(null, null); $$.loc = @$; }
3358         ;
3359
3360 declaration_mode:
3361      PUBLIC    { $$ = declMode = publicAccess; }
3362    | PRIVATE   { $$ = declMode = privateAccess; }
3363    | DEFAULT   { $$ = declMode = defaultAccess; }
3364    ;
3365
3366 member_access:
3367      PUBLIC    { $$ = publicAccess; }
3368    | PRIVATE   { $$ = privateAccess; }
3369    ;
3370
3371 declaration:
3372           declaration_specifiers ';'                       { $$ = MkDeclaration($1, null); $$.loc = @$; }
3373         | declaration_specifiers init_declarator_list ';'  { $$ = MkDeclaration($1, $2); $$.loc = @$; }
3374    | instantiation_named ';'                          { $$ = MkDeclarationInst($1); $$.loc = @$; }
3375    | declaration_error ';'                            { $$ = $1; }
3376         ;
3377
3378 external_guess_declaration:
3379      external_guess_declaration_specifiers ';'                 { $$ = MkDeclaration($1, null); $$.loc = @$; }
3380    | external_guess_declaration_specifiers init_declarator_list ';'                { $$ = MkDeclaration($1, $2); $$.loc = @$; }
3381    | external_guess_declaration_specifiers_error init_declarator_list ';'                { $$ = MkDeclaration($1, $2); $$.loc = @$; }
3382
3383    | external_guess_instantiation_named ';'                          { $$ = MkDeclarationInst($1); $$.loc = @$; }
3384    | DEFINE identifier '=' conditional_expression ';' { $$ = MkDeclarationDefine($2, $4); $$.loc = @$; }
3385    | STATIC DEFINE identifier '=' conditional_expression ';' { declMode = staticAccess; $$ = MkDeclarationDefine($3, $5); $$.loc = @$; }
3386         ;
3387
3388 external_guess_declaration_error:
3389    external_guess_declaration_specifiers error { $$ = MkDeclaration($1, null); $$.loc = @$; yyerrok; }
3390         ;
3391
3392 declaration_error:
3393      declaration_specifiers error                       { $$ = MkDeclaration($1, null); $$.loc = @$; }
3394    | declaration_error error {}
3395
3396    | instantiation_named_error error                   { $$ = MkDeclarationInst($1); $$.loc = @$; }
3397    | instantiation_named error                         { $$ = MkDeclarationInst($1); $$.loc = @$; }
3398    | declaration_specifiers init_declarator_list_error  { $$ = MkDeclaration($1, $2); $$.loc = @$; }
3399    ;
3400
3401 declaration_list:
3402           declaration                       { $$ = MkList(); ListAdd($$, $1); /*declMode = defaultDeclMode;*/ }
3403         | declaration_list declaration      { $$ = $1; ListAdd($1, $2); /*declMode = defaultDeclMode; */}
3404    | declaration_list_error declaration      { $$ = $1; ListAdd($1, $2); /*declMode = defaultDeclMode; */}
3405    | declaration_list error ';'       { $$ = $1; }
3406         ;
3407
3408 declaration_list_error:
3409     declaration_error                       { $$ = MkList(); ListAdd($$, $1); }
3410    | declaration_list declaration_error { $$ = $1; ListAdd($1, $2); }
3411         ;
3412
3413 statement_list:
3414           statement                         { $$ = MkList(); ListAdd($$, $1); }
3415         | statement_list statement          { $$ = $1; ListAdd($1, $2); }
3416    | statement_list_error statement          { $$ = $1; ListAdd($1, $2); }
3417         ;
3418
3419 statement_list_error:
3420      statement_error                   { $$ = MkList(); ListAdd($$, $1); }
3421    | statement_list statement_error          { $$ = $1; ListAdd($1, $2); }
3422    | statement_list_error statement_error          { $$ = $1; ListAdd($1, $2); }
3423    | statement_list declaration              { Statement stmt = MkBadDeclStmt($2); stmt.loc = @2; Compiler_Warning(C89_DECL_WARNING); $$ = $1; ListAdd($1, stmt); /*declMode = defaultDeclMode;*/ }
3424    | statement_list_error declaration        { Statement stmt = MkBadDeclStmt($2); stmt.loc = @2; Compiler_Warning(C89_DECL_WARNING); $$ = $1; ListAdd($1, stmt); /*declMode = defaultDeclMode;*/ }
3425    | statement_list declaration_error        { Statement stmt = MkBadDeclStmt($2); stmt.loc = @2; Compiler_Warning(C89_DECL_WARNING); $$ = $1; ListAdd($1, stmt); /*declMode = defaultDeclMode;*/ }
3426    | statement_list_error declaration_error  { Statement stmt = MkBadDeclStmt($2); stmt.loc = @2; Compiler_Warning(C89_DECL_WARNING); $$ = $1; ListAdd($1, stmt); /*declMode = defaultDeclMode;*/ }
3427    ;
3428
3429 compound_inside:
3430         statement_list                      { $$ = MkCompoundStmt(null, $1); }
3431         | declaration_list                  { $$ = MkCompoundStmt($1, null); }
3432         | declaration_list statement_list   { $$ = MkCompoundStmt($1, $2); }
3433    | declaration_list_error statement_list   { $$ = MkCompoundStmt($1, $2); }
3434    ;
3435
3436 compound_inside_error:
3437         statement_list_error                      { $$ = MkCompoundStmt(null, $1); }
3438         | declaration_list_error                  { $$ = MkCompoundStmt($1, null); }
3439         | declaration_list statement_list_error   { $$ = MkCompoundStmt($1, $2); }
3440    | declaration_list_error statement_list_error   { $$ = MkCompoundStmt($1, $2); }
3441    ;
3442
3443 compound_start:
3444     '{' { $<context>$ = PushContext(); } 
3445     ;
3446
3447 compound_statement: 
3448    compound_statement_error '}'     { $$ = $1; $$.loc = @$; }
3449         ;
3450
3451 compound_statement_error: 
3452           compound_start compound_inside_error
3453       { $$ = $2; $$.compound.context = $<context>1; PopContext($<context>1); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; }
3454    |    compound_start 
3455       { $$ = MkCompoundStmt(null, null); $$.compound.context = $<context>1; PopContext($<context>1); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; }
3456
3457         | compound_start compound_inside
3458       { $$ = $2; $$.compound.context = $<context>1; PopContext($<context>1); $$.loc = @$; $$.loc.end.charPos++; $$.loc.end.pos++; }
3459
3460         ;
3461
3462 expression_statement:
3463         ';'                         { $$ = MkExpressionStmt(null); $$.loc = @$; }
3464         | expression ';'              { $$ = MkExpressionStmt($1); $$.loc = @$; }
3465    | expression_error ';'            { $$ = MkExpressionStmt($1); $$.loc = @$; }
3466         ;
3467
3468 selection_statement:
3469           IF '(' expression ')' statement %prec IFX        { $$ = MkIfStmt($3, $5, null); $$.loc = @$; }
3470    | IF '(' expression_error ')' statement %prec IFX        { $$ = MkIfStmt($3, $5, null); $$.loc = @$; }
3471         | IF '(' expression ')' statement ELSE statement   { $$ = MkIfStmt($3, $5, $7); $$.loc = @$; }
3472    | IF '(' expression_error ')' statement ELSE statement   { $$ = MkIfStmt($3, $5, $7); $$.loc = @$; }
3473         | SWITCH '(' expression ')' statement              { $$ = MkSwitchStmt($3, $5); $$.loc = @$; }
3474    | SWITCH '(' expression_error ')' statement              { $$ = MkSwitchStmt($3, $5); $$.loc = @$; }
3475         ;
3476
3477 selection_statement_error:
3478    IF '(' expression_error    { $$ = MkIfStmt($3, null, null); $$.loc = @$; }
3479    | selection_statement error
3480    ;
3481
3482 iteration_statement:
3483           WHILE '(' expression ')' statement           { $$ = MkWhileStmt($3, $5); $$.loc = @$; }
3484    | WHILE '(' expression_error statement     { $$ = MkWhileStmt($3, $4); $$.loc = @$; }
3485    | WHILE '(' ')' statement     { $$ = MkWhileStmt(null, $4); $$.loc = @$; }
3486
3487         | DO statement WHILE '(' expression ')' ';'     { $$ = MkDoWhileStmt($2, $5); $$.loc = @$; }
3488    | DO statement WHILE '(' expression_error ';'     { $$ = MkDoWhileStmt($2, $5); $$.loc = @$; }
3489
3490         | FOR '(' expression_statement expression_statement ')' statement                   { $$ = MkForStmt($3, $4, null, $6); $$.loc = @$; }
3491    | FOR '(' expression_statement ')' statement                   { $$ = MkForStmt($3, null, null, $5); $$.loc = @$; }
3492         | FOR '(' expression_statement expression_statement expression ')' statement        { $$ = MkForStmt($3, $4, $5, $7); $$.loc = @$; }
3493    | FOR '(' expression_statement expression_statement expression_error statement  { $$ = MkForStmt($3, $4, $5, $6 ); $$.loc = @$; }
3494    | FOR '(' ')' statement  { $$ = MkForStmt(null, null, null, $4); $$.loc = @$; }
3495
3496    | FOR '(' identifier ':' expression ')' statement                   { $$ = MkForEachStmt($3, $5, null, $7); $$.loc = @$; }
3497    | FOR '(' identifier ':' expression ';' expression ')' statement    { $$ = MkForEachStmt($3, $5, $7, $9); $$.loc = @$; }
3498         ;
3499
3500 iteration_statement_error:
3501    FOR '(' error                                                        { $$ = MkForStmt(null, null, null, null); $$.loc = @$; } |
3502         FOR '(' expression_error error                                       { $$ = MkForStmt(MkExpressionStmt($3), null, null, null); $$.forStmt.init.loc = @3; $$.loc = @$; } |
3503         FOR '(' expression_statement error                                   { $$ = MkForStmt($3, null, null, null); $$.loc = @$; } |
3504         FOR '(' expression_statement expression_error error                  { $$ = MkForStmt($3, MkExpressionStmt($4), null, null); $$.loc = @$; $$.forStmt.check.loc = @4; } |
3505    /* Useless rules due to conflicts
3506         FOR '(' expression_statement expression_statement error              { $$ = MkForStmt($3, $4, null, null); $$.loc = @$; } |
3507    */
3508    FOR '(' expression_statement expression_statement expression_error   { $$ = MkForStmt($3, $4, $5, null); $$.loc = @$; } |
3509         FOR '(' expression_statement expression_statement ')' statement_error                   { $$ = MkForStmt($3, $4, null, $6); $$.loc = @$; } |
3510         FOR '(' expression_statement expression_statement expression ')' statement_error  { $$ = MkForStmt($3, $4, $5, $7); $$.loc = @$; } |
3511    FOR '(' expression_statement expression_statement expression_error statement_error  { $$ = MkForStmt($3, $4, $5, $6 ); $$.loc = @$; } |
3512
3513         DO statement WHILE '(' expression ')'     { $$ = MkDoWhileStmt($2, $5); $$.loc = @$; } |
3514         DO statement WHILE '(' expression      { $$ = MkDoWhileStmt($2, $5); $$.loc = @$; } |
3515    DO statement WHILE '(' expression_error      { $$ = MkDoWhileStmt($2, $5); $$.loc = @$; } |
3516         DO statement WHILE '(' { $$ = MkDoWhileStmt($2, null); $$.loc = @$; } |
3517    DO statement WHILE { $$ = MkDoWhileStmt($2, null); $$.loc = @$; } |
3518         DO statement { $$ = MkDoWhileStmt($2, null); $$.loc = @$; } |
3519    DO { $$ = MkDoWhileStmt(null, null); $$.loc = @$; } |
3520
3521
3522    WHILE error           { $$ = MkWhileStmt(null, null); $$.loc = @$; } |
3523    /* Useless rules due to conflicts
3524         WHILE '(' error           { $$ = MkWhileStmt(null, null); $$.loc = @$; } |
3525    */
3526    WHILE '(' ')' error           { $$ = MkWhileStmt(null, null); $$.loc = @$; } |
3527         WHILE '(' expression_error           { $$ = MkWhileStmt($3, null); $$.loc = @$; } |
3528    /* Useless rules due to conflicts
3529    WHILE '(' expression_error error          { $$ = MkWhileStmt($3, null); $$.loc = @$; } |
3530    */
3531         WHILE '(' expression ')' statement_error           { $$ = MkWhileStmt($3, $5); $$.loc = @$; } |
3532    WHILE '(' expression_error statement_error     { $$ = MkWhileStmt($3, $4 ); $$.loc = @$; }
3533
3534
3535 jump_statement:
3536           GOTO identifier ';'   { $$ = MkGotoStmt($2); $$.loc = @$; }
3537         | CONTINUE ';'          { $$ = MkContinueStmt(); $$.loc = @$; }
3538         | BREAK ';'             { $$ = MkBreakStmt(); $$.loc = @$; }
3539         | RETURN ';'            { Expression exp = MkExpDummy(); $$ = MkReturnStmt(MkListOne(exp)); $$.loc = @$; exp.loc = @2; }
3540         | RETURN expression ';' { $$ = MkReturnStmt($2); $$.loc = @$; }
3541    | RETURN expression_error ';' { $$ = MkReturnStmt($2); $$.loc = @$; }
3542         | RETURN anon_instantiation_expression ';' { $$ = MkReturnStmt(MkListOne($2)); $$.loc = @$; }
3543    | RETURN anon_instantiation_expression_error ';' { $$ = MkReturnStmt(MkListOne($2)); $$.loc = @$; }
3544         ;
3545
3546 jump_statement_error:
3547      RETURN expression_error { $$ = MkReturnStmt($2); $$.loc = @$; } |
3548      RETURN anon_instantiation_expression_error { $$ = MkReturnStmt(MkListOne($2)); $$.loc = @$; } |
3549      RETURN { Expression exp = MkExpDummy(); $$ = MkReturnStmt(MkListOne(exp)); $$.loc = @$; exp.loc.start = exp.loc.end = @1.end; } |
3550      GOTO { $$ = MkGotoStmt(null); $$.loc = @$; }
3551         ;
3552
3553 /*************************************************************************************/
3554
3555 function_definition:
3556           external_guess_declaration_specifiers declarator_function declaration_list compound_statement      { $$ = MkFunction($1, $2, $3); ProcessFunctionBody($$, $4); $$.loc = @$; }
3557         | external_guess_declaration_specifiers declarator_function compound_statement
3558        { $$ = MkFunction($1, $2, null); ProcessFunctionBody($$, $3); $$.loc = @$; }
3559         | external_guess_declaration_specifiers declarator_function_type_ok declaration_list compound_statement      { $$ = MkFunction($1, $2, $3); ProcessFunctionBody($$, $4); $$.loc = @$; }
3560         | external_guess_declaration_specifiers declarator_function_type_ok compound_statement                       
3561        { $$ = MkFunction($1, $2, null); ProcessFunctionBody($$, $3); $$.loc = @$; }
3562
3563         | declarator_function declaration_list compound_statement                             { $$ = MkFunction(null, $1, $2); ProcessFunctionBody($$, $3); $$.loc = @$; }
3564         | declarator_function compound_statement                                              { $$ = MkFunction(null, $1, null); ProcessFunctionBody($$, $2); $$.loc = @$;}
3565    ;
3566 function_definition_error:
3567      external_guess_declaration_specifiers declarator_function declaration_list compound_statement_error      { $$ = MkFunction($1, $2, $3); ProcessFunctionBody($$, $4); $$.loc = @$; $$.loc.end = $4.loc.end; }
3568         | external_guess_declaration_specifiers declarator_function compound_statement_error                       { $$ = MkFunction($1, $2, null); ProcessFunctionBody($$, $3); $$.loc = @$; $$.loc.end = $3.loc.end; }
3569    | 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; }
3570         | external_guess_declaration_specifiers declarator_function_type_ok compound_statement_error                       { $$ = MkFunction($1, $2, null); ProcessFunctionBody($$, $3); $$.loc = @$; $$.loc.end = $3.loc.end; }
3571         | declarator_function declaration_list compound_statement_error                             { $$ = MkFunction(null, $1, $2); ProcessFunctionBody($$, $3); $$.loc = @$; $$.loc.end = $3.loc.end; }
3572         | declarator_function compound_statement_error                                              { $$ = MkFunction(null, $1, null); ProcessFunctionBody($$, $2); $$.loc = @$; $$.loc.end = $2.loc.end; }
3573    ;
3574
3575 string_literal:
3576    STRING_LITERAL { $$ = CopyString(yytext); }
3577    | string_literal STRING_LITERAL 
3578    { 
3579       int len1 = strlen($1);
3580       int len2 = strlen(yytext);
3581       $$ = new byte[len1-1 + len2-1 + 1];
3582       memcpy($$, $1, len1-1);
3583       memcpy($$ + len1-1, yytext+1, len2);
3584       delete $1;
3585    }
3586    ;
3587
3588 external_declaration:
3589           function_definition { $$ = MkExternalFunction($1); $$.loc = @$; $1.declMode = declMode; declMode = defaultDeclMode; }
3590    | class               
3591       { $$ = MkExternalClass($1);  $$.loc = @$; $1.declMode = (declMode != defaultAccess) ? declMode : privateAccess; declMode = defaultDeclMode; }
3592
3593    | external_guess_declaration_specifiers class
3594       { $$ = MkExternalClass($2);  $$.loc = @$; $2.declMode = (declMode != defaultAccess) ? declMode : privateAccess; declMode = defaultDeclMode; FreeList($1, FreeSpecifier); }
3595
3596         | external_guess_declaration
3597       { $$ = MkExternalDeclaration($1);  $$.loc = @$; $1.declMode = declMode; declMode = defaultDeclMode; }
3598    | IMPORT string_literal { $$ = MkExternalImport($2, normalImport, (declMode != defaultAccess) ? declMode : privateAccess);  $$.loc = @$; }
3599    | IMPORT STATIC string_literal { $$ = MkExternalImport($3, staticImport, (declMode != defaultAccess) ? declMode : privateAccess);  $$.loc = @$; }
3600    | IMPORT identifier string_literal
3601    {
3602       bool isRemote = !strcmp($2.string, "remote");
3603       $$ = MkExternalImport($3, isRemote ? remoteImport : normalImport, (declMode != defaultAccess) ? declMode : privateAccess); 
3604       $$.loc = @$;
3605       FreeIdentifier($2);
3606       if(!isRemote)
3607          yyerror(); 
3608    }
3609    
3610    | ';' { $$ = null; }
3611
3612         | declaration_mode function_definition { $$ = MkExternalFunction($2); $$.loc = @$; $2.declMode = $1; declMode = defaultDeclMode; }
3613    | declaration_mode class               
3614       { $$ = MkExternalClass($2);  $$.loc = @$; $2.declMode = ($1 != defaultAccess) ? $1 : privateAccess; declMode = defaultDeclMode; }
3615         | declaration_mode external_guess_declaration         { $$ = MkExternalDeclaration($2); $$.loc = @$; $2.declMode = $1; declMode = defaultDeclMode; }
3616    | declaration_mode IMPORT string_literal { $$ = MkExternalImport($3, normalImport, ($1 != defaultAccess) ? $1 : privateAccess);  $$.loc = @$; declMode = defaultDeclMode; }
3617    | declaration_mode IMPORT STATIC string_literal { $$ = MkExternalImport($4, staticImport, ($1 != defaultAccess) ? $1 : privateAccess);  $$.loc = @$; declMode = defaultDeclMode; }
3618    | declaration_mode IMPORT identifier string_literal
3619    {
3620       bool isRemote = !strcmp($3.string, "remote");
3621       $$ = MkExternalImport($4, isRemote ? remoteImport : normalImport, ($1 != defaultAccess) ? $1 : privateAccess);
3622       $$.loc = @$;
3623       FreeIdentifier($3);
3624       declMode = defaultDeclMode;
3625       if(!isRemote)
3626          yyerror();  
3627    }
3628    | declaration_mode ':' { defaultDeclMode = $1; $$ = null; }
3629    | STATIC ':' { defaultDeclMode = staticAccess; $$ = null; }
3630    | NAMESPACE identifier { $$ = MkExternalNameSpace($2); $$.loc = @$; }
3631    | NAMESPACE strict_type { $$ = MkExternalNameSpace(MkIdentifier($2.name)); FreeSpecifier($2); $$.loc = @$; }
3632    | dbtable_definition { $$ = MkExternalDBTable($1); $$.loc = @$;  $1.declMode = (declMode != defaultAccess) ? declMode : privateAccess; declMode = defaultDeclMode; }
3633    | declaration_mode  dbtable_definition { $$ = MkExternalDBTable($2); $$.loc = @$;  $2.declMode = ($1 != defaultAccess) ? declMode : privateAccess; declMode = defaultDeclMode; }
3634    ;
3635
3636 external_declaration_error:
3637      class_error               { $$ = MkExternalClass($1);  $$.loc = $1.loc; $1.declMode = (declMode != defaultAccess) ? declMode : privateAccess; declMode = defaultDeclMode; }
3638    | external_guess_declaration_specifiers class_error
3639    {
3640       FreeList($1, FreeSpecifier);
3641       $$ = MkExternalClass($2);
3642       $$.loc = $2.loc;
3643       $2.declMode = (declMode != defaultAccess) ? declMode : privateAccess;
3644       declMode = defaultDeclMode;
3645    }
3646    | function_definition_error { $$ = MkExternalFunction($1); $$.loc = $1.loc;  $1.declMode = declMode; declMode = defaultDeclMode; }
3647
3648    | declaration_mode class_error               { $$ = MkExternalClass($2);  $$.loc = $2.loc; $2.declMode = ($1 != defaultAccess) ? $1 : privateAccess; declMode = defaultDeclMode; }
3649    | declaration_mode function_definition_error { $$ = MkExternalFunction($2); $$.loc = $2.loc; $2.declMode = $1; declMode = defaultDeclMode; }
3650
3651         | external_guess_declaration_error
3652       { $$ = MkExternalDeclaration($1);  $$.loc = @$; $1.declMode = declMode; declMode = defaultDeclMode; }
3653    | declaration_mode external_guess_declaration_error         { $$ = MkExternalDeclaration($2); $$.loc = @$; $2.declMode = $1; declMode = defaultDeclMode; }
3654    ;
3655
3656 translation_unit_error:
3657      external_declaration_error                    { $$ = MkList(); ListAdd($$, $1); ast = $$; }
3658    | translation_unit external_declaration_error   { $$ = $1; ListAdd($1, $2); }
3659    | translation_unit_error external_declaration_error   { $$ = $1; ListAdd($1, $2); }
3660    | translation_unit error
3661    | translation_unit_error error
3662         ;
3663
3664 translation_unit:
3665           external_declaration                    { $$ = MkList(); ListAdd($$, $1); ast = $$; }
3666         | translation_unit external_declaration   { $$ = $1; ListAdd($1, $2); }
3667    | translation_unit_error class  
3668       { External _class = MkExternalClass($2); $$ = $1; ListAdd($1, _class); _class.loc = @2;  $2.declMode = (declMode != defaultAccess) ? declMode : privateAccess; declMode = defaultDeclMode; }
3669    | translation_unit_error declaration_mode class
3670       { External _class = MkExternalClass($3); $$ = $1; ListAdd($1, _class); _class.loc = @3;  $3.declMode = ($2 != defaultAccess) ? $2 : privateAccess; declMode = defaultDeclMode; }
3671         ;
3672
3673 thefile:
3674    translation_unit
3675    | translation_unit_error
3676    | { ast = MkList(); }
3677    ;
3678
3679 dbtable_definition:
3680      DBTABLE string_literal identifier   '{' dbfield_definition_list '}' { Symbol symbol = DeclClassAddNameSpace(globalContext.nextID++, $3.string); FreeIdentifier($3); $$ = MkDBTableDef($2, symbol, $5); }
3681    | DBTABLE string_literal strict_type  '{' dbfield_definition_list '}' { Symbol symbol = DeclClass(globalContext.nextID++, $3.name); FreeSpecifier($3); $$ = MkDBTableDef($2, symbol, $5); }
3682    | DBTABLE string_literal '{' dbfield_definition_list '}' { $$ = MkDBTableDef($2, null, $4); }
3683    ;
3684
3685 dbfield_entry:
3686    guess_declaration_specifiers identifier string_literal ';' { $$ = MkDBFieldEntry(MkTypeName($1, null), $2, $3); }
3687    ;
3688
3689 dbindex_item:
3690      identifier      { $$ = MkDBIndexItem($1, ascending); }
3691    | '>' identifier  { $$ = MkDBIndexItem($2, descending); }
3692    | '<' identifier  { $$ = MkDBIndexItem($2, ascending); }
3693    ;
3694
3695 dbindex_item_list:
3696      dbindex_item                         { $$ = MkList(); ListAdd($$, $1); }
3697    | dbindex_item_list ',' dbindex_item   { ListAdd($1, $3); }
3698    ;
3699
3700 dbindex_entry:
3701      DBINDEX dbindex_item_list ';'             { $$ = MkDBIndexEntry($2, null); }
3702    | DBINDEX dbindex_item_list identifier ';'  { $$ = MkDBIndexEntry($2, $3); }
3703    ;
3704
3705 dbfield_definition_list:
3706      dbfield_entry                           { $$ = MkList(); ListAdd($$, $1); }
3707    | dbindex_entry                           { $$ = MkList(); ListAdd($$, $1); }
3708    | dbfield_definition_list dbfield_entry   { ListAdd($1, $2); }
3709    | dbfield_definition_list dbindex_entry   { ListAdd($1, $2); }
3710    ;
3711
3712 database_open:
3713    DATABASE_OPEN '(' assignment_expression ',' assignment_expression ')'     { $$ = MkExpDBOpen($3, $5); }      
3714    ;
3715
3716 dbfield:
3717    DBFIELD '(' string_literal ',' identifier ')'      { $$ = MkExpDBField($3, $5); }
3718    ;
3719
3720 dbindex:
3721    DBINDEX '(' string_literal ',' identifier ')'      { $$ = MkExpDBIndex($3, $5); }
3722    ;
3723
3724 dbtable:
3725    DBTABLE '(' string_literal ')'                     { $$ = MkExpDBTable($3); }
3726    ;
3727
3728 %%