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