1 /** Lemon grammar for Express parser, based on SCL's expparse.y.  */
2 %include {
3 #include <assert.h>
4 #include "token_type.h"
5 #include "parse_data.h"
6 
7 int yyerrstatus = 0;
8 #define yyerrok (yyerrstatus = 0)
9 
10 YYSTYPE yylval;
11 
12     /*
13      * YACC grammar for Express parser.
14      *
15      * This software was developed by U.S. Government employees as part of
16      * their official duties and is not subject to copyright.
17      *
18      * $Log: expparse.y,v $
19      * Revision 1.23  1997/11/14 17:09:04  libes
20      * allow multiple group references
21      *
22      * ** 22 older revision log records removed 3 January 2014 **
23      */
24 
25 #include "express/symbol.h"
26 #include "express/linklist.h"
27 #include "stack.h"
28 #include "express/express.h"
29 #include "express/schema.h"
30 #include "express/entity.h"
31 #include "express/resolve.h"
32 #include "expscan.h"
33 #include <float.h>
34 
35     extern int print_objects_while_running;
36 
37     int tag_count;    /**< use this to count tagged GENERIC types in the formal
38                          * argument lists.  Gross, but much easier to do it this
39                          * way then with the 'help' of yacc. Set it to -1 to
40                          * indicate that tags cannot be defined, only used
41                          * (outside of formal parameter list, i.e. for return
42                          * types). Hey, as long as there's a gross hack sitting
43                          * around, we might as well milk it for all it's worth!
44                          *   - snc
45                          */
46 
47     int local_var_count; /**< used to keep LOCAL variables in order
48                             * used in combination with Variable.offset
49                             */
50 
51     Express yyexpresult;    /* hook to everything built by parser */
52 
53     Symbol *interface_schema;    /* schema of interest in use/ref clauses */
54     void (*interface_func)();    /* func to attach rename clauses */
55 
56     /* record schemas found in a single parse here, allowing them to be */
57     /* differentiated from other schemas parsed earlier */
58     Linked_List PARSEnew_schemas;
59 
60     void SCANskip_to_end_schema(perplex_t scanner);
61 
62     int yylineno;
63 
64     bool yyeof = false;
65 
66 #define MAX_SCOPE_DEPTH    20    /* max number of scopes that can be nested */
67 
68     static struct scope {
69         struct Scope_ *this_;
70         char type;    /* one of OBJ_XXX */
71         struct scope *pscope;    /* pointer back to most recent scope */
72         /* that has a printable name - for better */
73         /* error messages */
74     } scopes[MAX_SCOPE_DEPTH], *scope;
75 #define CURRENT_SCOPE (scope->this_)
76 #define PREVIOUS_SCOPE ((scope-1)->this_)
77 #define CURRENT_SCHEMA (scope->this_->u.schema)
78 #define CURRENT_SCOPE_NAME        (OBJget_symbol(scope->pscope->this_,scope->pscope->type)->name)
79 #define CURRENT_SCOPE_TYPE_PRINTABLE    (OBJget_type(scope->pscope->type))
80 
81     /* ths = new scope to enter */
82     /* sym = name of scope to enter into parent.  Some scopes (i.e., increment) */
83     /*       are not named, in which case sym should be 0 */
84     /*     This is useful for when a diagnostic is printed, an earlier named */
85     /*      scoped can be used */
86     /* typ = type of scope */
87 #define PUSH_SCOPE(ths,sym,typ) \
88     if (sym) DICTdefine(scope->this_->symbol_table,(sym)->name,(Generic)ths,sym,typ);\
89     ths->superscope = scope->this_; \
90     scope++;        \
91     scope->type = typ;    \
92     scope->pscope = (sym?scope:(scope-1)->pscope); \
93     scope->this_ = ths; \
94     if (sym) { \
95         ths->symbol = *(sym); \
96     }
97 #define POP_SCOPE() scope--
98 
99     /* PUSH_SCOPE_DUMMY just pushes the scope stack with nothing actually on it */
100     /* Necessary for situations when a POP_SCOPE is unnecessary but inevitable */
101 #define PUSH_SCOPE_DUMMY() scope++
102 
103     /* normally the superscope is added by PUSH_SCOPE, but some things (types) */
104     /* bother to get pushed so fix them this way */
105 #define SCOPEadd_super(ths) ths->superscope = scope->this_;
106 
107 #define ERROR(code)    ERRORreport(code, yylineno)
108 
parserInitState()109 void parserInitState()
110 {
111     scope = scopes;
112     /* no need to define scope->this */
113     scope->this_ = yyexpresult;
114     scope->pscope = scope;
115     scope->type = OBJ_EXPRESS;
116     yyexpresult->symbol.name = yyexpresult->u.express->filename;
117     yyexpresult->symbol.filename = yyexpresult->u.express->filename;
118     yyexpresult->symbol.line = 1;
119 }
120 } /* include */
121 
122 %extra_argument { parse_data_t parseData }
123 
124 %destructor statement_list {
125     if (parseData.scanner == NULL) {
126     $$.string = (char*)NULL;
127     }
128 }
129 
130 %type case_action            { Case_Item }
131 %type case_otherwise            { Case_Item }
132 %type entity_body            { struct entity_body }
133 
134 %type aggregate_init_element        { Expression }
135 %type aggregate_initializer        { Expression }
136 %type assignable            { Expression }
137 %type attribute_decl            { Expression }
138 %type by_expression            { Expression }
139 %type constant                { Expression }
140 %type expression            { Expression }
141 %type function_call            { Expression }
142 %type general_ref            { Expression }
143 %type group_ref                { Expression }
144 %type identifier            { Expression }
145 %type initializer            { Expression }
146 %type interval                { Expression }
147 %type literal                { Expression }
148 %type local_initializer            { Expression }
149 %type precision_spec            { Expression }
150 %type query_expression            { Expression }
151 %type query_start            { Expression }
152 %type simple_expression            { Expression }
153 %type unary_expression            { Expression }
154 %type supertype_expression        { Expression }
155 %type until_control            { Expression }
156 %type while_control            { Expression }
157 
158 %type function_header            { Integer }
159 %type fh_lineno                { Integer }
160 %type rule_header            { Integer }
161 %type rh_start                { Integer }
162 %type rh_get_line            { Integer }
163 %type procedure_header            { Integer }
164 %type ph_get_line            { Integer }
165 
166 %type action_body            { Linked_List }
167 %type actual_parameters            { Linked_List }
168 %type aggregate_init_body        { Linked_List }
169 %type explicit_attr_list        { Linked_List }
170 %type case_action_list            { Linked_List }
171 %type case_block            { Linked_List }
172 %type case_labels            { Linked_List }
173 %type where_clause_list            { Linked_List }
174 %type derive_decl            { Linked_List }
175 %type explicit_attribute        { Linked_List }
176 %type expression_list            { Linked_List }
177 %type formal_parameter            { Linked_List }
178 %type formal_parameter_list        { Linked_List }
179 %type formal_parameter_rep        { Linked_List }
180 %type id_list                { Linked_List }
181 %type defined_type_list            { Linked_List }
182 %type nested_id_list            { Linked_List }
183 /*repeat_control_list*/
184 %type statement_rep            { Linked_List }
185 %type subtype_decl            { Linked_List }
186 %type where_rule            { Linked_List }
187 %type where_rule_OPT            { Linked_List }
188 %type supertype_expression_list        { Linked_List }
189 %type labelled_attrib_list_list        { Linked_List }
190 %type labelled_attrib_list        { Linked_List }
191 %type inverse_attr_list            { Linked_List }
192 
193 %type inverse_clause            { Linked_List }
194 %type attribute_decl_list        { Linked_List }
195 %type derived_attribute_rep        { Linked_List }
196 %type unique_clause            { Linked_List }
197 %type rule_formal_parameter_list    { Linked_List }
198 %type qualified_attr_list        { Linked_List }
199 /* remove labelled_attrib_list if this works */
200 
201 %type rel_op            { Op_Code }
202 
203 %type optional_or_unique    { struct type_flags }
204 %type optional_fixed        { struct type_flags }
205 %type optional            { struct type_flags }
206 %type var            { struct type_flags }
207 %type unique            { struct type_flags }
208 
209 %type qualified_attr        { Expression }
210 
211 %type qualifier            { struct qualifier }
212 
213 %type alias_statement        { Statement }
214 %type assignment_statement    { Statement }
215 %type case_statement        { Statement }
216 %type compound_statement    { Statement }
217 %type escape_statement        { Statement }
218 %type if_statement        { Statement }
219 %type proc_call_statement    { Statement }
220 %type repeat_statement        { Statement }
221 %type return_statement        { Statement }
222 %type skip_statement        { Statement }
223 %type statement            { Statement }
224 
225 %type subsuper_decl        { struct subsuper_decl }
226 
227 %type supertype_decl        { struct subtypes }
228 %type supertype_factor        { struct subtypes }
229 
230 %type function_id        { Symbol* }
231 %type procedure_id        { Symbol* }
232 
233 %type attribute_type        { Type }
234 %type defined_type        { Type }
235 %type parameter_type        { Type }
236 %type generic_type        { Type }
237 
238 %type basic_type        { TypeBody }
239 %type select_type        { TypeBody }
240 %type aggregate_type        { TypeBody }
241 %type aggregation_type        { TypeBody }
242 %type array_type        { TypeBody }
243 %type bag_type            { TypeBody }
244 %type conformant_aggregation    { TypeBody }
245 %type list_type            { TypeBody }
246 %type set_type            { TypeBody }
247 
248 %type set_or_bag_of_entity    { struct type_either }
249 %type type            { struct type_either }
250 
251 %type cardinality_op        { struct upper_lower }
252 %type bound_spec        { struct upper_lower }
253 
254 %type inverse_attr        { Variable }
255 %type derived_attribute        { Variable }
256 %type rule_formal_parameter    { Variable }
257 
258 %type where_clause        { Where }
259 
260 
261 %left    TOK_EQUAL
262     TOK_GREATER_EQUAL
263     TOK_GREATER_THAN
264     TOK_IN
265     TOK_INST_EQUAL
266     TOK_INST_NOT_EQUAL
267     TOK_LESS_EQUAL
268     TOK_LESS_THAN
269     TOK_LIKE TOK_NOT_EQUAL.
270 
271 %left    TOK_MINUS
272     TOK_PLUS
273     TOK_OR
274     TOK_XOR.
275 
276 %left    TOK_DIV
277     TOK_MOD
278     TOK_REAL_DIV
279     TOK_TIMES
280     TOK_AND
281     TOK_ANDOR
282     TOK_CONCAT_OP.
283 
284 %right TOK_EXP.
285 
286 %left TOK_NOT.
287 
288 %nonassoc    TOK_DOT
289         TOK_BACKSLASH
290         TOK_LEFT_BRACKET.
291 
292 %start_symbol express_file
293 
294 %token_type { YYSTYPE }
295 
296 action_body(A) ::= action_body_item_rep statement_rep(B).
297 {
298     A = B;
299 }
300 
301 /* this should be rewritten to force order, see comment on next production */
302 action_body_item(A) ::= declaration(B).
303 {
304     A = B;
305 }
306 action_body_item(A) ::= constant_decl(B).
307 {
308     A = B;
309 }
310 action_body_item(A) ::= local_decl(B).
311 {
312     A = B;
313 }
314 
315 /* this corresponds to 'algorithm_head' in N14-ese but it should be rewritten
316  * to force declarations followed by constants followed by local_decls
317  */
318 action_body_item_rep ::= /* NULL item */.
319 action_body_item_rep(A) ::= action_body_item(B) action_body_item_rep.
320 {
321     A = B;
322 }
323 
324 /* NOTE: can actually go to NULL, but it's a semantic problem */
325 /* to disambiguate this from a simple identifier, so let a call */
326 /* with no parameters be parsed as an identifier for now. */
327 
328 /* another problem is that x() is always an entity. func/proc calls
329  * with no args are called as "x".  By the time resolution occurs
330  * and we find out whether or not x is an entity or func/proc, we will
331  * no longer have the information about whether there were parens!
332  */
333 
334 /* EXPRESS is simply wrong to handle these two cases differently. */
335 
336 actual_parameters(A) ::= TOK_LEFT_PAREN expression_list(B) TOK_RIGHT_PAREN.
337 {
338     A = B;
339 }
340 actual_parameters(A) ::= TOK_LEFT_PAREN TOK_RIGHT_PAREN.
341 {
342     A = 0;
343 }
344 
345 /* I give up - why does 2nd parm of AGGR_LIT have to be non-null?  */
346 aggregate_initializer(A) ::= TOK_LEFT_BRACKET TOK_RIGHT_BRACKET.
347 {
348     A = EXPcreate(Type_Aggregate);
349     A->u.list = LISTcreate();
350 }
351 aggregate_initializer(A) ::= TOK_LEFT_BRACKET aggregate_init_body(B)
352 TOK_RIGHT_BRACKET.
353 {
354     A = EXPcreate(Type_Aggregate);
355     A->u.list = B;
356 }
357 
358 aggregate_init_element(A) ::= expression(B).
359 {
360     A = B;
361 }
362 
363 aggregate_init_body(A) ::= aggregate_init_element(B).
364 {
365     A = LISTcreate();
366     LISTadd_last(A, (Generic)B);
367 }
368 aggregate_init_body(A) ::= aggregate_init_element(B) TOK_COLON expression(C).
369 {
370     A = LISTcreate();
371     LISTadd_last(A, (Generic)B);
372 
373     LISTadd_last(A, (Generic)C);
374 
375     C->type = Type_Repeat;
376 }
377 aggregate_init_body(A) ::= aggregate_init_body(B) TOK_COMMA
378                 aggregate_init_element(C).
379 {
380     A = B;
381 
382     LISTadd_last(A, (Generic)C);
383 
384 }
385 aggregate_init_body(A) ::= aggregate_init_body(B) TOK_COMMA
386                 aggregate_init_element(C) TOK_COLON expression(D).
387 {
388     A = B;
389 
390     LISTadd_last(A, (Generic)C);
391     LISTadd_last(A, (Generic)D);
392 
393     D->type = Type_Repeat;
394 }
395 
396 aggregate_type(A) ::= TOK_AGGREGATE TOK_OF parameter_type(B).
397 {
398     A = TYPEBODYcreate(aggregate_);
399     A->base = B;
400 
401     if (tag_count < 0) {
402         Symbol sym;
403         sym.line = yylineno;
404         sym.filename = current_filename;
405         ERRORreport_with_symbol(ERROR_unlabelled_param_type, &sym,
406         CURRENT_SCOPE_NAME);
407     }
408 }
409 aggregate_type(A) ::= TOK_AGGREGATE TOK_COLON TOK_IDENTIFIER(B) TOK_OF
410                parameter_type(C).
411 {
412     Type t = TYPEcreate_user_defined_tag(C, CURRENT_SCOPE, B.symbol);
413 
414     if (t) {
415         SCOPEadd_super(t);
416         A = TYPEBODYcreate(aggregate_);
417         A->tag = t;
418         A->base = C;
419     }
420 }
421 
422 aggregation_type(A) ::= array_type(B).
423 {
424     A = B;
425 }
426 aggregation_type(A) ::= bag_type(B).
427 {
428     A = B;
429 }
430 aggregation_type(A) ::= list_type(B).
431 {
432     A = B;
433 }
434 aggregation_type(A) ::= set_type(B).
435 {
436     A = B;
437 }
438 
439 alias_statement(A) ::= TOK_ALIAS TOK_IDENTIFIER(B) TOK_FOR general_ref(C)
440             semicolon alias_push_scope statement_rep(D)
441             TOK_END_ALIAS semicolon.
442 {
443     Expression e = EXPcreate_from_symbol(Type_Attribute, B.symbol);
444     Variable v = VARcreate(e, Type_Unknown);
445 
446     v->initializer = C;
447 
448     DICTdefine(CURRENT_SCOPE->symbol_table, B.symbol->name, (Generic)v,
449         B.symbol, OBJ_VARIABLE);
450     A = ALIAScreate(CURRENT_SCOPE, v, D);
451 
452     POP_SCOPE();
453 }
454 
455 alias_push_scope ::= /* subroutine */.
456 {
457     struct Scope_ *s = SCOPEcreate_tiny(OBJ_ALIAS);
458     PUSH_SCOPE(s, (Symbol *)0, OBJ_ALIAS);
459 }
460 
461 array_type(A) ::= TOK_ARRAY bound_spec(B) TOK_OF optional_or_unique(C)
462            attribute_type(D).
463 {
464     A = TYPEBODYcreate(array_);
465 
466     A->flags.optional = C.optional;
467     A->flags.unique = C.unique;
468     A->upper = B.upper_limit;
469     A->lower = B.lower_limit;
470     A->base = D;
471 }
472 
473 /* this is anything that can be assigned to */
474 assignable(A) ::= assignable(B) qualifier(C).
475 {
476     C.first->e.op1 = B;
477     A = C.expr;
478 }
479 assignable(A) ::= identifier(B).
480 {
481     A = B;
482 }
483 
484 assignment_statement(A) ::= assignable(B) TOK_ASSIGNMENT expression(C)
485                 semicolon.
486 {
487     A = ASSIGNcreate(B, C);
488 }
489 
490 attribute_type(A) ::= aggregation_type(B).
491 {
492     A = TYPEcreate_from_body_anonymously(B);
493     SCOPEadd_super(A);
494 }
495 attribute_type(A) ::= basic_type(B).
496 {
497     A = TYPEcreate_from_body_anonymously(B);
498     SCOPEadd_super(A);
499 }
500 attribute_type(A) ::= defined_type(B).
501 {
502     A = B;
503 }
504 
505 explicit_attr_list(A) ::= /* NULL body */.
506 {
507     A = LISTcreate();
508 }
509 explicit_attr_list(A) ::= explicit_attr_list(B) explicit_attribute(C).
510 {
511     A = B;
512     LISTadd_last(A, (Generic)C);
513 }
514 
515 bag_type(A) ::= TOK_BAG bound_spec(B) TOK_OF attribute_type(C).
516 {
517     A = TYPEBODYcreate(bag_);
518     A->base = C;
519     A->upper = B.upper_limit;
520     A->lower = B.lower_limit;
521 }
522 bag_type(A) ::= TOK_BAG TOK_OF attribute_type(B).
523 {
524     A = TYPEBODYcreate(bag_);
525     A->base = B;
526 }
527 
528 basic_type(A) ::= TOK_BOOLEAN.
529 {
530     A = TYPEBODYcreate(boolean_);
531 }
532 basic_type(A) ::= TOK_INTEGER precision_spec(B).
533 {
534     A = TYPEBODYcreate(integer_);
535     A->precision = B;
536 }
537 basic_type(A) ::= TOK_REAL precision_spec(B).
538 {
539     A = TYPEBODYcreate(real_);
540     A->precision = B;
541 }
542 basic_type(A) ::= TOK_NUMBER.
543 {
544     A = TYPEBODYcreate(number_);
545 }
546 basic_type(A) ::= TOK_LOGICAL.
547 {
548     A = TYPEBODYcreate(logical_);
549 }
550 basic_type(A) ::= TOK_BINARY precision_spec(B) optional_fixed(C).
551 {
552     A = TYPEBODYcreate(binary_);
553     A->precision = B;
554     A->flags.fixed = C.fixed;
555 }
556 basic_type(A) ::= TOK_STRING precision_spec(B) optional_fixed(C).
557 {
558     A = TYPEBODYcreate(string_);
559     A->precision = B;
560     A->flags.fixed = C.fixed;
561 }
562 
563 block_list ::= /* NULL */.
564 block_list(A) ::= block_list(B) block_member.
565 {
566     A = B;
567 }
568 
569 block_member(A) ::= declaration(B).
570 {
571     A = B;
572 }
573 block_member(A) ::= include_directive(B).
574 {
575     A = B;
576 }
577 block_member(A) ::= rule_decl(B).
578 {
579     A = B;
580 }
581 
582 by_expression(A) ::= /* NULL by_expression */.
583 {
584     A = LITERAL_ONE;
585 }
586 by_expression(A) ::= TOK_BY expression(B).
587 {
588     A = B;
589 }
590 
591 cardinality_op(A) ::= TOK_LEFT_CURL expression(B) TOK_COLON expression(C)
592                TOK_RIGHT_CURL.
593 {
594     A.lower_limit = B;
595     A.upper_limit = C;
596 }
597 
598 case_action(A) ::= case_labels(B) TOK_COLON statement(C).
599 {
600     A = CASE_ITcreate(B, C);
601     SYMBOLset(A);
602 }
603 
604 case_action_list(A) ::= /* no case_actions */.
605 {
606     A = LISTcreate();
607 }
608 case_action_list(A) ::= case_action_list(B) case_action(C).
609 {
610     yyerrok;
611 
612     A = B;
613 
614     LISTadd_last(A, (Generic)C);
615 }
616 
617 case_block(A) ::= case_action_list(B) case_otherwise(C).
618 {
619     A = B;
620 
621     if (C) {
622         LISTadd_last(A,
623         (Generic)C);
624     }
625 }
626 
627 case_labels(A) ::= expression(B).
628 {
629     A = LISTcreate();
630 
631     LISTadd_last(A, (Generic)B);
632 }
633 case_labels(A) ::= case_labels(B) TOK_COMMA expression(C).
634 {
635     yyerrok;
636 
637     A = B;
638     LISTadd_last(A, (Generic)C);
639 }
640 
641 case_otherwise(A) ::= /* no otherwise clause */.
642 {
643     A = (Case_Item)0;
644 }
645 case_otherwise(A) ::= TOK_OTHERWISE TOK_COLON statement(B).
646 {
647     A = CASE_ITcreate(LIST_NULL, B);
648     SYMBOLset(A);
649 }
650 
651 case_statement(A) ::= TOK_CASE expression(B) TOK_OF case_block(C) TOK_END_CASE
652               semicolon.
653 {
654     A = CASEcreate(B, C);
655 }
656 
657 compound_statement(A) ::= TOK_BEGIN statement_rep(B) TOK_END semicolon.
658 {
659     A = COMP_STMTcreate(B);
660 }
661 
662 constant(A) ::= TOK_PI.
663 {
664     A = LITERAL_PI;
665 }
666 
667 constant(A) ::= TOK_E.
668 {
669     A = LITERAL_E;
670 }
671 
672 /* package this up as an attribute */
673 constant_body ::= identifier(A) TOK_COLON attribute_type(B) TOK_ASSIGNMENT
674     expression(C) semicolon.
675 {
676     Variable v;
677 
678     A->type = B;
679     v = VARcreate(A, B);
680     v->initializer = C;
681     v->flags.constant = 1;
682     DICTdefine(CURRENT_SCOPE->symbol_table, A->symbol.name, (Generic)v,
683     &A->symbol, OBJ_VARIABLE);
684 }
685 
686 constant_body_list ::= /* NULL */.
687 constant_body_list(A) ::= constant_body(B) constant_body_list.
688 {
689     A = B;
690 }
691 
692 constant_decl(A) ::= TOK_CONSTANT(B) constant_body_list TOK_END_CONSTANT
693              semicolon.
694 {
695     A = B;
696 }
697 
698 declaration(A) ::= entity_decl(B).
699 {
700     A = B;
701 }
702 declaration(A) ::= function_decl(B).
703 {
704     A = B;
705 }
706 declaration(A) ::= procedure_decl(B).
707 {
708     A = B;
709 }
710 declaration(A) ::= type_decl(B).
711 {
712     A = B;
713 }
714 
715 derive_decl(A) ::= /* NULL body */.
716 {
717     A = LISTcreate();
718 }
719 derive_decl(A) ::= TOK_DERIVE derived_attribute_rep(B).
720 {
721     A = B;
722 }
723 
724 derived_attribute(A) ::= attribute_decl(B) TOK_COLON attribute_type(C)
725              initializer(D) semicolon.
726 {
727     A = VARcreate(B, C);
728     A->initializer = D;
729     A->flags.attribute = true;
730 }
731 
732 derived_attribute_rep(A) ::= derived_attribute(B).
733 {
734     A = LISTcreate();
735     LISTadd_last(A, (Generic)B);
736 }
737 derived_attribute_rep(A) ::= derived_attribute_rep(B) derived_attribute(C).
738 {
739     A = B;
740     LISTadd_last(A, (Generic)C);
741 }
742 
743 entity_body(A) ::= explicit_attr_list(B) derive_decl(C) inverse_clause(D)
744            unique_clause(E) where_rule_OPT(F).
745 {
746     A.attributes = B;
747     /* this is flattened out in entity_decl - DEL */
748     LISTadd_last(A.attributes, (Generic)C);
749 
750     if (D != LIST_NULL) {
751     LISTadd_last(A.attributes, (Generic)D);
752     }
753 
754     A.unique = E;
755     A.where = F;
756 }
757 
758 entity_decl ::= entity_header subsuper_decl(A) semicolon entity_body(B)
759         TOK_END_ENTITY semicolon.
760 {
761     CURRENT_SCOPE->u.entity->subtype_expression = A.subtypes;
762     CURRENT_SCOPE->u.entity->supertype_symbols = A.supertypes;
763     LISTdo( B.attributes, l, Linked_List ) {
764         LISTdo_n( l, a, Variable, b ) {
765             ENTITYadd_attribute(CURRENT_SCOPE, a);
766         } LISTod;
767     } LISTod;
768     CURRENT_SCOPE->u.entity->abstract = A.abstract;
769     CURRENT_SCOPE->u.entity->unique = B.unique;
770     CURRENT_SCOPE->where = B.where;
771     POP_SCOPE();
772 }
773 
774 entity_header ::= TOK_ENTITY TOK_IDENTIFIER(A).
775 {
776     Entity e = ENTITYcreate(A.symbol);
777 
778     if (print_objects_while_running & OBJ_ENTITY_BITS) {
779     fprintf( stderr, "parse: %s (entity)\n", A.symbol->name);
780     }
781 
782     PUSH_SCOPE(e, A.symbol, OBJ_ENTITY);
783 }
784 
785 enumeration_type ::= TOK_ENUMERATION TOK_OF nested_id_list(A).
786 {
787     int value = 0;
788     Expression x;
789     Symbol *tmp;
790     TypeBody tb;
791     tb = TYPEBODYcreate(enumeration_);
792     CURRENT_SCOPE->u.type->head = 0;
793     CURRENT_SCOPE->u.type->body = tb;
794     tb->list = A;
795 
796     if (!CURRENT_SCOPE->symbol_table) {
797         CURRENT_SCOPE->symbol_table = DICTcreate(25);
798     }
799     if (!PREVIOUS_SCOPE->enum_table) {
800         PREVIOUS_SCOPE->enum_table = DICTcreate(25);
801     }
802     LISTdo_links(A, id) {
803         tmp = (Symbol *)id->data;
804         id->data = (Generic)(x = EXPcreate(CURRENT_SCOPE));
805         x->symbol = *(tmp);
806         x->u.integer = ++value;
807 
808         /* define both in enum scope and scope of */
809         /* 1st visibility */
810         DICT_define(CURRENT_SCOPE->symbol_table, x->symbol.name,
811             (Generic)x, &x->symbol, OBJ_EXPRESSION);
812         DICTdefine(PREVIOUS_SCOPE->enum_table, x->symbol.name,
813             (Generic)x, &x->symbol, OBJ_EXPRESSION);
814         SYMBOL_destroy(tmp);
815     } LISTod;
816 }
817 
818 escape_statement(A) ::= TOK_ESCAPE semicolon.
819 {
820     A = STATEMENT_ESCAPE;
821 }
822 
823 /* 10303-11:2004 production 177
824  * attribute_decl = attribute_id | redeclared_attribute .
825  *
826  * also
827  * 178 attribute_id = simple_id .
828  * 279 redeclared_attribute = qualified_attribute [ RENAMED attribute_id ] .
829  * 275 qualified_attribute = SELF group_qualifier attribute_qualifier .
830  *
831  * NOTE - production 279 isn't implemented
832  */
833 attribute_decl(A) ::= TOK_IDENTIFIER(B).
834 {
835     A = EXPcreate(Type_Attribute);
836     A->symbol = *B.symbol;
837     SYMBOL_destroy(B.symbol);
838 }
839 attribute_decl(A) ::= TOK_SELF TOK_BACKSLASH TOK_IDENTIFIER(B) TOK_DOT
840               TOK_IDENTIFIER(C).
841 {
842     A = EXPcreate(Type_Expression);
843     A->e.op1 = EXPcreate(Type_Expression);
844     A->e.op1->e.op_code = OP_GROUP;
845     A->e.op1->e.op1 = EXPcreate(Type_Self);
846     A->e.op1->e.op2 = EXPcreate_from_symbol(Type_Entity, B.symbol);
847     SYMBOL_destroy(B.symbol);
848 
849     A->e.op_code = OP_DOT;
850     A->e.op2 = EXPcreate_from_symbol(Type_Attribute, C.symbol);
851     SYMBOL_destroy(C.symbol);
852 }
853 
854 attribute_decl_list(A) ::= attribute_decl(B).
855 {
856     A = LISTcreate();
857     LISTadd_last(A, (Generic)B);
858 
859 }
860 attribute_decl_list(A) ::= attribute_decl_list(B) TOK_COMMA
861                attribute_decl(C).
862 {
863     A = B;
864     LISTadd_last(A, (Generic)C);
865 }
866 
867 optional(A) ::= /*NULL*/.
868 {
869     A.optional = 0;
870 }
871 optional(A) ::= TOK_OPTIONAL.
872 {
873     A.optional = 1;
874 }
875 
876 explicit_attribute(A) ::= attribute_decl_list(B) TOK_COLON optional(C)
877                attribute_type(D) semicolon.
878 {
879     Variable v;
880 
881     LISTdo_links (B, attr)
882     v = VARcreate((Expression)attr->data, D);
883     v->flags.optional = C.optional;
884     v->flags.attribute = true;
885     attr->data = (Generic)v;
886     LISTod;
887 
888     A = B;
889 }
890 
891 express_file ::= schema_decl_list.
892 
893 schema_decl_list(A) ::= schema_decl(B).
894 {
895     A = B;
896 }
897 schema_decl_list(A) ::= schema_decl_list(B) schema_decl.
898 {
899     A = B;
900 }
901 
902 expression(A) ::= simple_expression(B).
903 {
904     A = B;
905 }
906 expression(A) ::= expression(B) TOK_AND expression(C).
907 {
908     yyerrok;
909 
910     A = BIN_EXPcreate(OP_AND, B, C);
911 }
912 expression(A) ::= expression(B) TOK_OR expression(C).
913 {
914     yyerrok;
915 
916     A = BIN_EXPcreate(OP_OR, B, C);
917 }
918 expression(A) ::= expression(B) TOK_XOR expression(C).
919 {
920     yyerrok;
921 
922     A = BIN_EXPcreate(OP_XOR, B, C);
923 }
924 expression(A) ::= expression(B) TOK_LESS_THAN expression(C).
925 {
926     yyerrok;
927 
928     A = BIN_EXPcreate(OP_LESS_THAN, B, C);
929 }
930 expression(A) ::= expression(B) TOK_GREATER_THAN expression(C).
931 {
932     yyerrok;
933 
934     A = BIN_EXPcreate(OP_GREATER_THAN, B, C);
935 }
936 expression(A) ::= expression(B) TOK_EQUAL expression(C).
937 {
938     yyerrok;
939 
940     A = BIN_EXPcreate(OP_EQUAL, B, C);
941 }
942 expression(A) ::= expression(B) TOK_LESS_EQUAL expression(C).
943 {
944     yyerrok;
945 
946     A = BIN_EXPcreate(OP_LESS_EQUAL, B, C);
947 }
948 expression(A) ::= expression(B) TOK_GREATER_EQUAL expression(C).
949 {
950     yyerrok;
951 
952     A = BIN_EXPcreate(OP_GREATER_EQUAL, B, C);
953 }
954 expression(A) ::= expression(B) TOK_NOT_EQUAL expression(C).
955 {
956     yyerrok;
957 
958     A = BIN_EXPcreate(OP_NOT_EQUAL, B, C);
959 }
960 expression(A) ::= expression(B) TOK_INST_EQUAL expression(C).
961 {
962     yyerrok;
963 
964     A = BIN_EXPcreate(OP_INST_EQUAL, B, C);
965 }
966 expression(A) ::= expression(B) TOK_INST_NOT_EQUAL expression(C).
967 {
968     yyerrok;
969 
970     A = BIN_EXPcreate(OP_INST_NOT_EQUAL, B, C);
971 }
972 expression(A) ::= expression(B) TOK_IN expression(C).
973 {
974     yyerrok;
975 
976     A = BIN_EXPcreate(OP_IN, B, C);
977 }
978 expression(A) ::= expression(B) TOK_LIKE expression(C).
979 {
980     yyerrok;
981 
982     A = BIN_EXPcreate(OP_LIKE, B, C);
983 }
984 expression ::= simple_expression cardinality_op simple_expression.
985 {
986     yyerrok;
987 }
988 
989 simple_expression(A) ::= unary_expression(B).
990 {
991     A = B;
992 }
993 simple_expression(A) ::= simple_expression(B) TOK_CONCAT_OP
994              simple_expression(C).
995 {
996     yyerrok;
997 
998     A = BIN_EXPcreate(OP_CONCAT, B, C);
999 }
1000 simple_expression(A) ::= simple_expression(B) TOK_EXP simple_expression(C).
1001 {
1002     yyerrok;
1003 
1004     A = BIN_EXPcreate(OP_EXP, B, C);
1005 }
1006 simple_expression(A) ::= simple_expression(B) TOK_TIMES simple_expression(C).
1007 {
1008     yyerrok;
1009 
1010     A = BIN_EXPcreate(OP_TIMES, B, C);
1011 }
1012 simple_expression(A) ::= simple_expression(B) TOK_DIV simple_expression(C).
1013 {
1014     yyerrok;
1015 
1016     A = BIN_EXPcreate(OP_DIV, B, C);
1017 }
1018 simple_expression(A) ::= simple_expression(B) TOK_REAL_DIV simple_expression(C).
1019 {
1020     yyerrok;
1021 
1022     A = BIN_EXPcreate(OP_REAL_DIV, B, C);
1023 }
1024 simple_expression(A) ::= simple_expression(B) TOK_MOD simple_expression(C).
1025 {
1026     yyerrok;
1027 
1028     A = BIN_EXPcreate(OP_MOD, B, C);
1029 }
1030 simple_expression(A) ::= simple_expression(B) TOK_PLUS simple_expression(C).
1031 {
1032     yyerrok;
1033 
1034     A = BIN_EXPcreate(OP_PLUS, B, C);
1035 }
1036 simple_expression(A) ::= simple_expression(B) TOK_MINUS simple_expression(C).
1037 {
1038     yyerrok;
1039 
1040     A = BIN_EXPcreate(OP_MINUS, B, C);
1041 }
1042 
1043 expression_list(A) ::= expression(B).
1044 {
1045     A = LISTcreate();
1046     LISTadd_last(A, (Generic)B);
1047 }
1048 expression_list(A) ::= expression_list(B) TOK_COMMA expression(C).
1049 {
1050     A = B;
1051     LISTadd_last(A, (Generic)C);
1052 }
1053 
1054 var(A) ::= /* NULL */.
1055 {
1056     A.var = 0;
1057 }
1058 var(A) ::= TOK_VAR.
1059 {
1060     A.var = 1;
1061 }
1062 
1063 formal_parameter(A) ::= var(B) id_list(C) TOK_COLON parameter_type(D).
1064 {
1065     Symbol *tmp;
1066     Expression e;
1067     Variable v;
1068 
1069     A = C;
1070     LISTdo_links(A, param)
1071     tmp = (Symbol*)param->data;
1072 
1073     e = EXPcreate_from_symbol(Type_Attribute, tmp);
1074     v = VARcreate(e, D);
1075     v->flags.var = B.var; /* NOTE this was flags.optional... ?! */
1076     v->flags.parameter = true;
1077     param->data = (Generic)v;
1078 
1079     /* link it in to the current scope's dict */
1080     DICTdefine(CURRENT_SCOPE->symbol_table,
1081     tmp->name, (Generic)v, tmp, OBJ_VARIABLE);
1082 
1083     LISTod;
1084 }
1085 
1086 formal_parameter_list(A) ::= /* no parameters */.
1087 {
1088     A = LIST_NULL;
1089 }
1090 formal_parameter_list(A) ::= TOK_LEFT_PAREN formal_parameter_rep(B)
1091                  TOK_RIGHT_PAREN.
1092 {
1093     A = B;
1094 
1095 }
1096 
1097 formal_parameter_rep(A) ::= formal_parameter(B).
1098 {
1099     A = B;
1100 
1101 }
1102 formal_parameter_rep(A) ::= formal_parameter_rep(B) semicolon
1103                 formal_parameter(C).
1104 {
1105     A = B;
1106     LISTadd_all(A, C);
1107 }
1108 
1109 parameter_type(A) ::= basic_type(B).
1110 {
1111     A = TYPEcreate_from_body_anonymously(B);
1112     SCOPEadd_super(A);
1113 }
1114 parameter_type(A) ::= conformant_aggregation(B).
1115 {
1116     A = TYPEcreate_from_body_anonymously(B);
1117     SCOPEadd_super(A);
1118 }
1119 parameter_type(A) ::= defined_type(B).
1120 {
1121     A = B;
1122 }
1123 parameter_type(A) ::= generic_type(B).
1124 {
1125     A = B;
1126 }
1127 
1128 function_call(A) ::= function_id(B) actual_parameters(C).
1129 {
1130     A = EXPcreate(Type_Funcall);
1131     A->symbol = *B;
1132     SYMBOL_destroy(B);
1133     A->u.funcall.list = C;
1134 }
1135 
1136 function_decl ::= function_header(A) action_body(B) TOK_END_FUNCTION
1137           semicolon.
1138 {
1139     FUNCput_body(CURRENT_SCOPE, B);
1140     ALGput_full_text(CURRENT_SCOPE, A, SCANtell());
1141     POP_SCOPE();
1142 }
1143 
1144 function_header(A) ::= fh_lineno(B) fh_push_scope fh_plist TOK_COLON
1145                parameter_type(C) semicolon.
1146 {
1147     Function f = CURRENT_SCOPE;
1148 
1149     f->u.func->return_type = C;
1150     A = B;
1151 }
1152 
1153 fh_lineno(A) ::= TOK_FUNCTION.
1154 {
1155     A = SCANtell();
1156 }
1157 
1158 fh_push_scope ::= TOK_IDENTIFIER(A).
1159 {
1160     Function f = ALGcreate(OBJ_FUNCTION);
1161     tag_count = 0;
1162     if (print_objects_while_running & OBJ_FUNCTION_BITS) {
1163         fprintf( stderr, "parse: %s (function)\n", A.symbol->name);
1164     }
1165     PUSH_SCOPE(f, A.symbol, OBJ_FUNCTION);
1166 }
1167 
1168 fh_plist ::= formal_parameter_list(A).
1169 {
1170     Function f = CURRENT_SCOPE;
1171     f->u.func->parameters = A;
1172     f->u.func->pcount = LISTget_length(A);
1173     f->u.func->tag_count = tag_count;
1174     tag_count = -1;     /* done with parameters, no new tags can be defined */
1175 }
1176 
1177 function_id(A) ::= TOK_IDENTIFIER(B).
1178 {
1179     A = B.symbol;
1180 }
1181 function_id(A) ::= TOK_BUILTIN_FUNCTION(B).
1182 {
1183     A = B.symbol;
1184 
1185 }
1186 
1187 conformant_aggregation(A) ::= aggregate_type(B).
1188 {
1189     A = B;
1190 
1191 }
1192 conformant_aggregation(A) ::= TOK_ARRAY TOK_OF optional_or_unique(B)
1193                   parameter_type(C).
1194 {
1195     A = TYPEBODYcreate(array_);
1196     A->flags.optional = B.optional;
1197     A->flags.unique = B.unique;
1198     A->base = C;
1199 }
1200 conformant_aggregation(A) ::= TOK_ARRAY bound_spec(B) TOK_OF
1201     optional_or_unique(C) parameter_type(D).
1202 {
1203     A = TYPEBODYcreate(array_);
1204     A->flags.optional = C.optional;
1205     A->flags.unique = C.unique;
1206     A->base = D;
1207     A->upper = B.upper_limit;
1208     A->lower = B.lower_limit;
1209 }
1210 conformant_aggregation(A) ::= TOK_BAG TOK_OF parameter_type(B).
1211 {
1212     A = TYPEBODYcreate(bag_);
1213     A->base = B;
1214 
1215 }
1216 conformant_aggregation(A) ::= TOK_BAG bound_spec(B) TOK_OF parameter_type(C).
1217 {
1218     A = TYPEBODYcreate(bag_);
1219     A->base = C;
1220     A->upper = B.upper_limit;
1221     A->lower = B.lower_limit;
1222 }
1223 conformant_aggregation(A) ::= TOK_LIST TOK_OF unique(B) parameter_type(C).
1224 {
1225     A = TYPEBODYcreate(list_);
1226     A->flags.unique = B.unique;
1227     A->base = C;
1228 
1229 }
1230 conformant_aggregation(A) ::= TOK_LIST bound_spec(B) TOK_OF unique(C)
1231                   parameter_type(D).
1232 {
1233     A = TYPEBODYcreate(list_);
1234     A->base = D;
1235     A->flags.unique = C.unique;
1236     A->upper = B.upper_limit;
1237     A->lower = B.lower_limit;
1238 }
1239 conformant_aggregation(A) ::= TOK_SET TOK_OF parameter_type(B).
1240 {
1241     A = TYPEBODYcreate(set_);
1242     A->base = B;
1243 }
1244 conformant_aggregation(A) ::= TOK_SET bound_spec(B) TOK_OF parameter_type(C).
1245 {
1246     A = TYPEBODYcreate(set_);
1247     A->base = C;
1248     A->upper = B.upper_limit;
1249     A->lower = B.lower_limit;
1250 }
1251 
1252 generic_type(A) ::= TOK_GENERIC.
1253 {
1254     A = Type_Generic;
1255 
1256     if (tag_count < 0) {
1257         Symbol sym;
1258         sym.line = yylineno;
1259         sym.filename = current_filename;
1260         ERRORreport_with_symbol(ERROR_unlabelled_param_type, &sym,
1261         CURRENT_SCOPE_NAME);
1262     }
1263 }
1264 generic_type(A) ::= TOK_GENERIC TOK_COLON TOK_IDENTIFIER(B).
1265 {
1266     TypeBody g = TYPEBODYcreate(generic_);
1267     A = TYPEcreate_from_body_anonymously(g);
1268 
1269     SCOPEadd_super(A);
1270 
1271     g->tag = TYPEcreate_user_defined_tag(A, CURRENT_SCOPE, B.symbol);
1272     if (g->tag) {
1273         SCOPEadd_super(g->tag);
1274     }
1275 }
1276 
1277 id_list(A) ::= TOK_IDENTIFIER(B).
1278 {
1279     A = LISTcreate();
1280     LISTadd_last(A, (Generic)B.symbol);
1281 
1282 }
1283 id_list(A) ::= id_list(B) TOK_COMMA TOK_IDENTIFIER(C).
1284 {
1285     yyerrok;
1286 
1287     A = B;
1288     LISTadd_last(A, (Generic)C.symbol);
1289 }
1290 
1291 identifier(A) ::= TOK_SELF.
1292 {
1293     A = EXPcreate(Type_Self);
1294 }
1295 identifier(A) ::= TOK_QUESTION_MARK.
1296 {
1297     A = LITERAL_INFINITY;
1298 }
1299 identifier(A) ::= TOK_IDENTIFIER(B).
1300 {
1301     A = EXPcreate(Type_Identifier);
1302     A->symbol = *(B.symbol);
1303     SYMBOL_destroy(B.symbol);
1304 }
1305 
1306 if_statement(A) ::= TOK_IF expression(B) TOK_THEN statement_rep(C) TOK_END_IF
1307             semicolon.
1308 {
1309     A = CONDcreate(B, C, STATEMENT_LIST_NULL);
1310 }
1311 if_statement(A) ::= TOK_IF expression(B) TOK_THEN statement_rep(C) TOK_ELSE
1312     statement_rep(D) TOK_END_IF semicolon.
1313 {
1314     A = CONDcreate(B, C, D);
1315 }
1316 
1317 include_directive ::= TOK_INCLUDE TOK_STRING_LITERAL(A) semicolon.
1318 {
1319     SCANinclude_file(A.string);
1320 }
1321 
1322 increment_control ::= TOK_IDENTIFIER(A) TOK_ASSIGNMENT expression(B) TOK_TO
1323               expression(C) by_expression(D).
1324 {
1325     Increment i = INCR_CTLcreate(A.symbol, B, C, D);
1326 
1327     /* scope doesn't really have/need a name, I suppose */
1328     /* naming it by the iterator variable is fine */
1329 
1330     PUSH_SCOPE(i, (Symbol *)0, OBJ_INCREMENT);
1331 }
1332 
1333 initializer(A) ::= TOK_ASSIGNMENT expression(B).
1334 {
1335     A = B;
1336 }
1337 
1338 /* 10303-11:2004 production 259
1339  * named_type_or_rename = named_types [ AS ( entity_id | type_id ) ] .
1340  */
1341 rename ::= TOK_IDENTIFIER(A).
1342 {
1343     (*interface_func)(CURRENT_SCOPE, interface_schema, A, A);
1344 }
1345 rename ::= TOK_IDENTIFIER(A) TOK_AS TOK_IDENTIFIER(B).
1346 {
1347     (*interface_func)(CURRENT_SCOPE, interface_schema, A, B);
1348 }
1349 
1350 rename_list(A) ::= rename(B).
1351 {
1352     A = B;
1353 }
1354 rename_list(A) ::= rename_list(B) TOK_COMMA rename.
1355 {
1356     A = B;
1357 }
1358 
1359 /* 10303-11:2004 production 336
1360  * use_clause = USE FROM schema_ref [ ’(’ named_type_or_rename { ’,’ named_type_or_rename } ’)’ ] ’;’ .
1361  */
1362 parened_rename_list ::= TOK_LEFT_PAREN rename_list TOK_RIGHT_PAREN.
1363 
1364 reference_clause ::= TOK_REFERENCE TOK_FROM TOK_IDENTIFIER(A) semicolon.
1365 {
1366     if (!CURRENT_SCHEMA->ref_schemas) {
1367         CURRENT_SCHEMA->ref_schemas = LISTcreate();
1368     }
1369 
1370     LISTadd_last(CURRENT_SCHEMA->ref_schemas, (Generic)A.symbol);
1371 }
1372 reference_clause(A) ::= reference_head(B) parened_rename_list semicolon.
1373 {
1374     A = B;
1375 }
1376 
1377 reference_head ::= TOK_REFERENCE TOK_FROM TOK_IDENTIFIER(A).
1378 {
1379     interface_schema = A.symbol;
1380     interface_func = SCHEMAadd_reference;
1381 }
1382 
1383 use_clause ::= TOK_USE TOK_FROM TOK_IDENTIFIER(A) semicolon.
1384 {
1385     if (!CURRENT_SCHEMA->use_schemas) {
1386         CURRENT_SCHEMA->use_schemas = LISTcreate();
1387     }
1388 
1389     LISTadd_last(CURRENT_SCHEMA->use_schemas, (Generic)A.symbol);
1390 }
1391 use_clause(A) ::= use_head(B) parened_rename_list semicolon.
1392 {
1393     A = B;
1394 }
1395 
1396 use_head ::= TOK_USE TOK_FROM TOK_IDENTIFIER(A).
1397 {
1398     interface_schema = A.symbol;
1399     interface_func = SCHEMAadd_use;
1400 }
1401 
1402 interface_specification(A) ::= use_clause(B).
1403 {
1404     A = B;
1405 }
1406 interface_specification(A) ::= reference_clause(B).
1407 {
1408     A = B;
1409 }
1410 
1411 interface_specification_list ::= /*NULL*/.
1412 interface_specification_list(A) ::= interface_specification_list(B)
1413                     interface_specification.
1414 {
1415     A = B;
1416 }
1417 
1418 interval(A) ::= TOK_LEFT_CURL simple_expression(B) rel_op(C)
1419         simple_expression(D) rel_op(E) simple_expression(F) right_curl.
1420 {
1421     Expression    tmp1, tmp2;
1422 
1423     A = (Expression)0;
1424     tmp1 = BIN_EXPcreate(C, B, D);
1425     tmp2 = BIN_EXPcreate(E, D, F);
1426     A = BIN_EXPcreate(OP_AND, tmp1, tmp2);
1427 }
1428 
1429 /* defined_type might have to be something else since it's really an
1430  * entity_ref */
1431 set_or_bag_of_entity(A) ::= defined_type(B).
1432 {
1433     A.type = B;
1434     A.body = 0;
1435 }
1436 set_or_bag_of_entity(A) ::= TOK_SET TOK_OF defined_type(B).
1437 {
1438     A.type = 0;
1439     A.body = TYPEBODYcreate(set_);
1440     A.body->base = B;
1441 
1442 }
1443 set_or_bag_of_entity(A) ::= TOK_SET bound_spec(B) TOK_OF defined_type(C).
1444 {
1445     A.type = 0;
1446     A.body = TYPEBODYcreate(set_);
1447     A.body->base = C;
1448     A.body->upper = B.upper_limit;
1449     A.body->lower = B.lower_limit;
1450 }
1451 set_or_bag_of_entity(A) ::= TOK_BAG bound_spec(B) TOK_OF defined_type(C).
1452 {
1453     A.type = 0;
1454     A.body = TYPEBODYcreate(bag_);
1455     A.body->base = C;
1456     A.body->upper = B.upper_limit;
1457     A.body->lower = B.lower_limit;
1458 }
1459 set_or_bag_of_entity(A) ::= TOK_BAG TOK_OF defined_type(B).
1460 {
1461     A.type = 0;
1462     A.body = TYPEBODYcreate(bag_);
1463     A.body->base = B;
1464 }
1465 
1466 /* 10303-11:2004 production 249
1467  * inverse_clause = INVERSE inverse_attr { inverse_attr } .
1468  */
1469 inverse_attr_list(A) ::= inverse_attr(B).
1470 {
1471     A = LISTcreate();
1472     LISTadd_last(A, (Generic)B);
1473 }
1474 inverse_attr_list(A) ::= inverse_attr_list(B) inverse_attr(C).
1475 {
1476     A = B;
1477     LISTadd_last(A, (Generic)C);
1478 }
1479 
1480 /* 10303-11:2004 production 248
1481  * inverse_attr = attribute_decl ’:’ [ ( SET | BAG ) [ bound_spec ] OF ] entity_ref FOR [ entity_ref ’.’ ] attribute_ref ’;’ .
1482  *
1483  * NOTE - production 279 (RENAMED attr) isn't implemented
1484  */
1485 inverse_attr(A) ::= attribute_decl(B) TOK_COLON set_or_bag_of_entity(C)
1486             TOK_FOR TOK_IDENTIFIER(D) semicolon.
1487 {
1488     if (C.type) {
1489         A = VARcreate(B, C.type);
1490     } else {
1491         Type t = TYPEcreate_from_body_anonymously(C.body);
1492         SCOPEadd_super(t);
1493         A = VARcreate(B, t);
1494     }
1495 
1496     A->flags.attribute = true;
1497     A->inverse_symbol = D.symbol;
1498 }
1499 
1500 /* 10303-11:2004 production 249
1501  * inverse_clause = INVERSE inverse_attr { inverse_attr } .
1502  */
1503 inverse_clause(A) ::= /*NULL*/.
1504 {
1505     A = LIST_NULL;
1506 }
1507 inverse_clause(A) ::= TOK_INVERSE inverse_attr_list(B).
1508 {
1509     A = B;
1510 }
1511 
1512 /* 10303-11:2004 production 185 bound_spec = '[' bound_1 ':' bound_2 ']' . */
1513 bound_spec(A) ::= TOK_LEFT_BRACKET expression(B) TOK_COLON expression(C)
1514           TOK_RIGHT_BRACKET.
1515 {
1516     A.lower_limit = B;
1517     A.upper_limit = C;
1518 }
1519 
1520 list_type(A) ::= TOK_LIST bound_spec(B) TOK_OF unique(C) attribute_type(D).
1521 {
1522     A = TYPEBODYcreate(list_);
1523     A->base = D;
1524     A->flags.unique = C.unique;
1525     A->lower = B.lower_limit;
1526     A->upper = B.upper_limit;
1527 }
1528 list_type(A) ::= TOK_LIST TOK_OF unique(B) attribute_type(C).
1529 {
1530     A = TYPEBODYcreate(list_);
1531     A->base = C;
1532     A->flags.unique = B.unique;
1533 }
1534 
1535 literal(A) ::= TOK_INTEGER_LITERAL(B).
1536 {
1537     if (B.iVal == 0) {
1538         A = LITERAL_ZERO;
1539     } else if (B.iVal == 1) {
1540     A = LITERAL_ONE;
1541     } else {
1542     A = EXPcreate_simple(Type_Integer);
1543     A->u.integer = (int)B.iVal;
1544     resolved_all(A);
1545     }
1546 }
1547 literal(A) ::= TOK_REAL_LITERAL(B).
1548 {
1549     /* if rVal (a double) is nonzero and has magnitude <= the smallest non-denormal float, print a warning */
1550     if( ( fabs( B.rVal ) <= FLT_MIN ) && ( fabs( B.rVal ) > 0 ) ) {
1551         Symbol sym;
1552         sym.line = yylineno;
1553         sym.filename = current_filename;
1554         ERRORreport_with_symbol(ERROR_warn_small_real, &sym, B.rVal );
1555     }
1556     if( fabs( B.rVal ) < DBL_MIN ) {
1557         A = LITERAL_ZERO;
1558     } else {
1559         A = EXPcreate_simple(Type_Real);
1560         A->u.real = B.rVal;
1561         resolved_all(A);
1562     }
1563 }
1564 literal(A) ::= TOK_STRING_LITERAL(B).
1565 {
1566     A = EXPcreate_simple(Type_String);
1567     A->symbol.name = B.string;
1568     resolved_all(A);
1569 }
1570 literal(A) ::= TOK_STRING_LITERAL_ENCODED(B).
1571 {
1572     A = EXPcreate_simple(Type_String_Encoded);
1573     A->symbol.name = B.string;
1574     resolved_all(A);
1575 }
1576 literal(A) ::= TOK_LOGICAL_LITERAL(B).
1577 {
1578     A = EXPcreate_simple(Type_Logical);
1579     A->u.logical = B.logical;
1580     resolved_all(A);
1581 }
1582 literal(A) ::= TOK_BINARY_LITERAL(B).
1583 {
1584     A = EXPcreate_simple(Type_Binary);
1585     A->symbol.name = B.binary;
1586     resolved_all(A);
1587 }
1588 literal(A) ::= constant(B).
1589 {
1590     A = B;
1591 }
1592 
1593 local_initializer(A) ::= TOK_ASSIGNMENT expression(B).
1594 {
1595     A = B;
1596 }
1597 
1598 local_variable ::= id_list(A) TOK_COLON parameter_type(B) semicolon.
1599 {
1600     Expression e;
1601     Variable v;
1602     LISTdo(A, sym, Symbol *)
1603 
1604     /* convert symbol to name-expression */
1605 
1606     e = EXPcreate(Type_Attribute);
1607     e->symbol = *sym; SYMBOL_destroy(sym);
1608     v = VARcreate(e, B);
1609     v->offset = local_var_count++;
1610     DICTdefine(CURRENT_SCOPE->symbol_table, e->symbol.name, (Generic)v, &e->symbol, OBJ_VARIABLE);
1611     LISTod;
1612     LISTfree(A);
1613 }
1614 
1615 local_variable ::= id_list(A) TOK_COLON parameter_type(B) local_initializer(C) semicolon.
1616 {
1617     Expression e;
1618     Variable v;
1619     LISTdo(A, sym, Symbol *)
1620     e = EXPcreate(Type_Attribute);
1621     e->symbol = *sym; SYMBOL_destroy(sym);
1622     v = VARcreate(e, B);
1623     v->offset = local_var_count++;
1624     v->initializer = C;
1625     DICTdefine(CURRENT_SCOPE->symbol_table, e->symbol.name, (Generic)v,
1626     &e->symbol, OBJ_VARIABLE);
1627     LISTod;
1628     LISTfree(A);
1629 }
1630 
1631 local_body ::= /* no local_variables */.
1632 local_body(A) ::= local_variable(B) local_body.
1633 {
1634     A = B;
1635 }
1636 
1637 local_decl ::= TOK_LOCAL local_decl_rules_on local_body TOK_END_LOCAL semicolon local_decl_rules_off.
1638 
1639 local_decl_rules_on ::= /* subroutine */.
1640 {
1641     tag_count = 0; /* don't signal an error if we find a generic_type */
1642     local_var_count = 0; /* used to keep local var decl's in the same order */
1643 }
1644 
1645 local_decl_rules_off ::= /* subroutine */.
1646 {
1647     tag_count = -1; /* signal an error if we find a generic_type */
1648 }
1649 
1650 defined_type(A) ::= TOK_IDENTIFIER(B).
1651 {
1652     A = TYPEcreate_name(B.symbol);
1653     SCOPEadd_super(A);
1654     SYMBOL_destroy(B.symbol);
1655 }
1656 
1657 defined_type_list(A) ::= defined_type(B).
1658 {
1659     A = LISTcreate();
1660     LISTadd_last(A, (Generic)B);
1661 
1662 }
1663 defined_type_list(A) ::= defined_type_list(B) TOK_COMMA defined_type(C).
1664 {
1665     A = B;
1666     LISTadd_last(A,
1667     (Generic)C);
1668 }
1669 
1670 nested_id_list(A) ::= TOK_LEFT_PAREN id_list(B) TOK_RIGHT_PAREN.
1671 {
1672     A = B;
1673 }
1674 
1675 oneof_op(A) ::= TOK_ONEOF(B).
1676 {
1677     A = B;
1678 }
1679 
1680 optional_or_unique(A) ::= /* NULL body */.
1681 {
1682     A.unique = 0;
1683     A.optional = 0;
1684 }
1685 optional_or_unique(A) ::= TOK_OPTIONAL.
1686 {
1687     A.unique = 0;
1688     A.optional = 1;
1689 }
1690 optional_or_unique(A) ::= TOK_UNIQUE.
1691 {
1692     A.unique = 1;
1693     A.optional = 0;
1694 }
1695 optional_or_unique(A) ::= TOK_OPTIONAL TOK_UNIQUE.
1696 {
1697     A.unique = 1;
1698     A.optional = 1;
1699 }
1700 optional_or_unique(A) ::= TOK_UNIQUE TOK_OPTIONAL.
1701 {
1702     A.unique = 1;
1703     A.optional = 1;
1704 }
1705 
1706 optional_fixed(A) ::= /* nuthin' */.
1707 {
1708     A.fixed = 0;
1709 }
1710 optional_fixed(A) ::= TOK_FIXED.
1711 {
1712     A.fixed = 1;
1713 }
1714 
1715 precision_spec(A) ::= /* no precision specified */.
1716 {
1717     A = (Expression)0;
1718 }
1719 precision_spec(A) ::= TOK_LEFT_PAREN expression(B) TOK_RIGHT_PAREN.
1720 {
1721     A = B;
1722 }
1723 
1724 /* NOTE: actual parameters cannot go to NULL, since this causes
1725  * a syntactic ambiguity (see note at actual_parameters).  hence
1726  * the need for the second branch of this rule.
1727  */
1728 
1729 proc_call_statement(A) ::= procedure_id(B) actual_parameters(C) semicolon.
1730 {
1731     A = PCALLcreate(C);
1732     A->symbol = *(B);
1733 }
1734 proc_call_statement(A) ::= procedure_id(B) semicolon.
1735 {
1736     A = PCALLcreate((Linked_List)0);
1737     A->symbol = *(B);
1738 }
1739 
1740 procedure_decl ::= procedure_header(A) action_body(B) TOK_END_PROCEDURE
1741            semicolon.
1742 {
1743     PROCput_body(CURRENT_SCOPE, B);
1744     ALGput_full_text(CURRENT_SCOPE, A, SCANtell());
1745     POP_SCOPE();
1746 }
1747 
1748 procedure_header(A) ::= TOK_PROCEDURE ph_get_line(B) ph_push_scope
1749             formal_parameter_list(C) semicolon.
1750 {
1751     Procedure p = CURRENT_SCOPE;
1752     p->u.proc->parameters = C;
1753     p->u.proc->pcount = LISTget_length(C);
1754     p->u.proc->tag_count = tag_count;
1755     tag_count = -1;    /* done with parameters, no new tags can be defined */
1756     A = B;
1757 }
1758 
1759 ph_push_scope ::= TOK_IDENTIFIER(A).
1760 {
1761     Procedure p = ALGcreate(OBJ_PROCEDURE);
1762     tag_count = 0;
1763 
1764     if (print_objects_while_running & OBJ_PROCEDURE_BITS) {
1765     fprintf( stderr, "parse: %s (procedure)\n", A.symbol->name);
1766     }
1767 
1768     PUSH_SCOPE(p, A.symbol, OBJ_PROCEDURE);
1769 }
1770 
1771 ph_get_line(A) ::= /* subroutine */.
1772 {
1773     A = SCANtell();
1774 }
1775 
1776 procedure_id(A) ::= TOK_IDENTIFIER(B).
1777 {
1778     A = B.symbol;
1779 }
1780 procedure_id(A) ::= TOK_BUILTIN_PROCEDURE(B).
1781 {
1782     A = B.symbol;
1783 }
1784 
1785 group_ref(A) ::= TOK_BACKSLASH TOK_IDENTIFIER(B).
1786 {
1787     A = BIN_EXPcreate(OP_GROUP, (Expression)0, (Expression)0);
1788     A->e.op2 = EXPcreate(Type_Identifier);
1789     A->e.op2->symbol = *B.symbol;
1790     SYMBOL_destroy(B.symbol);
1791 }
1792 
1793 qualifier(A) ::= TOK_DOT TOK_IDENTIFIER(B).
1794 {
1795     A.expr = A.first = BIN_EXPcreate(OP_DOT, (Expression)0, (Expression)0);
1796     A.expr->e.op2 = EXPcreate(Type_Identifier);
1797     A.expr->e.op2->symbol = *B.symbol;
1798     SYMBOL_destroy(B.symbol);
1799 }
1800 qualifier(A) ::= TOK_BACKSLASH TOK_IDENTIFIER(B). [TOK_NOT]
1801 {
1802     A.expr = A.first = BIN_EXPcreate(OP_GROUP, (Expression)0, (Expression)0);
1803     A.expr->e.op2 = EXPcreate(Type_Identifier);
1804     A.expr->e.op2->symbol = *B.symbol;
1805     SYMBOL_destroy(B.symbol);
1806 }
1807 
1808 /* 10303-11:2004 production 239   index_qualifier = '[' index_1 [ ':' index_2 ] ']' . */
1809 qualifier(A) ::= TOK_LEFT_BRACKET simple_expression(B) TOK_RIGHT_BRACKET.
1810 {
1811     A.expr = A.first = BIN_EXPcreate(OP_ARRAY_ELEMENT, (Expression)0,
1812     (Expression)0);
1813     A.expr->e.op2 = B;
1814 }
1815 
1816 /* 10303-11:2004 production 239   index_qualifier = '[' index_1 [ ':' index_2 ] ']' . */
1817 qualifier(A) ::= TOK_LEFT_BRACKET simple_expression(B) TOK_COLON
1818          simple_expression(C) TOK_RIGHT_BRACKET.
1819 {
1820     A.expr = A.first = TERN_EXPcreate(OP_SUBCOMPONENT, (Expression)0,
1821     (Expression)0, (Expression)0);
1822     A.expr->e.op2 = B;
1823     A.expr->e.op3 = C;
1824 }
1825 
1826 query_expression(A) ::= query_start(B) expression(C) TOK_RIGHT_PAREN.
1827 {
1828     A = B;
1829     A->u.query->expression = C;
1830     POP_SCOPE();
1831 }
1832 
1833 query_start(A) ::= TOK_QUERY TOK_LEFT_PAREN TOK_IDENTIFIER(B) TOK_ALL_IN
1834            expression(C) TOK_SUCH_THAT.
1835 {
1836     A = QUERYcreate(B.symbol, C);
1837     SYMBOL_destroy(B.symbol);
1838     PUSH_SCOPE(A->u.query->scope, (Symbol *)0, OBJ_QUERY);
1839 }
1840 
1841 rel_op(A) ::= TOK_LESS_THAN.
1842 {
1843     A = OP_LESS_THAN;
1844 }
1845 rel_op(A) ::= TOK_GREATER_THAN.
1846 {
1847     A = OP_GREATER_THAN;
1848 }
1849 rel_op(A) ::= TOK_EQUAL.
1850 {
1851     A = OP_EQUAL;
1852 }
1853 rel_op(A) ::= TOK_LESS_EQUAL.
1854 {
1855     A = OP_LESS_EQUAL;
1856 }
1857 rel_op(A) ::= TOK_GREATER_EQUAL.
1858 {
1859     A = OP_GREATER_EQUAL;
1860 }
1861 rel_op(A) ::= TOK_NOT_EQUAL.
1862 {
1863     A = OP_NOT_EQUAL;
1864 }
1865 rel_op(A) ::= TOK_INST_EQUAL.
1866 {
1867     A = OP_INST_EQUAL;
1868 }
1869 rel_op(A) ::= TOK_INST_NOT_EQUAL.
1870 {
1871     A = OP_INST_NOT_EQUAL;
1872 }
1873 
1874 /* repeat_statement causes a scope creation if an increment_control exists */
1875 repeat_statement(A) ::= TOK_REPEAT increment_control while_control(B)
1876             until_control(C) semicolon statement_rep(D)
1877             TOK_END_REPEAT semicolon.
1878 {
1879     A = LOOPcreate(CURRENT_SCOPE, B, C, D);
1880 
1881     /* matching PUSH_SCOPE is in increment_control */
1882     POP_SCOPE();
1883 }
1884 repeat_statement(A) ::= TOK_REPEAT while_control(B) until_control(C) semicolon
1885             statement_rep(D) TOK_END_REPEAT semicolon.
1886 {
1887     A = LOOPcreate((struct Scope_ *)0, B, C, D);
1888 }
1889 
1890 return_statement(A) ::= TOK_RETURN semicolon.
1891 {
1892     A = RETcreate((Expression)0);
1893 }
1894 return_statement(A) ::= TOK_RETURN TOK_LEFT_PAREN expression(B) TOK_RIGHT_PAREN
1895             semicolon.
1896 {
1897     A = RETcreate(B);
1898 }
1899 
1900 right_curl ::= TOK_RIGHT_CURL.
1901 {
1902     yyerrok;
1903 }
1904 
1905 rule_decl ::= rule_header(A) action_body(B) where_rule(C) TOK_END_RULE
1906           semicolon.
1907 {
1908     RULEput_body(CURRENT_SCOPE, B);
1909     RULEput_where(CURRENT_SCOPE, C);
1910     ALGput_full_text(CURRENT_SCOPE, A, SCANtell());
1911     POP_SCOPE();
1912 }
1913 
1914 rule_formal_parameter(A) ::= TOK_IDENTIFIER(B).
1915 {
1916     Expression e;
1917     Type t;
1918 
1919     /* it's true that we know it will be an entity_ type later */
1920     TypeBody tb = TYPEBODYcreate(set_);
1921     tb->base = TYPEcreate_name(B.symbol);
1922     SCOPEadd_super(tb->base);
1923     t = TYPEcreate_from_body_anonymously(tb);
1924     SCOPEadd_super(t);
1925     e = EXPcreate_from_symbol(t, B.symbol);
1926     A = VARcreate(e, t);
1927     A->flags.attribute = true;
1928     A->flags.parameter = true;
1929 
1930     /* link it in to the current scope's dict */
1931     DICTdefine(CURRENT_SCOPE->symbol_table, B.symbol->name, (Generic)A,
1932     B.symbol, OBJ_VARIABLE);
1933 }
1934 
1935 rule_formal_parameter_list(A) ::= rule_formal_parameter(B).
1936 {
1937     A = LISTcreate();
1938     LISTadd_last(A, (Generic)B);
1939 }
1940 rule_formal_parameter_list(A) ::= rule_formal_parameter_list(B) TOK_COMMA
1941                   rule_formal_parameter(C).
1942 {
1943     A = B;
1944     LISTadd_last(A, (Generic)C);
1945 }
1946 
1947 rule_header(A) ::= rh_start(B) rule_formal_parameter_list(C) TOK_RIGHT_PAREN
1948            semicolon.
1949 {
1950     CURRENT_SCOPE->u.rule->parameters = C;
1951 
1952     A = B;
1953 }
1954 
1955 rh_start(A) ::= TOK_RULE rh_get_line(B) TOK_IDENTIFIER(C) TOK_FOR
1956         TOK_LEFT_PAREN.
1957 {
1958     Rule r = ALGcreate(OBJ_RULE);
1959 
1960     if (print_objects_while_running & OBJ_RULE_BITS) {
1961     fprintf( stderr, "parse: %s (rule)\n", C.symbol->name);
1962     }
1963 
1964     PUSH_SCOPE(r, C.symbol, OBJ_RULE);
1965 
1966     A = B;
1967 }
1968 
1969 rh_get_line(A) ::= /* subroutine */.
1970 {
1971     A = SCANtell();
1972 }
1973 
1974 schema_body(A) ::= interface_specification_list(B) block_list.
1975 {
1976     A = B;
1977 }
1978 schema_body(A) ::= interface_specification_list(B) constant_decl block_list.
1979 {
1980     A = B;
1981 }
1982 
1983 schema_decl ::= schema_header schema_body TOK_END_SCHEMA semicolon.
1984 {
1985     POP_SCOPE();
1986 }
1987 schema_decl(A) ::= include_directive(B).
1988 {
1989     A = B;
1990 }
1991 
1992 schema_header ::= TOK_SCHEMA TOK_IDENTIFIER(A) semicolon.
1993 {
1994     Schema schema = ( Schema ) DICTlookup(CURRENT_SCOPE->symbol_table, A.symbol->name);
1995 
1996     if (print_objects_while_running & OBJ_SCHEMA_BITS) {
1997     fprintf( stderr, "parse: %s (schema)\n", A.symbol->name);
1998     }
1999 
2000     if (EXPRESSignore_duplicate_schemas && schema) {
2001     SCANskip_to_end_schema(parseData.scanner);
2002     PUSH_SCOPE_DUMMY();
2003     } else {
2004     schema = SCHEMAcreate();
2005     LISTadd_last(PARSEnew_schemas, (Generic)schema);
2006     PUSH_SCOPE(schema, A.symbol, OBJ_SCHEMA);
2007     }
2008 }
2009 
2010 select_type(A) ::= TOK_SELECT TOK_LEFT_PAREN defined_type_list(B)
2011            TOK_RIGHT_PAREN.
2012 {
2013     A = TYPEBODYcreate(select_);
2014     A->list = B;
2015 }
2016 
2017 semicolon ::= TOK_SEMICOLON.
2018 {
2019     yyerrok;
2020 }
2021 
2022 set_type(A) ::= TOK_SET bound_spec(B) TOK_OF attribute_type(C).
2023 {
2024     A = TYPEBODYcreate(set_);
2025     A->base = C;
2026     A->lower = B.lower_limit;
2027     A->upper = B.upper_limit;
2028 }
2029 set_type(A) ::= TOK_SET TOK_OF attribute_type(B).
2030 {
2031     A = TYPEBODYcreate(set_);
2032     A->base = B;
2033 }
2034 
2035 skip_statement(A) ::= TOK_SKIP semicolon.
2036 {
2037     A = STATEMENT_SKIP;
2038 }
2039 
2040 statement(A) ::= alias_statement(B).
2041 {
2042     A = B;
2043 }
2044 statement(A) ::= assignment_statement(B).
2045 {
2046     A = B;
2047 }
2048 statement(A) ::= case_statement(B).
2049 {
2050     A = B;
2051 }
2052 statement(A) ::= compound_statement(B).
2053 {
2054     A = B;
2055 }
2056 statement(A) ::= escape_statement(B).
2057 {
2058     A = B;
2059 }
2060 statement(A) ::= if_statement(B).
2061 {
2062     A = B;
2063 }
2064 statement(A) ::= proc_call_statement(B).
2065 {
2066     A = B;
2067 }
2068 statement(A) ::= repeat_statement(B).
2069 {
2070     A = B;
2071 }
2072 statement(A) ::= return_statement(B).
2073 {
2074     A = B;
2075 }
2076 statement(A) ::= skip_statement(B).
2077 {
2078     A = B;
2079 }
2080 
2081 statement_rep(A) ::= /* no statements */.
2082 {
2083     A = LISTcreate();
2084 }
2085 statement_rep(A) ::= /* ignore null statement */ semicolon statement_rep(B).
2086 {
2087     A = B;
2088 }
2089 statement_rep(A) ::= statement(B) statement_rep(C).
2090 {
2091     A = C;
2092     LISTadd_first(A, (Generic)B);
2093 }
2094 
2095 /* if the actions look backwards, remember the declaration syntax:
2096  * <entity> SUPERTYPE OF <subtype1> ...  SUBTYPE OF <supertype1> ...
2097  */
2098 
2099 subsuper_decl(A) ::= /* NULL body */.
2100 {
2101     A.subtypes = EXPRESSION_NULL;
2102     A.abstract = false;
2103     A.supertypes = LIST_NULL;
2104 }
2105 subsuper_decl(A) ::= supertype_decl(B).
2106 {
2107     A.subtypes = B.subtypes;
2108     A.abstract = B.abstract;
2109     A.supertypes = LIST_NULL;
2110 }
2111 subsuper_decl(A) ::= subtype_decl(B).
2112 {
2113     A.supertypes = B;
2114     A.abstract = false;
2115     A.subtypes = EXPRESSION_NULL;
2116 }
2117 subsuper_decl(A) ::= supertype_decl(B) subtype_decl(C).
2118 {
2119     A.subtypes = B.subtypes;
2120     A.abstract = B.abstract;
2121     A.supertypes = C;
2122 }
2123 
2124 subtype_decl(A) ::= TOK_SUBTYPE TOK_OF TOK_LEFT_PAREN defined_type_list(B)
2125     TOK_RIGHT_PAREN.
2126 {
2127     A = B;
2128 }
2129 
2130 supertype_decl(A) ::= TOK_ABSTRACT TOK_SUPERTYPE.
2131 {
2132     A.subtypes = (Expression)0;
2133     A.abstract = true;
2134 }
2135 supertype_decl(A) ::= TOK_SUPERTYPE TOK_OF TOK_LEFT_PAREN
2136               supertype_expression(B) TOK_RIGHT_PAREN.
2137 {
2138     A.subtypes = B;
2139     A.abstract = false;
2140 }
2141 supertype_decl(A) ::= TOK_ABSTRACT TOK_SUPERTYPE TOK_OF TOK_LEFT_PAREN
2142               supertype_expression(B) TOK_RIGHT_PAREN.
2143 {
2144     A.subtypes = B;
2145     A.abstract = true;
2146 }
2147 
2148 supertype_expression(A) ::= supertype_factor(B).
2149 {
2150     A = B.subtypes;
2151 }
2152 supertype_expression(A) ::= supertype_expression(B) TOK_AND supertype_factor(C).
2153 {
2154     A = BIN_EXPcreate(OP_AND, B, C.subtypes);
2155 }
2156 supertype_expression(A) ::= supertype_expression(B) TOK_ANDOR
2157                 supertype_factor(C).
2158 {
2159     A = BIN_EXPcreate(OP_ANDOR, B, C.subtypes);
2160 }
2161 
2162 supertype_expression_list(A) ::= supertype_expression(B).
2163 {
2164     A = LISTcreate();
2165     LISTadd_last(A, (Generic)B);
2166 }
2167 supertype_expression_list(A) ::= supertype_expression_list(B) TOK_COMMA
2168                  supertype_expression(C).
2169 {
2170     LISTadd_last(B, (Generic)C);
2171     A = B;
2172 }
2173 
2174 supertype_factor(A) ::= identifier(B).
2175 {
2176     A.subtypes = B;
2177 }
2178 supertype_factor(A) ::= oneof_op TOK_LEFT_PAREN supertype_expression_list(B)
2179             TOK_RIGHT_PAREN.
2180 {
2181     A.subtypes = EXPcreate(Type_Oneof);
2182     A.subtypes->u.list = B;
2183 }
2184 supertype_factor(A) ::= TOK_LEFT_PAREN supertype_expression(B) TOK_RIGHT_PAREN.
2185 {
2186     A.subtypes = B;
2187 }
2188 
2189 type(A) ::= aggregation_type(B).
2190 {
2191     A.type = 0;
2192     A.body = B;
2193 }
2194 type(A) ::= basic_type(B).
2195 {
2196     A.type = 0;
2197     A.body = B;
2198 }
2199 type(A) ::= defined_type(B).
2200 {
2201     A.type = B;
2202     A.body = 0;
2203 }
2204 type(A) ::= select_type(B).
2205 {
2206     A.type = 0;
2207     A.body = B;
2208 }
2209 
2210 type_item_body(A) ::= enumeration_type(B).
2211 {
2212     A = B;
2213 }
2214 type_item_body ::= type(A).
2215 {
2216     CURRENT_SCOPE->u.type->head = A.type;
2217     CURRENT_SCOPE->u.type->body = A.body;
2218 }
2219 
2220 type_item ::= ti_start type_item_body semicolon.
2221 
2222 ti_start ::= TOK_IDENTIFIER(A) TOK_EQUAL.
2223 {
2224     Type t = TYPEcreate_name(A.symbol);
2225     PUSH_SCOPE(t, A.symbol, OBJ_TYPE);
2226 }
2227 
2228 type_decl(A) ::= td_start(B) TOK_END_TYPE semicolon.
2229 {
2230     A = B;
2231 }
2232 
2233 td_start(A) ::= TOK_TYPE(B) type_item where_rule_OPT(C).
2234 {
2235     CURRENT_SCOPE->where = C;
2236     POP_SCOPE();
2237     A = B;
2238 }
2239 
2240 general_ref(A) ::= assignable(B) group_ref(C).
2241 {
2242     C->e.op1 = B;
2243     A = C;
2244 }
2245 general_ref(A) ::= assignable(B).
2246 {
2247     A = B;
2248 }
2249 
2250 unary_expression(A) ::= aggregate_initializer(B).
2251 {
2252     A = B;
2253 }
2254 unary_expression(A) ::= unary_expression(B) qualifier(C).
2255 {
2256     C.first->e.op1 = B;
2257     A = C.expr;
2258 }
2259 unary_expression(A) ::= literal(B).
2260 {
2261     A = B;
2262 }
2263 unary_expression(A) ::= function_call(B).
2264 {
2265     A = B;
2266 }
2267 unary_expression(A) ::= identifier(B).
2268 {
2269     A = B;
2270 }
2271 unary_expression(A) ::= TOK_LEFT_PAREN expression(B) TOK_RIGHT_PAREN.
2272 {
2273     A = B;
2274 }
2275 unary_expression(A) ::= interval(B).
2276 {
2277     A = B;
2278 }
2279 unary_expression(A) ::= query_expression(B).
2280 {
2281     A = B;
2282 }
2283 unary_expression(A) ::= TOK_NOT unary_expression(B).
2284 {
2285     A = UN_EXPcreate(OP_NOT, B);
2286 }
2287 unary_expression(A) ::= TOK_PLUS unary_expression(B).  [TOK_NOT]
2288 {
2289     A = B;
2290 }
2291 unary_expression(A) ::= TOK_MINUS unary_expression(B).  [TOK_NOT]
2292 {
2293     A = UN_EXPcreate(OP_NEGATE, B);
2294 }
2295 
2296 unique(A) ::= /* look for optional UNIQUE */.
2297 {
2298     A.unique = 0;
2299 }
2300 unique(A) ::= TOK_UNIQUE.
2301 {
2302     A.unique = 1;
2303 }
2304 
2305 /* 10303-11:2004 production 275
2306  * qualified_attribute = SELF group_qualifier attribute_qualifier .
2307  *
2308  * NOTE rule 279 doesn't seem to be implemented
2309  * redeclared_attribute = qualified_attribute [ RENAMED attribute_id ] .
2310  */
2311 qualified_attr(A) ::= attribute_decl(B).
2312 {
2313     A = B;
2314 }
2315 
2316 qualified_attr_list(A) ::= qualified_attr(B).
2317 {
2318     A = LISTcreate();
2319     LISTadd_last(A, (Generic)B);
2320 }
2321 qualified_attr_list(A) ::= qualified_attr_list(B) TOK_COMMA qualified_attr(C).
2322 {
2323     A = B;
2324     LISTadd_last(A, (Generic)C);
2325 }
2326 
2327 labelled_attrib_list(A) ::= qualified_attr_list(B) semicolon.
2328 {
2329     LISTadd_first(B, (Generic)EXPRESSION_NULL);
2330     A = B;
2331 }
2332 labelled_attrib_list(A) ::= TOK_IDENTIFIER(B) TOK_COLON qualified_attr_list(C)
2333                 semicolon.
2334 {
2335     LISTadd_first(C, (Generic)B.symbol);
2336     A = C;
2337 }
2338 
2339 /* returns a list */
2340 labelled_attrib_list_list(A) ::= labelled_attrib_list(B).
2341 {
2342     A = LISTcreate();
2343     LISTadd_last(A, (Generic)B);
2344 }
2345 labelled_attrib_list_list(A) ::= labelled_attrib_list_list(B)
2346                  labelled_attrib_list(C).
2347 {
2348     LISTadd_last(B, (Generic)C);
2349     A = B;
2350 }
2351 
2352 unique_clause(A) ::= /* unique clause is always optional */.
2353 {
2354     A = 0;
2355 }
2356 unique_clause(A) ::= TOK_UNIQUE labelled_attrib_list_list(B).
2357 {
2358     A = B;
2359 }
2360 
2361 until_control(A) ::= /* NULL */.
2362 {
2363     A = 0;
2364 }
2365 until_control(A) ::= TOK_UNTIL expression(B).
2366 {
2367     A = B;
2368 }
2369 
2370 where_clause(A) ::= expression(B) semicolon.
2371 {
2372     A = WHERE_new();
2373     A->label = SYMBOLcreate("<unnamed>", yylineno, current_filename);
2374     A->expr = B;
2375 }
2376 where_clause(A) ::= TOK_IDENTIFIER(B) TOK_COLON expression(C) semicolon.
2377 {
2378     A = WHERE_new();
2379     A->label = B.symbol;
2380     A->expr = C;
2381 
2382     if (!CURRENT_SCOPE->symbol_table) {
2383     CURRENT_SCOPE->symbol_table = DICTcreate(25);
2384     }
2385 
2386     DICTdefine(CURRENT_SCOPE->symbol_table, B.symbol->name, (Generic)A,
2387     B.symbol, OBJ_WHERE);
2388 }
2389 
2390 where_clause_list(A) ::= where_clause(B).
2391 {
2392     A = LISTcreate();
2393     LISTadd_last(A, (Generic)B);
2394 }
2395 where_clause_list(A) ::= where_clause_list(B) where_clause(C).
2396 {
2397     A = B;
2398     LISTadd_last(A, (Generic)C);
2399 }
2400 
2401 where_rule(A) ::= TOK_WHERE where_clause_list(B).
2402 {
2403     A = B;
2404 }
2405 
2406 where_rule_OPT(A) ::= /* NULL body: no where rule */.
2407 {
2408     A = LIST_NULL;
2409 }
2410 where_rule_OPT(A) ::= where_rule(B).
2411 {
2412     A = B;
2413 }
2414 
2415 while_control(A) ::= /* NULL */.
2416 {
2417     A = 0;
2418 }
2419 while_control(A) ::= TOK_WHILE expression(B).
2420 {
2421     A = B;
2422 }
2423 
2424 %syntax_error {
2425     Symbol sym;
2426 
2427     (void) yymajor; /* quell unused param warning */
2428     (void) yyminor;
2429     yyerrstatus++;
2430 
2431     sym.line = yylineno;
2432     sym.filename = current_filename;
2433 
2434     ERRORreport_with_symbol(ERROR_syntax, &sym, "Syntax error",
2435     CURRENT_SCOPE_TYPE_PRINTABLE, CURRENT_SCOPE_NAME);
2436 }
2437 
2438 %stack_size 0
2439 
2440 %stack_overflow {
2441     fprintf(stderr, "Express parser experienced stack overflow.\n");
2442     fprintf(stderr, "Last token had value %x\n", yypMinor->yy0.val);
2443 }
2444