home *** CD-ROM | disk | FTP | other *** search
/ ftptest.leeds.ac.uk / 2015.02.ftptest.leeds.ac.uk.tar / ftptest.leeds.ac.uk / bionet / CAE-GROUP / SCL-WIN3x / FED_PLUS.EXE / EXPPARSE.Y < prev    next >
Text File  |  1994-07-21  |  56KB  |  1,940 lines

  1. %{
  2.  
  3. static char rcsid[] = "$Id: expparse.y,v 1.13 1994/05/11 19:50:00 libes Exp $";
  4.  
  5. /*
  6.  * YACC grammar for Express parser.
  7.  *
  8.  * This software was developed by U.S. Government employees as part of
  9.  * their official duties and is not subject to copyright.
  10.  *
  11.  * $Log: expparse.y,v $
  12.  * Revision 1.13  1994/05/11  19:50:00  libes
  13.  * numerous fixes
  14.  *
  15.  * Revision 1.12  1993/10/15  18:47:26  libes
  16.  * CADDETC certified
  17.  *
  18.  * Revision 1.10  1993/03/19  20:53:57  libes
  19.  * one more, with feeling
  20.  *
  21.  * Revision 1.9  1993/03/19  20:39:51  libes
  22.  * added unique to parameter types
  23.  *
  24.  * Revision 1.8  1993/02/16  03:17:22  libes
  25.  * reorg'd alg bodies to not force artificial begin/ends
  26.  * added flag to differentiate parameters in scopes
  27.  * rewrote query to fix scope handling
  28.  * added support for Where type
  29.  *
  30.  * Revision 1.7  1993/01/19  22:44:17  libes
  31.  * *** empty log message ***
  32.  *
  33.  * Revision 1.6  1992/08/27  23:36:35  libes
  34.  * created fifo for new schemas that are parsed
  35.  * connected entity list to create of oneof
  36.  *
  37.  * Revision 1.5  1992/08/18  17:11:36  libes
  38.  * rm'd extraneous error messages
  39.  *
  40.  * Revision 1.4  1992/06/08  18:05:20  libes
  41.  * prettied up interface to print_objects_when_running
  42.  *
  43.  * Revision 1.3  1992/05/31  23:31:13  libes
  44.  * implemented ALIAS resolution
  45.  *
  46.  * Revision 1.2  1992/05/31  08:30:54  libes
  47.  * multiple files
  48.  *
  49.  * Revision 1.1  1992/05/28  03:52:25  libes
  50.  * Initial revision
  51.  */
  52.  
  53.  
  54. #include "linklist.h"
  55. #include "stack.h"
  56. #include "express.h"
  57. #include "schema.h"
  58. #include "entity.h"
  59. #include "resolve.h"
  60. //#include "expscan.h"
  61.  
  62. extern int print_objects_while_running;
  63.  
  64. int tag_count;    /* use this to count tagged GENERIC types in the formal */
  65.         /* argument lists.  Gross, but much easier to do it this */
  66.         /* way then with the 'help' of yacc. */
  67.  
  68. /*SUPPRESS 61*/
  69. /* Type current_type;    /* pass type placeholder down */
  70.         /* this allows us to attach a dictionary to it only when */
  71.         /* we decide we absolutely need one */
  72.  
  73. Express yyresult;    /* hook to everything built by parser */
  74.  
  75. Symbol *interface_schema;    /* schema of interest in use/ref clauses */
  76. void (*interface_func)();    /* func to attach rename clauses */
  77.  
  78. /* record schemas found in a single parse here, allowing them to be */
  79. /* differentiated from other schemas parsed earlier */
  80. Linked_List PARSEnew_schemas;
  81.  
  82. extern int    yylineno;
  83.  
  84. static void    yyerror PROTO((char*));
  85. static void    yyerror2 PROTO((char CONST *));
  86.  
  87. Boolean        yyeof = false;
  88.  
  89. #ifdef FLEX
  90. extern char    *yytext;
  91. #else /* LEX */
  92. extern char    yytext[];
  93. #endif /*FLEX*/
  94.  
  95. #define MAX_SCOPE_DEPTH    20    /* max number of scopes that can be nested */
  96.  
  97. static struct scope {
  98.     struct Scope *this;
  99.     char type;    /* one of OBJ_XXX */
  100.     struct scope *pscope;    /* pointer back to most recent scope */
  101.                 /* that has a printable name - for better */
  102.                 /* error messages */
  103. } scopes[MAX_SCOPE_DEPTH], *scope;
  104. #define CURRENT_SCOPE (scope->this)
  105. #define PREVIOUS_SCOPE ((scope-1)->this)
  106. #define CURRENT_SCHEMA (scope->this->u.schema)
  107. #define CURRENT_SCOPE_NAME        (OBJget_symbol(scope->pscope->this,scope->pscope->type)->name)
  108. #define CURRENT_SCOPE_TYPE_PRINTABLE    (OBJget_type(scope->pscope->type))
  109.  
  110. /* ths = new scope to enter */
  111. /* sym = name of scope to enter into parent.  Some scopes (i.e., increment) */
  112. /*       are not named, in which case sym should be 0 */
  113. /*     This is useful for when a diagnostic is printed, an earlier named */
  114. /*      scoped can be used */
  115. /* typ = type of scope */
  116. #define PUSH_SCOPE(ths,sym,typ) \
  117.     if (sym) DICTdefine(scope->this->symbol_table,(sym)->name,(Generic)ths,sym,typ);\
  118.     ths->superscope = scope->this; \
  119.     scope++;        \
  120.     scope->type = typ;    \
  121.     scope->pscope = (sym?scope:(scope-1)->pscope); \
  122.     scope->this = ths; \
  123.     if (sym) { \
  124.         ths->symbol = *(sym); \
  125.     }
  126. #define POP_SCOPE() scope--
  127.  
  128. /* PUSH_SCOPE_DUMMY just pushes the scope stack with nothing actually on it */
  129. /* Necessary for situations when a POP_SCOPE is unnecessary but inevitable */
  130. #define PUSH_SCOPE_DUMMY() scope++
  131.  
  132. /* normally the superscope is added by PUSH_SCOPE, but some things (types) */
  133. /* bother to get pushed so fix them this way */
  134. #define SCOPEadd_super(ths) ths->superscope = scope->this;
  135.  
  136. #define ERROR(code)    ERRORreport(code, yylineno)
  137.  
  138. /* structured types for parse node decorations */
  139.  
  140. %}
  141.  
  142. %type <case_item>    case_action        case_otherwise
  143.  
  144. %type <entity_body>    entity_body
  145.  
  146. %type <expression>    aggregate_init_element    aggregate_initializer
  147.             attribute_decl
  148.             by_expression
  149.             constant
  150.             expression
  151.             function_call
  152.             general_ref
  153.             identifier        initializer
  154.             interval        literal
  155.             local_initializer    precision_spec
  156.             query_expression
  157.             simple_expression
  158.             unary_expression
  159.             qualifier
  160.             supertype_expression
  161.             until_control        while_control
  162.  
  163. %type <list>    action_body        actual_parameters    aggregate_init_body
  164.         explicit_attr_list    case_action_list    case_block
  165.         case_labels        where_clause_list    derive_decl
  166.         explicit_attribute    expression_list
  167.         formal_parameter    formal_parameter_list    formal_parameter_rep
  168.         id_list            defined_type_list
  169.         nested_id_list        /*repeat_control_list*/    statement_rep
  170.         subtype_decl
  171.         where_rule
  172.         supertype_expression_list
  173.         labelled_attrib_list_list
  174.         labelled_attrib_list
  175.         inverse_attr_list
  176.         inverse_clause
  177.         attribute_decl_list
  178.         derived_attribute_rep
  179.         unique_clause
  180.         rule_formal_parameter_list
  181.         qualified_attr_list    /* remove labelled_attrib_list if this works */
  182.  
  183. %type <op_code>        rel_op
  184.  
  185. %type <type_flags>    optional_or_unique    optional_fixed    optional    var    unique
  186.  
  187. %type <qualified_attr>    qualified_attr
  188.  
  189. %type <statement>    alias_statement
  190.             assignment_statement    case_statement
  191.             compound_statement
  192.             escape_statement    if_statement
  193.             proc_call_statement    repeat_statement
  194.             return_statement    skip_statement
  195.             statement
  196.  
  197. %type <subsuper_decl>    subsuper_decl
  198.  
  199. %type <subtypes>    supertype_decl
  200.             supertype_factor
  201.  
  202. %type <symbol>        function_id    procedure_id
  203.  
  204. %type <type>        attribute_type    defined_type    parameter_type
  205.             generic_type
  206.  
  207. %type <typebody>    basic_type
  208.             select_type        aggregate_type
  209.             aggregation_type    array_type
  210.             bag_type        conformant_aggregation
  211.             list_type
  212.             set_type
  213.  
  214. %type <type_either>    set_or_bag_of_entity    type
  215.  
  216. %type <upper_lower>    cardinality_op    index_spec        limit_spec
  217.  
  218. %type <variable>    inverse_attr    derived_attribute
  219.             rule_formal_parameter
  220.  
  221. %type <where>        where_clause
  222.  
  223. %left    TOK_OR            TOK_XOR
  224.  
  225. %left    TOK_AND            TOK_ANDOR
  226.  
  227. %left    TOK_EQUAL        TOK_GREATER_EQUAL    TOK_GREATER_THAN
  228.     TOK_IN            TOK_INST_EQUAL        TOK_INST_NOT_EQUAL
  229.     TOK_LESS_EQUAL        TOK_LESS_THAN        TOK_LIKE
  230.     TOK_NOT_EQUAL
  231.  
  232. %left    TOK_MINUS        TOK_PLUS
  233.  
  234. %left    TOK_DIV            TOK_MOD            TOK_REAL_DIV
  235.     TOK_TIMES
  236.  
  237. %left    TOK_CONCAT_OP    /*direction doesn't really matter, just priority */
  238.  
  239. %right    TOK_EXP
  240.  
  241. %left    TOK_NOT
  242.  
  243.  
  244. %nonassoc TOK_DOT TOK_BACKSLASH TOK_LEFT_BRACKET
  245.  
  246. %token    TOK_ABSTRACT
  247.     TOK_AGGREGATE        TOK_ALIAS
  248.     TOK_ALL_IN        TOK_ARRAY
  249.     TOK_AS            TOK_ASSIGNMENT
  250.     TOK_BACKSLASH
  251.     TOK_BAG            TOK_BEGIN        TOK_BINARY
  252.     TOK_BOOLEAN
  253.     TOK_BY            TOK_CASE        TOK_COLON
  254.     TOK_COMMA        TOK_CONSTANT        TOK_CONTEXT
  255.     TOK_E            TOK_DERIVE
  256.     TOK_DOT            TOK_ELSE        TOK_END
  257.     TOK_END_ALIAS
  258.     TOK_END_CASE        TOK_END_CONSTANT    TOK_END_CONTEXT
  259.     TOK_END_ENTITY        TOK_END_FUNCTION
  260.     TOK_END_IF        TOK_END_LOCAL        TOK_END_MODEL
  261.     TOK_END_PROCEDURE    TOK_END_REPEAT        TOK_END_RULE
  262.     TOK_END_SCHEMA        TOK_END_TYPE        TOK_ENTITY
  263.     TOK_ENUMERATION        TOK_ESCAPE
  264.     TOK_FIXED        TOK_FOR            TOK_FROM
  265.     TOK_FUNCTION        TOK_GENERIC        TOK_IF
  266.     TOK_INCLUDE
  267.     TOK_INTEGER
  268.     TOK_INVERSE
  269.     TOK_LEFT_BRACKET    TOK_LEFT_CURL
  270.     TOK_LEFT_PAREN        TOK_LIST        TOK_LOCAL
  271.     TOK_LOGICAL        TOK_MODEL
  272.     TOK_NUMBER        TOK_OF            TOK_ONEOF
  273.     TOK_OPTIONAL        TOK_OTHERWISE        TOK_PI
  274.     TOK_PROCEDURE        TOK_QUERY
  275.     TOK_QUESTION_MARK    TOK_REAL        TOK_REFERENCE
  276.     TOK_REPEAT        TOK_RETURN
  277.     TOK_RIGHT_BRACKET    TOK_RIGHT_CURL        TOK_RIGHT_PAREN
  278.     TOK_RULE        TOK_SCHEMA
  279.     TOK_SELECT        TOK_SEMICOLON        TOK_SET
  280.     TOK_SKIP        TOK_STRING        TOK_SUBTYPE
  281.     TOK_SUCH_THAT        TOK_SUPERTYPE        TOK_THEN
  282.     TOK_TO            TOK_TYPE        TOK_UNIQUE
  283.     TOK_UNTIL        TOK_USE
  284.     TOK_VAR            TOK_WHERE
  285.     TOK_WHILE
  286.  
  287. %token <string>        TOK_STRING_LITERAL    TOK_STRING_LITERAL_ENCODED
  288. %token <symbol>        TOK_BUILTIN_FUNCTION    TOK_BUILTIN_PROCEDURE
  289.             TOK_IDENTIFIER        TOK_SELF
  290. %token <iVal>        TOK_INTEGER_LITERAL
  291. %token <rVal>        TOK_REAL_LITERAL
  292. %token <logical>    TOK_LOGICAL_LITERAL
  293. %token <binary>        TOK_BINARY_LITERAL
  294.  
  295. %start express_file
  296.  
  297. %union {
  298.     /* simple (single-valued) node types */
  299.  
  300.     Binary        binary;
  301.     Case_Item        case_item;
  302.     Expression    expression;
  303.     Integer        iVal;
  304.     Linked_List        list;
  305.     Logical        logical;
  306.     Op_Code        op_code;
  307.     Qualified_Attr *    qualified_attr;
  308.     Real        rVal;
  309.     Statement        statement;
  310.     Symbol *        symbol;
  311.     char *        string;
  312.     Type        type;
  313.     TypeBody        typebody;
  314.     Variable        variable;
  315.     Where        where;
  316.  
  317.     struct type_either {
  318.         Type     type;
  319.         TypeBody body;
  320.     } type_either;    /* either one of these can be returned */
  321.  
  322.     struct {
  323.         unsigned optional:1;
  324.         unsigned unique:1;
  325.         unsigned fixed:1;
  326.         unsigned var:1;        /* when formal is "VAR" */
  327.     } type_flags;
  328.  
  329.     struct {
  330.     Linked_List    attributes;
  331.     Linked_List    unique;
  332.     Linked_List    where;
  333.     } entity_body;
  334.  
  335.     struct {
  336.     Expression    subtypes;
  337.     Linked_List    supertypes;
  338.     Boolean        abstract;
  339.     } subsuper_decl;
  340.  
  341.     struct {
  342.     Expression    subtypes;
  343.     Boolean        abstract;
  344.     } subtypes;
  345.  
  346.     struct {
  347.     Expression    lower_limit;
  348.     Expression    upper_limit;
  349.     } upper_lower;
  350. }
  351.  
  352. %%
  353.  
  354. action_body        : action_body_item_rep statement_rep
  355.               { $$ = $2; }
  356.             ;
  357.  
  358. /* this should be rewritten to force order, see comment on next production */
  359. action_body_item    : declaration
  360.             | constant_decl
  361.             | local_decl
  362. /*            | error */
  363.             ;
  364.  
  365. /* this corresponds to 'algorithm_head' in N14-ese
  366.    but it should be rewritten to force
  367.     declarations    followed by
  368.     constants    followed by
  369.     local_decls
  370. */
  371. action_body_item_rep    : /* NULL item */
  372.             | action_body_item action_body_item_rep
  373.             ;
  374.  
  375. /* NOTE: can actually go to NULL, but it's a semantic problem */
  376. /* to disambiguate this from a simple identifier, so let a call */
  377. /* with no parameters be parsed as an identifier for now. */
  378.  
  379. /* another problem is that x() is always an entity.  func/proc calls */
  380. /* with no args are called as "x".  By the time resolution occurs */
  381. /* and we find out whether or not x is an entity or func/proc, we will */
  382. /* no longer have the information about whether there were parens! */
  383. /* EXPRESS is simply wrong to handle these two cases differently. */
  384.  
  385. actual_parameters    : TOK_LEFT_PAREN expression_list TOK_RIGHT_PAREN
  386.               { $$ = $2; }
  387.             | TOK_LEFT_PAREN TOK_RIGHT_PAREN
  388.               { $$ = 0; /*LISTcreate();*/
  389.                 /* NULL would do, except that we'll end */
  390.                 /* up stuff the call name in as the 1st */
  391.                 /* arg, so we might as well create the */
  392.                 /* list now */
  393.                 }
  394.             ;
  395.  
  396. /* I give up - why does 2nd parm of AGGR_LIT have to be non-null? */
  397. aggregate_initializer    : TOK_LEFT_BRACKET TOK_RIGHT_BRACKET
  398.               {  $$ = EXPcreate(Type_Aggregate);
  399.                  $$->u.list = LISTcreate();}
  400.             | TOK_LEFT_BRACKET aggregate_init_body TOK_RIGHT_BRACKET
  401.               {  $$ = EXPcreate(Type_Aggregate);
  402.                  $$->u.list = $2;}
  403.             ;
  404.  
  405. aggregate_init_element    : expression
  406.               { $$ = $1; }
  407. /*
  408.             | expression TOK_COLON expression
  409.               { $$ = 
  410.               { $$ = EXPRESSION_NULL;
  411.                 ERRORreport_with_line(ERROR_unimplemented_feature,
  412.                           yylineno,
  413.                           "`:' repetition in aggregate initializer"); }
  414. */
  415.             ;
  416.  
  417. aggregate_init_body    : aggregate_init_element
  418.               { $$ = LISTcreate();
  419.                 LISTadd($$, (Generic)$1); }
  420.             | aggregate_init_element TOK_COLON expression
  421.               { $$ = LISTcreate();
  422.                 LISTadd($$, (Generic)$1);
  423.                 LISTadd($$, (Generic)$3);
  424.                 $1->type->u.type->body->flags.repeat = 1; }
  425.             | aggregate_init_body TOK_COMMA aggregate_init_element
  426.               { $$ = $1;
  427.                 LISTadd_last($$, (Generic)$3); }
  428.             | aggregate_init_body TOK_COMMA aggregate_init_element TOK_COLON expression
  429.               { $$ = $1;
  430.                 LISTadd_last($$, (Generic)$3);
  431.                 LISTadd_last($$, (Generic)$5);
  432.                 $3->type->u.type->body->flags.repeat = 1;}
  433.             ;
  434.  
  435. aggregate_type        : TOK_AGGREGATE TOK_OF parameter_type
  436.               { $$ = TYPEBODYcreate(aggregate_);
  437.                 $$->base = $3;}
  438.             | TOK_AGGREGATE TOK_COLON TOK_IDENTIFIER TOK_OF parameter_type
  439.               { Type t = TYPEcreate_user_defined_tag($5,CURRENT_SCOPE,$3);
  440.                 SCOPEadd_super(t);
  441.                 $$ = TYPEBODYcreate(aggregate_);
  442.                 $$->tag = t;
  443.                 $$->base = $5;}
  444.             ;
  445.  
  446. aggregation_type    : array_type
  447.               { $$ = $1; }
  448.             | bag_type
  449.               { $$ = $1; }
  450.             | list_type
  451.               { $$ = $1; }
  452.             | set_type
  453.               { $$ = $1; }
  454.             ;
  455.  
  456. alias_statement        : TOK_ALIAS TOK_IDENTIFIER TOK_FOR general_ref semicolon
  457.               { struct Scope *s = SCOPEcreate_tiny(OBJ_ALIAS);
  458.             /* scope doesn't really have/need a name */
  459.             /* I suppose that naming it by the alias is fine */
  460.                 /*SUPPRESS 622*/
  461.                 PUSH_SCOPE(s,(Symbol *)0,OBJ_ALIAS);}
  462.                 statement_rep
  463.               TOK_END_ALIAS semicolon
  464.               { Expression e = EXPcreate_from_symbol(Type_Attribute,$2);
  465.                 Variable v = VARcreate(e,Type_Unknown);
  466.                 v->initializer = $4;
  467.                 DICTdefine(CURRENT_SCOPE->symbol_table,$2->name,
  468.                       (Generic)v,$2,OBJ_VARIABLE);
  469.                 $$ = ALIAScreate(CURRENT_SCOPE,v,$7);
  470.                 POP_SCOPE(); }
  471.             ;
  472.  
  473. array_type        : TOK_ARRAY index_spec TOK_OF optional_or_unique
  474.               attribute_type
  475.               { $$ = TYPEBODYcreate(array_);
  476.                 $$->flags.optional = $4.optional;
  477.                 $$->flags.unique = $4.unique;
  478.                 $$->upper = $2.upper_limit;
  479.                 $$->lower = $2.lower_limit;
  480.                 $$->base = $5;}
  481.             ;
  482.  
  483. assignment_statement    : general_ref TOK_ASSIGNMENT expression semicolon
  484.               { $$ = ASSIGNcreate($1,$3);}
  485.             ;
  486.  
  487. attribute_type        : aggregation_type
  488.               { $$ = TYPEcreate_from_body_anonymously($1);
  489.                 SCOPEadd_super($$);}
  490.             | basic_type
  491.               { $$ = TYPEcreate_from_body_anonymously($1);
  492.                 SCOPEadd_super($$);}
  493.             | defined_type
  494.               { $$ = $1; }
  495.             ;
  496.  
  497. explicit_attr_list    : /* NULL body */
  498.               { $$ = LISTcreate();}
  499.             | explicit_attr_list explicit_attribute
  500.               { $$ = $1;
  501.                 LISTadd_last($$, (Generic)$2); }
  502.             ;
  503.  
  504. bag_type        : TOK_BAG limit_spec TOK_OF attribute_type
  505.               { $$ = TYPEBODYcreate(bag_);
  506.                 $$->base = $4;
  507.                 $$->upper = $2.upper_limit;
  508.                 $$->lower = $2.lower_limit;}
  509.             | TOK_BAG TOK_OF attribute_type
  510.               { $$ = TYPEBODYcreate(bag_);
  511.                 $$->base = $3; }
  512.             ;
  513.  
  514. basic_type        : TOK_BOOLEAN
  515.               { $$ = TYPEBODYcreate(boolean_);}
  516.             | TOK_INTEGER precision_spec
  517.               { $$ = TYPEBODYcreate(integer_);
  518.                 $$->precision = $2;}
  519.             | TOK_REAL precision_spec
  520.               { $$ = TYPEBODYcreate(real_);
  521.                 $$->precision = $2;}
  522.             | TOK_NUMBER
  523.               { $$ = TYPEBODYcreate(number_);}
  524.             | TOK_LOGICAL
  525.               { $$ = TYPEBODYcreate(logical_);}
  526.             | TOK_BINARY precision_spec optional_fixed
  527.               { $$ = TYPEBODYcreate(binary_);
  528.                 $$->precision = $2;
  529.                 $$->flags.fixed = $3.fixed;}
  530.             | TOK_STRING precision_spec optional_fixed
  531.               { $$ = TYPEBODYcreate(string_);
  532.                 $$->precision = $2;
  533.                 $$->flags.fixed = $3.fixed;}
  534.             ;
  535.  
  536. block_list        : /*NULL*/
  537.             | block_list block_member
  538.             ;
  539.  
  540. block_member        : declaration
  541.             | include_directive
  542.             | rule_decl
  543.             ;
  544.  
  545. by_expression        : /* NULL by_expression */
  546.               { $$ = LITERAL_ONE;}
  547.             | TOK_BY expression
  548.               { $$ = $2; }
  549.             ;
  550.  
  551. cardinality_op        : TOK_LEFT_CURL expression TOK_COLON expression TOK_RIGHT_CURL
  552.               { $$.lower_limit = $2;
  553.                 $$.upper_limit = $4; }
  554.             ;
  555.  
  556. case_action        : case_labels TOK_COLON statement
  557.               { $$ = CASE_ITcreate($1, $3);
  558.                 SYMBOLset($$);}
  559.             ;
  560.  
  561. case_action_list    : /* no case_actions */
  562.               { $$ = LISTcreate();}
  563.             | case_action_list case_action
  564.               { yyerrok;
  565.                 $$ = $1;
  566.                 LISTadd_last($$, (Generic)$2); }
  567. /*            | error
  568.               { ERROR(ERROR_empty_case);
  569.                 $$ = LISTcreate(); }*/
  570.             ;
  571.  
  572. case_block        : case_action_list case_otherwise
  573.               { $$ = $1;
  574.                 if ($2) LISTadd_last($$, (Generic)$2); }
  575.             ;
  576.  
  577. case_labels        : expression
  578.               { $$ = LISTcreate();
  579.                 LISTadd_last($$, (Generic)$1); }
  580.             | case_labels TOK_COMMA expression
  581.               { yyerrok;
  582.                 $$ = $1;
  583.                 LISTadd_last($$, (Generic)$3); }
  584. /*            | case_labels error
  585.               { ERROR(ERROR_comma_expected);
  586.                 $$ = $1; }
  587.             | case_labels error
  588.               { ERROR(ERROR_comma_expected); }
  589.               expression
  590.               { yyerrok;
  591.                 $$ = $1; }
  592.             | case_labels TOK_COMMA error
  593.               { ERROR(ERROR_case_labels);
  594.                 $$ = $1; }*/
  595.             ;
  596.  
  597. case_otherwise        : /* no otherwise clause */
  598.               { $$ = (Case_Item)0; }
  599.             | TOK_OTHERWISE TOK_COLON statement
  600.               { $$ = CASE_ITcreate(LIST_NULL, $3);
  601.                 SYMBOLset($$);}
  602.             ;
  603.  
  604. case_statement        : TOK_CASE expression TOK_OF case_block TOK_END_CASE
  605.               semicolon
  606.               { $$ = CASEcreate($2, $4);}
  607.             ;
  608.  
  609. compound_statement    : TOK_BEGIN statement_rep TOK_END semicolon
  610.               { $$ = COMP_STMTcreate($2);}
  611.             ;
  612.  
  613. constant        : TOK_PI
  614.               { $$ = LITERAL_PI; }
  615.             | TOK_E
  616.               { $$ = LITERAL_E; }
  617.             ;
  618.  
  619.             /* package this up as an attribute */
  620. constant_body        : identifier TOK_COLON attribute_type TOK_ASSIGNMENT
  621.                 expression semicolon
  622.               { Variable v;
  623.                 $1->type = $3;
  624.                 v = VARcreate($1,$3);
  625.                 v->initializer = $5;
  626.                 v->flags.constant = 1;
  627.                 DICTdefine(CURRENT_SCOPE->symbol_table,
  628.                 $1->symbol.name,
  629.                 (Generic)v,&$1->symbol,OBJ_VARIABLE);
  630.             }
  631.             ;
  632.  
  633. constant_body_list    : /* NULL */
  634.             | constant_body constant_body_list
  635.             ;
  636.  
  637. constant_decl        :
  638.               TOK_CONSTANT constant_body_list TOK_END_CONSTANT
  639.                   semicolon
  640.             ;
  641.  
  642. declaration        : entity_decl
  643.             | function_decl
  644.             | procedure_decl
  645.             | type_decl
  646.             ;
  647.  
  648. derive_decl        : /* NULL body */
  649.               { $$ = LISTcreate(); }
  650.             | TOK_DERIVE derived_attribute_rep
  651.               { $$ = $2; }
  652.             ;
  653.  
  654. derived_attribute    : attribute_decl TOK_COLON attribute_type initializer semicolon
  655.               { $$ = VARcreate($1,$3);
  656.                 $$->initializer = $4;
  657.               }
  658.             ;
  659.  
  660. derived_attribute_rep    : derived_attribute
  661.               { $$ = LISTcreate();
  662.                 LISTadd_last($$, (Generic)$1); }
  663.             | derived_attribute_rep derived_attribute
  664.               { $$ = $1;
  665.                 LISTadd_last($$, (Generic)$2); }
  666. /*            | error
  667.               { ERROR(ERROR_missing_derive);
  668.                 $$ = LISTcreate(); }
  669.             | derived_attribute_rep error
  670.               { ERROR(ERROR_derived_attribute);
  671.                 $$ = $1; }*/
  672.             ;
  673.  
  674. entity_body        : explicit_attr_list derive_decl inverse_clause
  675.               unique_clause where_rule
  676.               { $$.attributes = $1;
  677.                 /* this is flattened out in entity_decl - DEL */
  678.                 LISTadd_last($$.attributes, (Generic)$2);
  679.                 if ($3 != LIST_NULL) {
  680.                     LISTadd_last($$.attributes, (Generic)$3);
  681.                 }
  682.                 $$.unique = $4;
  683.                 $$.where = $5; }
  684.             ;
  685.  
  686. entity_decl        : entity_header subsuper_decl semicolon
  687.               entity_body TOK_END_ENTITY semicolon
  688.               { CURRENT_SCOPE->u.entity->subtype_expression = $2.subtypes;
  689.                 CURRENT_SCOPE->u.entity->supertype_symbols = $2.supertypes;
  690.                 LISTdo ($4.attributes, l, Linked_List)
  691.                 LISTdo (l, a, Variable)
  692.                     ENTITYadd_attribute(CURRENT_SCOPE, a);
  693.                 LISTod;
  694.                 LISTod;
  695.                 CURRENT_SCOPE->u.entity->abstract = $2.abstract;
  696.                 CURRENT_SCOPE->u.entity->unique = $4.unique;
  697.                 CURRENT_SCOPE->where = $4.where;
  698.                 POP_SCOPE();}
  699. /*            | entity_header error TOK_END_ENTITY semicolon
  700.               { POP_SCOPE();}*/
  701.             ;
  702.  
  703.  
  704. entity_header        : TOK_ENTITY TOK_IDENTIFIER
  705.               { Entity e = ENTITYcreate($2);
  706.                 if (print_objects_while_running & OBJ_ENTITY_BITS){
  707.                 fprintf(stdout,"parse: %s (entity)\n",$2->name);
  708.                 }
  709.                 PUSH_SCOPE(e,$2,OBJ_ENTITY);}
  710.             ;
  711.  
  712. enumeration_type    : TOK_ENUMERATION TOK_OF nested_id_list
  713.               { int value = 0; Expression x; Symbol *tmp;
  714.                 TypeBody tb;
  715.                 tb = TYPEBODYcreate(enumeration_);
  716.                 CURRENT_SCOPE->u.type->head = 0;
  717.                 CURRENT_SCOPE->u.type->body = tb;
  718.                 tb->list = $3;
  719.                 if (!CURRENT_SCOPE->symbol_table) {
  720.                 CURRENT_SCOPE->symbol_table = DICTcreate(25);
  721.                 }
  722.                 LISTdo_links($3, id)
  723.                 tmp = (Symbol *)id->data;
  724.                 id->data = (Generic)(x = EXPcreate(CURRENT_SCOPE));
  725.                 x->symbol = *(tmp);
  726.                 x->u.integer = ++value;
  727.                 /* define both in enum scope and scope of */
  728.                 /* 1st visibility */
  729.                 DICT_define(CURRENT_SCOPE->symbol_table,
  730.                     x->symbol.name,
  731.                     (Generic)x,&x->symbol,OBJ_EXPRESSION);
  732.                 DICTdefine(PREVIOUS_SCOPE->symbol_table,x->symbol.name,
  733.                     (Generic)x,&x->symbol,OBJ_EXPRESSION);
  734.                     SYMBOL_destroy(tmp);
  735.                 LISTod;
  736.                   }
  737.             ;
  738.  
  739. escape_statement    : TOK_ESCAPE semicolon
  740.               { $$ = STATEMENT_ESCAPE; }
  741.             ;
  742.  
  743. attribute_decl        : TOK_IDENTIFIER
  744.               { $$ = EXPcreate(Type_Attribute);
  745.                 $$->symbol = *$1;SYMBOL_destroy($1);
  746.               }
  747.             | TOK_SELF TOK_BACKSLASH TOK_IDENTIFIER TOK_DOT TOK_IDENTIFIER
  748.               { $$ = EXPcreate(Type_Expression);
  749.                 $$->e.op1 = EXPcreate(Type_Expression);
  750.                 $$->e.op1->e.op_code = OP_GROUP;
  751.                 $$->e.op1->e.op1 = EXPcreate(Type_Self);
  752.                 $$->e.op1->e.op2 = EXPcreate_from_symbol(Type_Entity,$3);
  753.                 SYMBOL_destroy($3);
  754.                 $$->e.op_code = OP_DOT;
  755.                 $$->e.op2 = EXPcreate_from_symbol(Type_Attribute,$5);
  756.                 SYMBOL_destroy($5);
  757.               }
  758.             ;
  759.  
  760. attribute_decl_list    : attribute_decl
  761.               { $$ = LISTcreate();
  762.                 LISTadd_last($$, (Generic)$1); }
  763.             | attribute_decl_list TOK_COMMA attribute_decl
  764.               { $$ = $1;
  765.                 LISTadd_last($$, (Generic)$3); }
  766.             ;
  767.  
  768. optional        : /*NULL*/
  769.               { $$.optional = 0;}
  770.             | TOK_OPTIONAL
  771.               { $$.optional = 1;}
  772.             ;
  773.  
  774. explicit_attribute    : attribute_decl_list TOK_COLON optional
  775.               attribute_type semicolon
  776.               { Variable v;
  777.                 LISTdo_links ($1, attr)
  778.                 v = VARcreate((Expression)attr->data,$4);
  779.                 v->flags.optional = $3.optional;
  780.                 attr->data = (Generic)v;
  781.                 LISTod;
  782.               }
  783.             ;
  784. /*
  785.                 if (OBJis_kind_of(attr,Class_Binary_Expression)) {
  786.                     x = BIN_EXPget_second_operand(attr);
  787.                 } else  x = attr;
  788.                 if (!OBJis_kind_of(x,Class_Identifier)) {
  789.                     yyerror("illegal attribute name");
  790.                 }
  791.                 v = EXPcreate(...);
  792.                 v->symbol = SYMBOLget_name(
  793.                     IDENTget_identifier(x)),$4,&errc);
  794.                 VARput_optional(v, true);
  795.                 VARput_reference(v,attr);
  796.                 LISTadd_last(vlist,(Generic)v);
  797. */
  798.  
  799.  
  800. express_file        : { scope = scopes;
  801.                 /* no need to define scope->this */
  802.                 scope->this = yyresult;
  803.                 scope->pscope = scope;
  804.                 scope->type = OBJ_EXPRESS;
  805.                 yyresult->symbol.name = yyresult->u.express->filename;
  806.                 yyresult->symbol.filename = yyresult->u.express->filename;
  807.                 yyresult->symbol.line = 1;
  808.               }
  809.               schema_decl_list
  810.             ;
  811.  
  812. schema_decl_list    : /*NULL*/
  813.             | schema_decl_list schema_decl
  814.             ;
  815.  
  816. expression        : simple_expression
  817.               { $$ = $1; }
  818.             | expression TOK_AND expression
  819.               { yyerrok;
  820.                 $$ = BIN_EXPcreate(OP_AND, $1, $3);}
  821.             | expression TOK_OR expression
  822.               { yyerrok;
  823.                 $$ = BIN_EXPcreate(OP_OR, $1, $3);}
  824.             | expression TOK_XOR expression
  825.               { yyerrok;
  826.                 $$ = BIN_EXPcreate(OP_XOR, $1, $3);}
  827.             | expression TOK_LESS_THAN expression
  828.               { yyerrok;
  829.                 $$ = BIN_EXPcreate(OP_LESS_THAN, $1, $3);}
  830.             | expression TOK_GREATER_THAN expression
  831.               { yyerrok;
  832.                 $$ = BIN_EXPcreate(OP_GREATER_THAN, $1, $3);}
  833.             | expression TOK_EQUAL expression
  834.               { yyerrok;
  835.                 $$ = BIN_EXPcreate(OP_EQUAL, $1, $3);}
  836.             | expression TOK_LESS_EQUAL expression
  837.               { yyerrok;
  838.                 $$ = BIN_EXPcreate(OP_LESS_EQUAL, $1, $3);}
  839.             | expression TOK_GREATER_EQUAL expression
  840.               { yyerrok;
  841.                 $$ = BIN_EXPcreate(OP_GREATER_EQUAL, $1, $3);}
  842.             | expression TOK_NOT_EQUAL expression
  843.               { yyerrok;
  844.                 $$ = BIN_EXPcreate(OP_NOT_EQUAL, $1, $3);}
  845.             | expression TOK_INST_EQUAL expression
  846.               { yyerrok;
  847.                 $$ = BIN_EXPcreate(OP_INST_EQUAL, $1, $3);}
  848.             | expression TOK_INST_NOT_EQUAL expression
  849.               { yyerrok;
  850.                 $$ = BIN_EXPcreate(OP_INST_NOT_EQUAL, $1, $3);}
  851.             | expression TOK_IN expression
  852.               { yyerrok;
  853.                 $$ = BIN_EXPcreate(OP_IN, $1, $3);}
  854.             | expression TOK_LIKE expression
  855.               { yyerrok;
  856.                 $$ = BIN_EXPcreate(OP_LIKE, $1, $3);}
  857.             | simple_expression cardinality_op simple_expression
  858.               { yyerrok; }
  859. /*            | expression error 
  860.               { ERROR;
  861.                 $$ = EXPRESSION_NULL; }*/
  862.             ;
  863.  
  864. simple_expression    : unary_expression
  865.               { $$ = $1; }
  866.             | simple_expression TOK_CONCAT_OP simple_expression
  867.               { yyerrok;
  868.                 $$ = BIN_EXPcreate(OP_CONCAT, $1, $3);}
  869.             | simple_expression TOK_EXP simple_expression
  870.               { yyerrok;
  871.                 $$ = BIN_EXPcreate(OP_EXP, $1, $3);}
  872.             | simple_expression TOK_TIMES simple_expression
  873.               { yyerrok;
  874.                 $$ = BIN_EXPcreate(OP_TIMES, $1, $3);}
  875.             | simple_expression TOK_DIV simple_expression
  876.               { yyerrok;
  877.                 $$ = BIN_EXPcreate(OP_DIV, $1, $3);}
  878.             | simple_expression TOK_REAL_DIV simple_expression
  879.               { yyerrok;
  880.                 $$ = BIN_EXPcreate(OP_REAL_DIV, $1, $3);}
  881.             | simple_expression TOK_MOD simple_expression
  882.               { yyerrok;
  883.                 $$ = BIN_EXPcreate(OP_MOD, $1, $3);}
  884.             | simple_expression TOK_PLUS simple_expression
  885.               { yyerrok;
  886.                 $$ = BIN_EXPcreate(OP_PLUS, $1, $3);}
  887.             | simple_expression TOK_MINUS simple_expression
  888.               { yyerrok;
  889.                 $$ = BIN_EXPcreate(OP_MINUS, $1, $3);}
  890. /* this would be for string concatenation, but the parser can't tell whether
  891. something is a string or not, so let it be tagged as just arithmetic plus.
  892.             | simple_expression TOK_PLUS simple_expression
  893.               { yyerrok;
  894.                 $$ = BIN_EXPcreate(OP_CONCAT, $1, $3);}
  895. */
  896. /*            | simple_expression error
  897.               { ERROR;
  898.                 $$ = EXPRESSION_NULL; }*/
  899.             ;
  900.  
  901. expression_list        : expression
  902.               { $$ = LISTcreate();
  903.                 LISTadd_last($$, (Generic)$1); }
  904.             | expression_list TOK_COMMA expression
  905.               { $$ = $1;
  906.                 LISTadd_last($$, (Generic)$3); }
  907.             ;
  908.  
  909. var            : /*NULL*/
  910.               { $$.var = 1;}
  911.             | TOK_VAR
  912.               { $$.var = 0;}
  913.             ;
  914.  
  915. formal_parameter    : var id_list TOK_COLON parameter_type
  916.               { Symbol *tmp; Expression e; Variable v;
  917.                 $$ = $2;
  918.                 LISTdo_links($$, param)
  919.                 tmp = (Symbol *)param->data;
  920. /*                e = EXPcreate_from_symbol($4,tmp);*/
  921.                 e = EXPcreate_from_symbol(Type_Attribute,tmp);
  922.                     v = VARcreate(e,$4);
  923.                     v->flags.optional = $1.var;
  924.                 v->flags.parameter = true;
  925.                 param->data = (Generic)v;
  926.  
  927.                 /* link it in to the current scope's dict */
  928.                 DICTdefine(CURRENT_SCOPE->symbol_table,
  929.                     tmp->name,(Generic)v,
  930.                     tmp,OBJ_VARIABLE);
  931.  
  932.                 /* see explanation of this in TYPEresolve func */
  933.                 /* $4->refcount++; */
  934.                 LISTod;
  935.               }
  936.             ;
  937.  
  938. formal_parameter_list    : /* no parameters */
  939.               { $$ = LIST_NULL; }
  940.             | TOK_LEFT_PAREN formal_parameter_rep TOK_RIGHT_PAREN
  941.               { $$ = $2; }
  942.             ;
  943.  
  944. formal_parameter_rep    : formal_parameter
  945.               { $$ = $1; }
  946.             | formal_parameter_rep semicolon formal_parameter
  947.               { $$ = $1;
  948.                 LISTadd_all($$, $3); }
  949.             ;
  950.  
  951. parameter_type        : basic_type
  952.               { $$ = TYPEcreate_from_body_anonymously($1);
  953.                 SCOPEadd_super($$);}
  954.             | conformant_aggregation
  955.               { $$ = TYPEcreate_from_body_anonymously($1);
  956.                 SCOPEadd_super($$);}
  957.             | defined_type
  958.               { $$ = $1; }
  959.             | generic_type
  960.               { $$ = $1; }
  961.             ;
  962.  
  963. function_call        : function_id actual_parameters
  964.               { $$ = EXPcreate(Type_Funcall);
  965.                 $$->symbol = *$1; SYMBOL_destroy($1);
  966.                 $$->u.funcall.list = $2;}
  967.             ;
  968.  
  969. function_decl        : function_header action_body TOK_END_FUNCTION
  970.               semicolon
  971.               { CURRENT_SCOPE->u.func->body = $2;
  972.                 POP_SCOPE();}
  973. /*            | function_header error TOK_END_FUNCTION semicolon
  974.               { POP_SCOPE();}*/
  975.             ;
  976.  
  977. function_header        : TOK_FUNCTION TOK_IDENTIFIER
  978.               { Function f = ALGcreate(OBJ_FUNCTION); tag_count = 0;
  979.                 if (print_objects_while_running & OBJ_FUNCTION_BITS) fprintf(stdout,"parse: %s (function)\n",$2->name);
  980.  
  981.                 PUSH_SCOPE(f,$2,OBJ_FUNCTION);}
  982.               formal_parameter_list TOK_COLON parameter_type semicolon
  983.               { Function f = CURRENT_SCOPE;
  984.                 f->u.func->parameters = $4;
  985.                 f->u.func->pcount = LISTget_length($4);
  986.                 f->u.func->return_type = $6;
  987.                 f->u.func->tag_count = tag_count;
  988.               }
  989.             ;
  990.  
  991. function_id        : TOK_IDENTIFIER
  992.               { $$ = $1; }
  993.             | TOK_BUILTIN_FUNCTION
  994.               { $$ = $1; }
  995.             ;
  996.  
  997. conformant_aggregation    : aggregate_type
  998.               { $$ = $1; }
  999.             | TOK_ARRAY TOK_OF optional_or_unique parameter_type
  1000.               { $$ = TYPEBODYcreate(array_);
  1001.                 $$->flags.optional = $3.optional;
  1002.                 $$->flags.unique = $3.unique;
  1003.                 $$->base = $4;}
  1004.             | TOK_ARRAY index_spec TOK_OF optional_or_unique parameter_type
  1005.               { $$ = TYPEBODYcreate(array_);
  1006.                 $$->flags.optional = $4.optional;
  1007.                 $$->flags.unique = $4.unique;
  1008.                 $$->base = $5;
  1009.                 $$->upper = $2.upper_limit;
  1010.                 $$->lower = $2.lower_limit;}
  1011.             | TOK_BAG TOK_OF parameter_type
  1012.               { $$ = TYPEBODYcreate(bag_);
  1013.                 $$->base = $3; }
  1014.             | TOK_BAG index_spec TOK_OF parameter_type
  1015.               { $$ = TYPEBODYcreate(bag_);
  1016.                 $$->base = $4;
  1017.                 $$->upper = $2.upper_limit;
  1018.                 $$->lower = $2.lower_limit;}
  1019.             | TOK_LIST TOK_OF unique parameter_type
  1020.               { $$ = TYPEBODYcreate(list_);
  1021.                 $$->flags.unique = $3.unique;
  1022.                 $$->base = $4; }
  1023.             | TOK_LIST index_spec TOK_OF unique parameter_type
  1024.               { $$ = TYPEBODYcreate(list_);
  1025.                 $$->base = $5;
  1026.                 $$->flags.unique = $4.unique;
  1027.                 $$->upper = $2.upper_limit;
  1028.                 $$->lower = $2.lower_limit;}
  1029.             | TOK_SET TOK_OF parameter_type
  1030.               { $$ = TYPEBODYcreate(set_);
  1031.                 $$->base = $3; }
  1032.             | TOK_SET index_spec TOK_OF parameter_type
  1033.               { $$ = TYPEBODYcreate(set_);
  1034.                 $$->base = $4;
  1035.                 $$->upper = $2.upper_limit;
  1036.                 $$->lower = $2.lower_limit;}
  1037.             ;
  1038.  
  1039. generic_type        : TOK_GENERIC
  1040.               { $$ = Type_Generic; }
  1041.             | TOK_GENERIC TOK_COLON TOK_IDENTIFIER
  1042.               { 
  1043.                 TypeBody g = TYPEBODYcreate(generic_);
  1044.                 $$ = TYPEcreate_from_body_anonymously(g);
  1045.                 SCOPEadd_super($$);
  1046.                 g->tag = TYPEcreate_user_defined_tag($$,CURRENT_SCOPE,$3);
  1047.                 SCOPEadd_super(g->tag);
  1048.                   }
  1049.             ;
  1050.  
  1051. id_list            : TOK_IDENTIFIER
  1052.               { $$ = LISTcreate();
  1053.                 LISTadd_last($$, (Generic)$1); }
  1054.             | id_list TOK_COMMA TOK_IDENTIFIER
  1055.               { yyerrok;
  1056.                 $$ = $1;
  1057.                 LISTadd_last($$, (Generic)$3); }
  1058. /*            | error
  1059.               { $$ = LISTcreate(); }*/
  1060. /*            | id_list error
  1061.               { $$ = $1; }*/
  1062. /*            | id_list error TOK_IDENTIFIER
  1063.               { yyerrok;
  1064.                 $$ = $1; }*/
  1065. /*            | id_list TOK_COMMA error
  1066.               { $$ = $1; }*/
  1067.             ;
  1068.  
  1069. identifier        : TOK_SELF
  1070.               {$$ = EXPcreate(Type_Self);}
  1071.             | TOK_QUESTION_MARK
  1072.               {$$ = LITERAL_INFINITY; }
  1073.             | TOK_IDENTIFIER
  1074.               {$$ = EXPcreate(Type_Identifier);
  1075.                 $$->symbol = *($1); SYMBOL_destroy($1);}
  1076.             ;
  1077.  
  1078. if_statement        : TOK_IF expression TOK_THEN statement_rep
  1079.               TOK_END_IF semicolon
  1080.               { $$ = CONDcreate($2,$4,STATEMENT_LIST_NULL);}
  1081.             | TOK_IF expression TOK_THEN statement_rep
  1082.               TOK_ELSE statement_rep TOK_END_IF semicolon
  1083.               { $$ = CONDcreate($2,$4,$6);}
  1084. /*            | TOK_IF expression TOK_THEN statement_rep
  1085.               TOK_ELSE error TOK_END_IF semicolon
  1086.               { $$ = CONDcreate($2,$4,STATEMENT_LIST_NULL);}*/
  1087. /*            | TOK_IF expression TOK_THEN error TOK_END_IF semicolon
  1088.               { $$ = CONDcreate($2, STATEMENT_LIST_NULL, STATEMENT_LIST_NULL);*/
  1089.             ;
  1090.  
  1091. include_directive    : TOK_INCLUDE TOK_STRING_LITERAL semicolon
  1092.             { SCANinclude_file($2); }
  1093.             ;
  1094.  
  1095. increment_control    : TOK_IDENTIFIER TOK_ASSIGNMENT expression TOK_TO
  1096.               expression by_expression
  1097.               { Increment i = INCR_CTLcreate($1, $3, $5, $6);
  1098.             /* scope doesn't really have/need a name, I suppose */
  1099.             /* naming it by the iterator variable is fine */
  1100.             PUSH_SCOPE(i,(Symbol *)0,OBJ_INCREMENT);}
  1101.             ;
  1102.  
  1103. index_spec        : TOK_LEFT_BRACKET expression TOK_COLON expression
  1104.               TOK_RIGHT_BRACKET
  1105.               { $$.lower_limit = $2;
  1106.                 $$.upper_limit = $4; }
  1107. /*            | TOK_LEFT_BRACKET expression error TOK_RIGHT_BRACKET
  1108.               { $$.lower_limit = $2;
  1109.                 $$.upper_limit = LITERAL_INFINITY; }*/
  1110. /*            | TOK_LEFT_BRACKET error TOK_RIGHT_BRACKET
  1111.               { $$.lower_limit = LITERAL_INFINITY;
  1112.                 $$.upper_limit = LITERAL_INFINITY; }*/
  1113.             ;
  1114.  
  1115. initializer        : TOK_ASSIGNMENT expression
  1116.               { $$ = $2; }
  1117.             ;
  1118.  
  1119. rename            : TOK_IDENTIFIER
  1120.               { (*interface_func)(CURRENT_SCOPE,interface_schema,$1,$1);}
  1121.             | TOK_IDENTIFIER TOK_AS TOK_IDENTIFIER
  1122.               { (*interface_func)(CURRENT_SCOPE,interface_schema,$1,$3);}
  1123.             ;
  1124.  
  1125. rename_list        : rename
  1126.             | rename_list TOK_COMMA rename
  1127.             ;
  1128.  
  1129. parened_rename_list    : TOK_LEFT_PAREN rename_list TOK_RIGHT_PAREN
  1130.             ;
  1131.  
  1132. reference_clause    : TOK_REFERENCE TOK_FROM TOK_IDENTIFIER semicolon
  1133.               { if (!CURRENT_SCHEMA->reflist) CURRENT_SCHEMA->reflist = LISTcreate();
  1134.                 LISTadd(CURRENT_SCHEMA->reflist,(Generic)$3);}
  1135.             | TOK_REFERENCE TOK_FROM TOK_IDENTIFIER 
  1136.               {interface_schema = $3; interface_func = SCHEMAadd_reference;}
  1137.               parened_rename_list semicolon
  1138.             ;
  1139.  
  1140. use_clause        : TOK_USE TOK_FROM TOK_IDENTIFIER semicolon
  1141.               { if (!CURRENT_SCHEMA->uselist) CURRENT_SCHEMA->uselist = LISTcreate();
  1142.                 LISTadd(CURRENT_SCHEMA->uselist,(Generic)$3);}
  1143.             | TOK_USE TOK_FROM TOK_IDENTIFIER
  1144.               {interface_schema = $3; interface_func = SCHEMAadd_use;}
  1145.               parened_rename_list semicolon
  1146.             ;
  1147.  
  1148. interface_specification    : use_clause
  1149.             | reference_clause
  1150.             ;
  1151.  
  1152. interface_specification_list    : /*NULL*/
  1153.             | interface_specification_list interface_specification
  1154.             ;
  1155.  
  1156. interval        : TOK_LEFT_CURL simple_expression rel_op
  1157.               simple_expression rel_op simple_expression
  1158.               right_curl
  1159.               { Expression    tmp1, tmp2;
  1160.  
  1161.                 $$ = (Expression )0;
  1162.                 tmp1 = BIN_EXPcreate($3, $2, $4);
  1163.                 tmp2 = BIN_EXPcreate($5, $4, $6);
  1164.                 $$ = BIN_EXPcreate(OP_AND, tmp1, tmp2);
  1165.               }
  1166.             ;
  1167.  
  1168. /* defined_type might have to be something else since it's really an */
  1169. /* entity_ref */
  1170. set_or_bag_of_entity    : defined_type
  1171.               { $$.type = $1;
  1172.                 $$.body = 0;}
  1173.             | TOK_SET TOK_OF defined_type
  1174.               { $$.type = 0;
  1175.                 $$.body = TYPEBODYcreate(set_);
  1176.                 $$.body->base = $3; }
  1177.             | TOK_SET limit_spec TOK_OF defined_type
  1178.               { $$.type = 0;
  1179.                 $$.body = TYPEBODYcreate(set_);
  1180.                 $$.body->base = $4;
  1181.                 $$.body->upper = $2.upper_limit;
  1182.                 $$.body->lower = $2.lower_limit;}
  1183.             | TOK_BAG limit_spec TOK_OF defined_type
  1184.               { $$.type = 0;
  1185.                 $$.body = TYPEBODYcreate(bag_);
  1186.                 $$.body->base = $4;
  1187.                 $$.body->upper = $2.upper_limit;
  1188.                 $$.body->lower = $2.lower_limit;}
  1189.             | TOK_BAG TOK_OF defined_type
  1190.               { $$.type = 0;
  1191.                 $$.body = TYPEBODYcreate(bag_);
  1192.                 $$.body->base = $3; }
  1193.             ;
  1194.  
  1195. inverse_attr_list    : inverse_attr
  1196.             { $$ = LISTcreate();
  1197.               LISTadd_last($$,(Generic)$1);}
  1198.             | inverse_attr_list inverse_attr
  1199.               { $$ = $1;
  1200.                 LISTadd_last($$, (Generic)$2); }
  1201.             ;
  1202.  
  1203. inverse_attr        : TOK_IDENTIFIER TOK_COLON set_or_bag_of_entity
  1204.                 TOK_FOR TOK_IDENTIFIER semicolon
  1205.             { Expression e = EXPcreate(Type_Attribute);
  1206.               e->symbol = *$1;SYMBOL_destroy($1);
  1207.               if ($3.type) $$ = VARcreate(e,$3.type);
  1208.               else {
  1209.                   Type t = TYPEcreate_from_body_anonymously($3.body);
  1210.                   SCOPEadd_super(t);
  1211.                   $$ = VARcreate(e,t);
  1212.               }
  1213.               $$->inverse_symbol = $5;}
  1214.             ;
  1215.  
  1216. inverse_clause        : /*NULL*/
  1217.               { $$ = LIST_NULL; }
  1218.             | TOK_INVERSE inverse_attr_list
  1219.               { $$ = $2; }
  1220.             ;
  1221.  
  1222. limit_spec        : TOK_LEFT_BRACKET expression TOK_COLON
  1223.               expression TOK_RIGHT_BRACKET
  1224.               { $$.lower_limit = $2;
  1225.                 $$.upper_limit = $4; }
  1226. /*            | TOK_LEFT_BRACKET expression error TOK_RIGHT_BRACKET
  1227.               { $$.lower_limit = $2;
  1228.                 $$.upper_limit = LITERAL_INFINITY; }*/
  1229. /*            | TOK_LEFT_BRACKET error TOK_RIGHT_BRACKET
  1230.               { $$.lower_limit = LITERAL_INFINITY; 
  1231.                 $$.upper_limit = LITERAL_INFINITY; }*/
  1232. /*            | error
  1233.               { $$.lower_limit = LITERAL_INFINITY;
  1234.                 $$.upper_limit = LITERAL_INFINITY; }*/
  1235.             ;
  1236.  
  1237. list_type        : TOK_LIST limit_spec TOK_OF unique attribute_type
  1238.               { $$ = TYPEBODYcreate(list_);
  1239.                 $$->base = $5;
  1240.                 $$->flags.unique = $4.unique;
  1241.                 $$->lower = $2.lower_limit;
  1242.                 $$->upper = $2.upper_limit;}
  1243.             | TOK_LIST TOK_OF unique attribute_type
  1244.               { $$ = TYPEBODYcreate(list_);
  1245.                 $$->base = $4;
  1246.                 $$->flags.unique = $3.unique;}
  1247.             ;
  1248.  
  1249. literal            : TOK_INTEGER_LITERAL
  1250.               { if ($1 == 0)
  1251.                 $$ = LITERAL_ZERO;
  1252.                 else if ($1 == 1)
  1253.                 $$ = LITERAL_ONE;
  1254.                 else {
  1255.                 $$ = EXPcreate_simple(Type_Integer);
  1256.                 /*SUPPRESS 112*/
  1257.                 $$->u.integer = (int)$1;
  1258.                 resolved_all($$);
  1259.                 } }
  1260.             | TOK_REAL_LITERAL
  1261.               { if ($1 == 0.0)
  1262.                 $$ = LITERAL_ZERO;
  1263.                 else {
  1264.                 $$ = EXPcreate_simple(Type_Real);
  1265.                 $$->u.real = $1;
  1266.                 resolved_all($$);
  1267.                 } }
  1268.             | TOK_STRING_LITERAL
  1269.               { $$ = EXPcreate_simple(Type_String);
  1270.                 $$->symbol.name = $1;
  1271.                 resolved_all($$);}
  1272.             | TOK_STRING_LITERAL_ENCODED
  1273.               { $$ = EXPcreate_simple(Type_String_Encoded);
  1274.                 $$->symbol.name = $1;
  1275.                 resolved_all($$);}
  1276.             | TOK_LOGICAL_LITERAL
  1277.               { $$ = EXPcreate_simple(Type_Logical);
  1278.                 $$->u.logical = $1;
  1279.                 resolved_all($$);}
  1280.             | TOK_BINARY_LITERAL
  1281.               { $$ = EXPcreate_simple(Type_Binary);
  1282.                 $$->symbol.name = $1;
  1283.                 resolved_all($$);}
  1284.             | constant
  1285.               { $$ = $1; }
  1286.             ;
  1287.  
  1288. local_initializer    : TOK_ASSIGNMENT expression
  1289.               { $$ = $2; }
  1290.             ;
  1291.  
  1292. local_variable        : id_list TOK_COLON parameter_type semicolon
  1293.               { Expression e; Variable v;
  1294.                 LISTdo($1, sym, Symbol *)
  1295.                 /* convert symbol to name-expression */
  1296.                 e = EXPcreate(Type_Attribute);
  1297.                 e->symbol = *sym;SYMBOL_destroy(sym);
  1298.                 v = VARcreate(e,$3);
  1299.                 DICTdefine(CURRENT_SCOPE->symbol_table,
  1300.                     e->symbol.name,(Generic)v,&e->symbol,OBJ_VARIABLE);
  1301.                 LISTod; LISTfree($1); }
  1302.             | id_list TOK_COLON parameter_type local_initializer semicolon
  1303.               { Expression e; Variable v;
  1304.                 LISTdo($1, sym, Symbol *)
  1305.                 e = EXPcreate(Type_Attribute);
  1306.                 e->symbol = *sym;SYMBOL_destroy(sym);
  1307.                 v = VARcreate(e,$3);
  1308.                 v->initializer = $4;
  1309.                 DICTdefine(CURRENT_SCOPE->symbol_table,
  1310.                     e->symbol.name,(Generic)v,&e->symbol,OBJ_VARIABLE);
  1311.                 LISTod; LISTfree($1);}
  1312.             ;
  1313.  
  1314. local_body        : /* no local_variables */
  1315.             | local_variable local_body
  1316.             ;
  1317.  
  1318. local_decl        : TOK_LOCAL local_body TOK_END_LOCAL semicolon
  1319.               { }
  1320. /*            | TOK_LOCAL error TOK_END_LOCAL semicolon
  1321.               { }*/
  1322.             ;
  1323.  
  1324. defined_type        : TOK_IDENTIFIER
  1325.               { $$ = TYPEcreate_name($1);
  1326.                 SCOPEadd_super($$);
  1327.                 SYMBOL_destroy($1);}
  1328.             ;
  1329.  
  1330. defined_type_list        : defined_type
  1331.               { $$ = LISTcreate();
  1332.                 LISTadd($$, (Generic)$1); }
  1333.             | defined_type_list TOK_COMMA defined_type
  1334.               { $$ = $1;
  1335.                 LISTadd_last($$, (Generic)$3); }
  1336.             ;
  1337.  
  1338. nested_id_list        : TOK_LEFT_PAREN id_list TOK_RIGHT_PAREN
  1339.               { $$ = $2; }
  1340.             ;
  1341.  
  1342. oneof_op        : TOK_ONEOF
  1343.             ;
  1344.  
  1345. optional_or_unique    : /* NULL body */
  1346.               { $$.unique = 0; $$.optional = 0;}
  1347.             | TOK_OPTIONAL
  1348.               { $$.unique = 0; $$.optional = 1;}
  1349.             | TOK_UNIQUE
  1350.               { $$.unique = 1; $$.optional = 0;}
  1351.             | TOK_OPTIONAL TOK_UNIQUE
  1352.               { $$.unique = 1; $$.optional = 1;}
  1353.             | TOK_UNIQUE TOK_OPTIONAL
  1354.               { $$.unique = 1; $$.optional = 1;}
  1355.             ;
  1356.  
  1357. optional_fixed        : /* nuthin' */
  1358.               { $$.fixed = 0; }
  1359.             | TOK_FIXED
  1360.               { $$.fixed = 1; }
  1361.             ;
  1362.  
  1363. precision_spec        : /* no precision specified */
  1364.               { $$ = (Expression )0; }
  1365.             | TOK_LEFT_PAREN expression TOK_RIGHT_PAREN
  1366.               { $$ = $2; }
  1367.             ;
  1368.  
  1369. /* NOTE: actual parameters cannot go to NULL, since this causes */
  1370. /* a syntactic ambiguity (see note at actual_parameters).  hence */
  1371. /* the need for the second branch of this rule. */
  1372.  
  1373. proc_call_statement    : procedure_id actual_parameters semicolon
  1374.               { $$ = PCALLcreate($2);
  1375.                 $$->symbol = *($1);}
  1376.             | procedure_id semicolon
  1377.               { $$ = PCALLcreate((Linked_List)0);
  1378.                 $$->symbol = *($1);}
  1379.             ;
  1380.  
  1381. procedure_decl        : procedure_header action_body TOK_END_PROCEDURE
  1382.               semicolon
  1383.               { CURRENT_SCOPE->u.proc->body = $2;
  1384.                 POP_SCOPE();}
  1385.  
  1386. /*            | procedure_header error TOK_END_PROCEDURE semicolon
  1387.               { POP_SCOPE();}*/
  1388.             ;
  1389.  
  1390. procedure_header    : TOK_PROCEDURE TOK_IDENTIFIER
  1391.               { Procedure p = ALGcreate(OBJ_PROCEDURE); tag_count = 0;
  1392.                 if (print_objects_while_running & OBJ_PROCEDURE_BITS){
  1393.                 fprintf(stdout,"parse: %s (procedure)\n",$2->name);
  1394.                 }
  1395.  
  1396.                 PUSH_SCOPE(p,$2,OBJ_PROCEDURE);}
  1397.               formal_parameter_list semicolon
  1398.               { CURRENT_SCOPE->u.proc->parameters = $4; 
  1399.                 CURRENT_SCOPE->u.proc->pcount = LISTget_length($4);
  1400.                 CURRENT_SCOPE->u.proc->tag_count = tag_count;
  1401.               }
  1402.             ;
  1403.  
  1404. procedure_id        : TOK_IDENTIFIER
  1405.               { $$ = $1; }
  1406.             | TOK_BUILTIN_PROCEDURE
  1407.               { $$ = $1; }
  1408.             ;
  1409.  
  1410. qualifier        :
  1411.               TOK_DOT TOK_IDENTIFIER
  1412.               { $$ = BIN_EXPcreate(OP_DOT,(Expression )0,(Expression )0);
  1413.                 $$->e.op2 = EXPcreate(Type_Identifier);
  1414.                 $$->e.op2->symbol = *$2; SYMBOL_destroy($2);}
  1415.             | TOK_BACKSLASH TOK_IDENTIFIER
  1416.               { $$ = BIN_EXPcreate(OP_GROUP,(Expression )0,(Expression )0);
  1417.                 $$->e.op2 = EXPcreate(Type_Identifier);
  1418.                 $$->e.op2->symbol = *$2; SYMBOL_destroy($2);}
  1419.             | TOK_LEFT_BRACKET simple_expression TOK_RIGHT_BRACKET
  1420.               { $$ = BIN_EXPcreate(OP_ARRAY_ELEMENT,(Expression )0,(Expression )0);
  1421.                 $$->e.op2 = $2;}
  1422.             | TOK_LEFT_BRACKET simple_expression TOK_COLON
  1423.                        simple_expression TOK_RIGHT_BRACKET
  1424.               { $$ = TERN_EXPcreate(OP_SUBCOMPONENT,(Expression )0,(Expression )0,(Expression )0);
  1425.                 $$->e.op2 = $2;
  1426.                 $$->e.op3 = $4;}
  1427.             ;
  1428.  
  1429. query_expression    : TOK_QUERY TOK_LEFT_PAREN
  1430.               TOK_IDENTIFIER TOK_ALL_IN expression
  1431.               TOK_SUCH_THAT
  1432.               {
  1433.                 $<expression>$ = QUERYcreate($3,$5);
  1434.                 SYMBOL_destroy($3);
  1435.                 PUSH_SCOPE($<expression>$->u.query->scope,(Symbol *)0,OBJ_QUERY);
  1436.               }
  1437.               expression TOK_RIGHT_PAREN
  1438.               {
  1439.                 $$ = $<expression>7;    /* nice syntax, eh? */
  1440.                 $$->u.query->expression = $8;
  1441.                 POP_SCOPE();
  1442.               }
  1443.             ;
  1444.  
  1445. rel_op            : TOK_LESS_THAN
  1446.               { $$ = OP_LESS_THAN; }
  1447.             | TOK_GREATER_THAN
  1448.               { $$ = OP_GREATER_THAN; }
  1449.             | TOK_EQUAL
  1450.               { $$ = OP_EQUAL; }
  1451.             | TOK_LESS_EQUAL
  1452.               { $$ = OP_LESS_EQUAL; }
  1453.             | TOK_GREATER_EQUAL
  1454.               { $$ = OP_GREATER_EQUAL; }
  1455.             | TOK_NOT_EQUAL
  1456.               { $$ = OP_NOT_EQUAL; }
  1457.             | TOK_INST_EQUAL
  1458.               { $$ = OP_INST_EQUAL; }
  1459.             | TOK_INST_NOT_EQUAL
  1460.               { $$ = OP_INST_NOT_EQUAL; }
  1461.             ;
  1462.  
  1463. /* repeat_statement causes a scope creation if an increment_control exists */
  1464. repeat_statement    : TOK_REPEAT increment_control
  1465.                 while_control until_control semicolon
  1466.               statement_rep TOK_END_REPEAT semicolon
  1467.               { $$ = LOOPcreate(CURRENT_SCOPE,$3,$4,$6);
  1468.                 /* matching PUSH_SCOPE is in increment_control */
  1469.                 POP_SCOPE(); }
  1470.             | TOK_REPEAT while_control until_control semicolon
  1471.               statement_rep TOK_END_REPEAT semicolon
  1472.               { $$ = LOOPcreate((struct Scope *)0,$2,$3,$5);}
  1473. /*            | TOK_REPEAT error TOK_END_REPEAT semicolon
  1474.               { $$ = STATEMENT_NULL; }*/
  1475.             ;
  1476.  
  1477. return_statement    : TOK_RETURN semicolon
  1478.               { $$ = RETcreate((Expression )0);}
  1479.             | TOK_RETURN TOK_LEFT_PAREN expression TOK_RIGHT_PAREN
  1480.               semicolon
  1481.               { $$ = RETcreate($3);}
  1482.             ;
  1483.  
  1484. right_curl        : TOK_RIGHT_CURL
  1485.               { yyerrok; }
  1486.             ;
  1487.  
  1488. rule_decl        : rule_header action_body where_rule TOK_END_RULE semicolon
  1489.               { RULEput_body(CURRENT_SCOPE,$2);
  1490.                 RULEput_where(CURRENT_SCOPE,$3);
  1491.                 POP_SCOPE();}
  1492. /*            | rule_header error TOK_END_RULE semicolon
  1493.               { POP_SCOPE();}*/
  1494.             ;
  1495.  
  1496. rule_formal_parameter    : TOK_IDENTIFIER
  1497.               { Expression e; Type t;
  1498.                 /* it's true that we know it will be an */
  1499.                 /* entity_ type later */
  1500.                 TypeBody tb = TYPEBODYcreate(set_);
  1501.                 tb->base = TYPEcreate_name($1);
  1502.                 SCOPEadd_super(tb->base);
  1503.                 t = TYPEcreate_from_body_anonymously(tb);
  1504.                 SCOPEadd_super(t);
  1505.                 e = EXPcreate_from_symbol(t,$1);
  1506.                 $$ = VARcreate(e,t);
  1507.                 $$->flags.parameter = true;
  1508.                 /* link it in to the current scope's dict */
  1509.                 DICTdefine(CURRENT_SCOPE->symbol_table,
  1510.                 $1->name,(Generic)$$,$1,OBJ_VARIABLE);
  1511.             }
  1512.             ;
  1513.  
  1514. rule_formal_parameter_list    : rule_formal_parameter
  1515.               { $$ = LISTcreate();
  1516.                 LISTadd($$, (Generic)$1); }
  1517.             | rule_formal_parameter_list TOK_COMMA rule_formal_parameter
  1518.               { $$ = $1;
  1519.                 LISTadd_last($$, (Generic)$3); }
  1520.             ;
  1521.  
  1522. rule_header        : TOK_RULE TOK_IDENTIFIER TOK_FOR TOK_LEFT_PAREN
  1523.               { Rule r = ALGcreate(OBJ_RULE);
  1524.                 if (print_objects_while_running & OBJ_RULE_BITS){
  1525.                 fprintf(stdout,"parse: %s (rule)\n",$2->name);
  1526.                 }
  1527.                 PUSH_SCOPE(r,$2,OBJ_RULE);
  1528.                   }
  1529.               rule_formal_parameter_list TOK_RIGHT_PAREN semicolon
  1530.               {  CURRENT_SCOPE->u.rule->parameters = $6; }
  1531.             ;
  1532.  
  1533. schema_body        : interface_specification_list
  1534.                         block_list
  1535.             | interface_specification_list constant_decl
  1536.                         block_list
  1537.             ;
  1538.  
  1539. schema_decl        : schema_header schema_body TOK_END_SCHEMA
  1540.               semicolon
  1541.               { POP_SCOPE();}
  1542.             | include_directive
  1543. /*            | schema_header error TOK_END_SCHEMA semicolon
  1544.               { POP_SCOPE();}*/
  1545.             ;
  1546.  
  1547. schema_header        : TOK_SCHEMA TOK_IDENTIFIER semicolon
  1548.               { Schema schema = DICTlookup(CURRENT_SCOPE->symbol_table,$2->name);
  1549.  
  1550.                 if (print_objects_while_running & OBJ_SCHEMA_BITS){
  1551.                 fprintf(stdout,"parse: %s (schema)\n",$2->name);
  1552.                 }
  1553.                // if (EXPRESSignore_duplicate_schemas && schema) {
  1554.             //    SCANskip_to_end_schema();
  1555.                 //PUSH_SCOPE_DUMMY();
  1556.               // } else {
  1557.                 schema = SCHEMAcreate();
  1558.                 LISTadd_last(PARSEnew_schemas,(Generic)schema);
  1559.                 PUSH_SCOPE(schema,$2,OBJ_SCHEMA);
  1560.                // }
  1561.                   }
  1562.             ;
  1563.  
  1564. select_type        : TOK_SELECT TOK_LEFT_PAREN defined_type_list
  1565.               TOK_RIGHT_PAREN
  1566.               { $$ = TYPEBODYcreate(select_);
  1567.                 $$->list = $3; }
  1568.             ;
  1569.  
  1570. semicolon        : TOK_SEMICOLON
  1571.               { yyerrok; }
  1572.             ;
  1573.  
  1574. set_type        : TOK_SET limit_spec TOK_OF attribute_type
  1575.               { $$ = TYPEBODYcreate(set_);
  1576.                 $$->base = $4;
  1577.                 $$->lower = $2.lower_limit;
  1578.                 $$->upper = $2.upper_limit;}
  1579.             | TOK_SET TOK_OF attribute_type
  1580.               { $$ = TYPEBODYcreate(set_);
  1581.                 $$->base = $3;}
  1582.             ;
  1583.  
  1584. skip_statement        : TOK_SKIP semicolon
  1585.               { $$ = STATEMENT_SKIP; }
  1586.             ;
  1587.  
  1588. statement        : alias_statement
  1589.               { $$ = $1; }
  1590.             | assignment_statement
  1591.               { $$ = $1; }
  1592.             | case_statement
  1593.               { $$ = $1; }
  1594.             | compound_statement
  1595.               { $$ = $1; }
  1596.             | escape_statement
  1597.               { $$ = $1; }
  1598.             | if_statement
  1599.               { $$ = $1; }
  1600.             | proc_call_statement
  1601.               { $$ = $1; }
  1602.             | repeat_statement
  1603.               { $$ = $1; }
  1604.             | return_statement
  1605.               { $$ = $1; }
  1606.             | skip_statement
  1607.               { $$ = $1; }
  1608. /*            | error semicolon
  1609.               { $$ = STATEMENT_NULL; }*/
  1610.             ;
  1611.  
  1612. statement_rep        : /* no statements */
  1613.               { $$ = LISTcreate(); }
  1614.             | /* ignore null statement */
  1615.               semicolon statement_rep
  1616.               { $$ = $2; }
  1617.             | statement statement_rep
  1618.               { $$ = $2;
  1619.                 LISTadd_first($$, (Generic)$1); }
  1620.             ;
  1621.  
  1622. /* if the actions look backwards, remember the declaration syntax:  */
  1623. /* <entity> SUPERTYPE OF <subtype1> ... SUBTYPE OF <supertype1> ... */
  1624.  
  1625. subsuper_decl        : /* NULL body */
  1626.               { $$.subtypes = EXPRESSION_NULL;
  1627.                 $$.abstract = false;
  1628.                 $$.supertypes = LIST_NULL; }
  1629.             | supertype_decl
  1630.               { $$.subtypes = $1.subtypes;
  1631.                 $$.abstract = $1.abstract;
  1632.                 $$.supertypes = LIST_NULL; }
  1633.             | subtype_decl
  1634.               { $$.supertypes = $1;
  1635.                 $$.abstract = false;
  1636.                 $$.subtypes = EXPRESSION_NULL; }
  1637. /*            | subtype_decl supertype_decl
  1638.               { $$.supertypes = $1;
  1639.                 $$.abstract = $2.abstract;
  1640.                 $$.subtypes = $2.subtypes; }*/
  1641.             | supertype_decl subtype_decl
  1642.               { $$.subtypes = $1.subtypes;
  1643.                 $$.abstract = $1.abstract;
  1644.                 $$.supertypes = $2; }
  1645.             ;
  1646.  
  1647. subtype_decl        : TOK_SUBTYPE TOK_OF TOK_LEFT_PAREN defined_type_list
  1648.               TOK_RIGHT_PAREN
  1649.               { $$ = $4; }
  1650.             ;
  1651.  
  1652. supertype_decl        : TOK_ABSTRACT TOK_SUPERTYPE
  1653.               { $$.subtypes = (Expression)0;
  1654.                 $$.abstract = true; }
  1655.             | TOK_SUPERTYPE TOK_OF TOK_LEFT_PAREN
  1656.               supertype_expression TOK_RIGHT_PAREN
  1657.               { $$.subtypes = $4;
  1658.                 $$.abstract = false; }
  1659.             | TOK_ABSTRACT TOK_SUPERTYPE TOK_OF TOK_LEFT_PAREN
  1660.               supertype_expression TOK_RIGHT_PAREN
  1661.               { $$.subtypes = $5;
  1662.                 $$.abstract = true; }
  1663.             ;
  1664.  
  1665. supertype_expression    : supertype_factor
  1666.               { $$ = $1.subtypes; }
  1667.             | supertype_expression TOK_AND supertype_factor
  1668.               { $$ = BIN_EXPcreate(OP_AND, $1, $3.subtypes);}
  1669.             | supertype_expression TOK_ANDOR supertype_factor
  1670.               { $$ = BIN_EXPcreate(OP_ANDOR, $1, $3.subtypes);}
  1671.             ;
  1672.  
  1673. supertype_expression_list    : supertype_expression
  1674.             { $$ = LISTcreate();
  1675.                 LISTadd_last($$,(Generic)$1); }
  1676.             | supertype_expression_list TOK_COMMA supertype_expression
  1677.                 { LISTadd_last($1,(Generic)$3);
  1678.                   $$ = $1;}
  1679.             ;
  1680.  
  1681. supertype_factor    : identifier
  1682.               { $$.subtypes = $1; }
  1683.             | oneof_op TOK_LEFT_PAREN supertype_expression_list
  1684.                 TOK_RIGHT_PAREN
  1685.               { $$.subtypes = EXPcreate(Type_Oneof);
  1686.                 $$.subtypes->u.list = $3;}
  1687.             | TOK_LEFT_PAREN supertype_expression TOK_RIGHT_PAREN
  1688.               { $$.subtypes = $2; }
  1689.             ;
  1690.  
  1691. type            : aggregation_type
  1692.               { $$.type = 0;
  1693.                 $$.body = $1; }
  1694.             | basic_type
  1695.               { $$.type = 0;
  1696.                 $$.body = $1; }
  1697.             | defined_type
  1698.               { $$.type = $1;
  1699.                 $$.body = 0; }
  1700.             | select_type
  1701.               { $$.type = 0;
  1702.                 $$.body = $1; }
  1703.             ;
  1704.  
  1705. type_item_body        : enumeration_type
  1706.             | type {
  1707.                 CURRENT_SCOPE->u.type->head = $1.type;
  1708.                 CURRENT_SCOPE->u.type->body = $1.body;
  1709.             }
  1710.             ;
  1711.  
  1712. type_item        : TOK_IDENTIFIER TOK_EQUAL {
  1713.                 Type t = TYPEcreate_name($1);
  1714.                 PUSH_SCOPE(t,$1,OBJ_TYPE);
  1715.             } type_item_body {
  1716.                 SYMBOL_destroy($1);
  1717.                 } semicolon
  1718.             ;
  1719.  
  1720. type_decl        : TOK_TYPE type_item {
  1721.                 POP_SCOPE();
  1722.               } TOK_END_TYPE semicolon
  1723.             | TOK_TYPE type_item where_rule {
  1724.                 CURRENT_SCOPE->where = $3;
  1725.                 POP_SCOPE();
  1726.               } TOK_END_TYPE semicolon
  1727. /*            | TOK_TYPE error TOK_END_TYPE semicolon*/
  1728.             ;
  1729.  
  1730.  
  1731. /* this is anything that can be assigned to */
  1732. general_ref        : general_ref qualifier
  1733.               { $2->e.op1 = $1;
  1734.                 $$ = $2;}
  1735.             | identifier
  1736.               { $$ = $1; }
  1737.             ;
  1738.  
  1739. unary_expression    : aggregate_initializer
  1740.               { $$ = $1; }
  1741.             | unary_expression qualifier 
  1742.               { $2->e.op1 = $1;
  1743.                 $$ = $2;}
  1744.             | literal
  1745.               { $$ = $1; }
  1746.             | function_call
  1747.               { $$ = $1; }
  1748.             | identifier
  1749.               { $$ = $1; }
  1750.             | TOK_LEFT_PAREN expression TOK_RIGHT_PAREN
  1751.               { $$ = $2; }
  1752. /*            | TOK_LEFT_PAREN expression error
  1753.               { $$ = $2; }*/
  1754.             | interval
  1755.               { $$ = $1; }
  1756. /*subsuper_init looks just like any expression */
  1757. /*            | subsuper_init
  1758.               { $$ = $1; }*/
  1759.             | query_expression
  1760.               { $$ = $1; }
  1761.             | TOK_NOT unary_expression
  1762.               { $$ = UN_EXPcreate(OP_NOT, $2);}
  1763.             | TOK_PLUS unary_expression        %prec TOK_NOT
  1764.               { $$ = $2; }
  1765.             | TOK_MINUS unary_expression        %prec TOK_NOT
  1766.               { $$ = UN_EXPcreate(OP_NEGATE, $2);}
  1767. /*            | error
  1768.               { /*ERROR(ERROR_expression);*/ 
  1769. /*                $$ = EXPRESSION_NULL; }*/
  1770.             ;
  1771.  
  1772. unique            : /* look for optional UNIQUE */
  1773.               { $$.unique = 0;}
  1774.             | TOK_UNIQUE
  1775.               { $$.unique = 1;}
  1776.             ;
  1777.  
  1778. qualified_attr        : TOK_IDENTIFIER
  1779.               { $$ = QUAL_ATTR_new();
  1780.                 $$->attribute = $1;
  1781.               }
  1782.             | TOK_SELF TOK_BACKSLASH TOK_IDENTIFIER TOK_DOT TOK_IDENTIFIER
  1783.               { $$ = QUAL_ATTR_new();
  1784.                 $$->entity = $3;
  1785.                 $$->attribute = $5;
  1786.               }
  1787.             ;
  1788.  
  1789. qualified_attr_list    : qualified_attr
  1790.               { $$ = LISTcreate();
  1791.                 LISTadd_last($$, (Generic)$1); }
  1792.             | qualified_attr_list TOK_COMMA qualified_attr
  1793.               { $$ = $1;
  1794.                 LISTadd_last($$, (Generic)$3); }
  1795.             ;
  1796.  
  1797. labelled_attrib_list    : qualified_attr_list semicolon
  1798.               { LISTadd_first($1,(Generic)EXPRESSION_NULL);
  1799.                 $$ = $1;}
  1800.             | TOK_IDENTIFIER TOK_COLON qualified_attr_list semicolon
  1801.               { LISTadd_first($3,(Generic)$1);
  1802.                 $$ = $3;}
  1803.             ;
  1804.  
  1805. /*
  1806. labelled_attrib_list    : /* these could be unary_expression_lists instead */
  1807.               /* of expression_lists if there is a parse prob */
  1808. /*              expression_list semicolon
  1809.               { LISTadd_first($1,(Generic)EXPRESSION_NULL);
  1810.                 $$ = $1;}
  1811.             | TOK_IDENTIFIER TOK_COLON expression_list semicolon
  1812.               { LISTadd_first($3,(Generic)$1);
  1813.                 $$ = $3;}
  1814.             ;
  1815. */
  1816.  
  1817. /* returns a list */
  1818. labelled_attrib_list_list    :
  1819.               labelled_attrib_list
  1820.               { $$ = LISTcreate();
  1821.                 LISTadd_last($$,(Generic)$1); }
  1822.             | labelled_attrib_list_list labelled_attrib_list
  1823.                 { LISTadd_last($1,(Generic)$2);
  1824.                   $$ = $1;}
  1825.             ;
  1826.  
  1827. unique_clause        : 
  1828.               /* unique clause is always optional */
  1829.               { $$ = 0; }
  1830.             | TOK_UNIQUE labelled_attrib_list_list
  1831.               { $$ = $2; }
  1832.             ;
  1833.  
  1834. until_control        : /* NULL */
  1835.             { $$ = 0; }
  1836.             | TOK_UNTIL expression
  1837.               { $$ = $2;}
  1838.             ;
  1839.  
  1840. where_clause        : expression semicolon
  1841.               { $$ = WHERE_new();
  1842.                 $$->label = 0;
  1843.                 $$->expr = $1;
  1844.                   }
  1845.             | TOK_IDENTIFIER TOK_COLON expression semicolon
  1846.               { $$ = WHERE_new();
  1847.                 $$->label = $1;
  1848.                 $$->expr = $3;
  1849.                 if (!CURRENT_SCOPE->symbol_table) {
  1850.                 CURRENT_SCOPE->symbol_table = DICTcreate(25);
  1851.                 }
  1852.                 DICTdefine(CURRENT_SCOPE->symbol_table,$1->name,
  1853.                 (Generic)$$,$1,OBJ_WHERE);
  1854.                   }
  1855.             ;
  1856.  
  1857. where_clause_list    : where_clause
  1858.               { $$ = LISTcreate();
  1859.                 LISTadd($$, (Generic)$1); }
  1860.             | where_clause_list where_clause
  1861.               { $$ = $1;
  1862.                 LISTadd_last($$, (Generic)$2); }
  1863. /*            | where_clause_list error
  1864.               { $$ = $1; }*/
  1865.             ;
  1866.  
  1867. where_rule        : /* NULL body: no where rule */
  1868.               { $$ = LIST_NULL; }
  1869.             | TOK_WHERE where_clause_list
  1870.               { $$ = $2; }
  1871.             ;
  1872.  
  1873. while_control        : /* NULL */
  1874.             { $$ = 0; }
  1875.             | TOK_WHILE expression
  1876.               { $$ = $2;}
  1877.             ;
  1878.  
  1879. %%
  1880. static void
  1881. yyerror(string)
  1882. char* string;
  1883. {
  1884.     char buf[200];
  1885.     Symbol sym;
  1886.  
  1887.     strcpy (buf, string);
  1888.  
  1889.     if (yyeof) strcat(buf, " at end of input");
  1890.     else if (yytext[0] == 0) strcat(buf, " at null character");
  1891.     else if (yytext[0] < 040 || yytext[0] >= 0177)
  1892.         sprintf(buf + strlen(buf), " before character 0%o", yytext[0]);
  1893.     else    sprintf(buf + strlen(buf), " before `%s'", yytext);
  1894.  
  1895.     sym.line = yylineno;
  1896.     sym.filename = current_filename;
  1897.     ERRORreport_with_symbol(ERROR_syntax, &sym, buf, CURRENT_SCOPE_TYPE_PRINTABLE,CURRENT_SCOPE_NAME);
  1898.   }
  1899.  
  1900. static void
  1901. yyerror2(t)
  1902. char CONST * t;    /* token or 0 to indicate no more tokens */
  1903. {
  1904.     char buf[200];
  1905.     Symbol sym;
  1906.     static int first = 1;    /* true if first suggested replacement */
  1907.     static char tokens[4000] = "";/* error message, saying */
  1908.                     /* "expecting <token types>" */
  1909.  
  1910.     if (t) {    /* subsequent token? */
  1911.         if (first) first = 0;
  1912.         else strcat (tokens," or ");
  1913.         strcat(tokens,t);
  1914.     } else {
  1915.       strcpy(buf,"syntax error");
  1916.       if (yyeof)
  1917.         strcat(buf, " at end of input");
  1918.       else if (yytext[0] == 0)
  1919.         strcat(buf, " at null character");
  1920.       else if (yytext[0] < 040 || yytext[0] >= 0177)
  1921.         sprintf(buf + strlen(buf), " near character 0%o", yytext[0]);
  1922.       else
  1923.         sprintf(buf + strlen(buf), " near `%s'", yytext);
  1924.  
  1925.       if (0 == strlen(tokens)) yyerror("syntax error");
  1926.       sym.line = yylineno - (yytext[0] == '\n');
  1927.       sym.filename = current_filename;
  1928.       ERRORreport_with_symbol(ERROR_syntax_expecting,&sym,buf,tokens
  1929.             ,CURRENT_SCOPE_TYPE_PRINTABLE,CURRENT_SCOPE_NAME);
  1930.     }
  1931. }
  1932. void
  1933. SCANskip_to_end_schema()
  1934. {
  1935.     while (yylex() != TOK_END_SCHEMA);
  1936.  
  1937.     unput('X');    /* any old character */
  1938.  
  1939.     BEGIN return_end_schema;
  1940. }