-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathexpparse.y
More file actions
2031 lines (1812 loc) · 76.2 KB
/
expparse.y
File metadata and controls
2031 lines (1812 loc) · 76.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%{
/*
* YACC grammar for Express parser.
*
* This software was developed by U.S. Government employees as part of
* their official duties and is not subject to copyright.
*
* $Log: expparse.y,v $
* Revision 1.23 1997/11/14 17:09:04 libes
* allow multiple group references
*
* Revision 1.22 1997/01/21 19:35:43 dar
* made C++ compatible
*
* Revision 1.21 1995/06/08 22:59:59 clark
* bug fixes
*
* Revision 1.20 1995/04/08 21:06:07 clark
* WHERE rule resolution bug fixes, take 2
*
* Revision 1.19 1995/04/08 20:54:18 clark
* WHERE rule resolution bug fixes
*
* Revision 1.19 1995/04/08 20:49:08 clark
* WHERE
*
* Revision 1.18 1995/04/05 13:55:40 clark
* CADDETC preval
*
* Revision 1.17 1995/03/09 18:43:47 clark
* various fixes for caddetc - before interface clause changes
*
* Revision 1.16 1994/11/29 20:55:58 clark
* fix inline comment bug
*
* Revision 1.15 1994/11/22 18:32:39 clark
* Part 11 IS; group reference
*
* Revision 1.14 1994/11/10 19:20:03 clark
* Update to IS
*
* Revision 1.13 1994/05/11 19:50:00 libes
* numerous fixes
*
* Revision 1.12 1993/10/15 18:47:26 libes
* CADDETC certified
*
* Revision 1.10 1993/03/19 20:53:57 libes
* one more, with feeling
*
* Revision 1.9 1993/03/19 20:39:51 libes
* added unique to parameter types
*
* Revision 1.8 1993/02/16 03:17:22 libes
* reorg'd alg bodies to not force artificial begin/ends
* added flag to differentiate parameters in scopes
* rewrote query to fix scope handling
* added support for Where type
*
* Revision 1.7 1993/01/19 22:44:17 libes
* *** empty log message ***
*
* Revision 1.6 1992/08/27 23:36:35 libes
* created fifo for new schemas that are parsed
* connected entity list to create of oneof
*
* Revision 1.5 1992/08/18 17:11:36 libes
* rm'd extraneous error messages
*
* Revision 1.4 1992/06/08 18:05:20 libes
* prettied up interface to print_objects_when_running
*
* Revision 1.3 1992/05/31 23:31:13 libes
* implemented ALIAS resolution
*
* Revision 1.2 1992/05/31 08:30:54 libes
* multiple files
*
* Revision 1.1 1992/05/28 03:52:25 libes
* Initial revision
*/
#include "express/symbol.h"
#include "express/linklist.h"
#include "stack.h"
#include "express/express.h"
#include "express/schema.h"
#include "express/entity.h"
#include "express/resolve.h"
#ifdef YYDEBUG
int yydbg_upper_limit = -1;
int yydbg_lower_limit = -1;
#endif /*YYDEBUG*/
extern int print_objects_while_running;
int tag_count; /* use this to count tagged GENERIC types in the formal */
/* argument lists. Gross, but much easier to do it this */
/* way then with the 'help' of yacc. */
/* Set it to -1 to indicate that tags cannot be defined, */
/* only used (outside of formal parameter list, i.e. for */
/* return types and local variables). Hey, as long as */
/* there's a gross hack sitting around, we might as well */
/* milk it for all it's worth! -snc */
Express yyexpresult; /* hook to everything built by parser */
Symbol *interface_schema; /* schema of interest in use/ref clauses */
void (*interface_func)(); /* func to attach rename clauses */
/* record schemas found in a single parse here, allowing them to be */
/* differentiated from other schemas parsed earlier */
Linked_List PARSEnew_schemas;
void SCANskip_to_end_schema(); //in expscan.l
extern int yylineno;
static void yyerror PROTO((char*));
bool yyeof = false;
#ifdef FLEX
extern char *yytext;
#else /* LEX */
extern char yytext[];
#endif /*FLEX*/
#define MAX_SCOPE_DEPTH 20 /* max number of scopes that can be nested */
static struct scope {
struct Scope_ *this_;
char type; /* one of OBJ_XXX */
struct scope *pscope; /* pointer back to most recent scope */
/* that has a printable name - for better */
/* error messages */
} scopes[MAX_SCOPE_DEPTH], *scope;
#define CURRENT_SCOPE (scope->this_)
#define PREVIOUS_SCOPE ((scope-1)->this_)
#define CURRENT_SCHEMA (scope->this_->u.schema)
#define CURRENT_SCOPE_NAME (OBJget_symbol(scope->pscope->this_,scope->pscope->type)->name)
#define CURRENT_SCOPE_TYPE_PRINTABLE (OBJget_type(scope->pscope->type))
/* ths = new scope to enter */
/* sym = name of scope to enter into parent. Some scopes (i.e., increment) */
/* are not named, in which case sym should be 0 */
/* This is useful for when a diagnostic is printed, an earlier named */
/* scoped can be used */
/* typ = type of scope */
#define PUSH_SCOPE(ths,sym,typ) \
if (sym) DICTdefine(scope->this_->symbol_table,(sym)->name,(Generic)ths,sym,typ);\
ths->superscope = scope->this_; \
scope++; \
scope->type = typ; \
scope->pscope = (sym?scope:(scope-1)->pscope); \
scope->this_ = ths; \
if (sym) { \
ths->symbol = *(sym); \
}
#define POP_SCOPE() scope--
/* PUSH_SCOPE_DUMMY just pushes the scope stack with nothing actually on it */
/* Necessary for situations when a POP_SCOPE is unnecessary but inevitable */
#define PUSH_SCOPE_DUMMY() scope++
/* normally the superscope is added by PUSH_SCOPE, but some things (types) */
/* bother to get pushed so fix them this way */
#define SCOPEadd_super(ths) ths->superscope = scope->this_;
#define ERROR(code) ERRORreport(code, yylineno)
/* structured types for parse node decorations */
%}
%type <case_item> case_action case_otherwise
%type <entity_body> entity_body
%type <expression> aggregate_init_element aggregate_initializer
assignable
attribute_decl
by_expression
constant
expression
function_call
general_ref /* group_ref*/
identifier initializer
interval literal
local_initializer precision_spec
query_expression
simple_expression
unary_expression
supertype_expression
until_control while_control
%type <iVal> function_header rule_header procedure_header
%type <list> action_body actual_parameters aggregate_init_body
explicit_attr_list case_action_list case_block
case_labels where_clause_list derive_decl
explicit_attribute expression_list
formal_parameter formal_parameter_list formal_parameter_rep
id_list defined_type_list
nested_id_list /*repeat_control_list*/ statement_rep
subtype_decl
where_rule where_rule_OPT
supertype_expression_list
labelled_attrib_list_list
labelled_attrib_list
inverse_attr_list
inverse_clause
attribute_decl_list
derived_attribute_rep
unique_clause
rule_formal_parameter_list
qualified_attr_list /* remove labelled_attrib_list if this works */
%type <op_code> rel_op
%type <type_flags> optional_or_unique optional_fixed optional var unique
%type <qualified_attr> qualified_attr
%type <qualifier> qualifier
%type <statement> alias_statement
assignment_statement case_statement
compound_statement
escape_statement if_statement
proc_call_statement repeat_statement
return_statement skip_statement
statement
%type <subsuper_decl> subsuper_decl
%type <subtypes> supertype_decl
supertype_factor
%type <symbol> function_id procedure_id
%type <type> attribute_type defined_type
parameter_type generic_type
%type <typebody> basic_type
select_type aggregate_type
aggregation_type array_type
bag_type conformant_aggregation
list_type
set_type
%type <type_either> set_or_bag_of_entity type
%type <upper_lower> cardinality_op index_spec limit_spec
%type <variable> inverse_attr derived_attribute
rule_formal_parameter
%type <where> where_clause
/***** these tokens also appear in exptoks.h and lexact.c *****/
%left TOK_EQUAL TOK_GREATER_EQUAL TOK_GREATER_THAN
TOK_IN TOK_INST_EQUAL TOK_INST_NOT_EQUAL
TOK_LESS_EQUAL TOK_LESS_THAN TOK_LIKE
TOK_NOT_EQUAL
%left TOK_MINUS TOK_PLUS
TOK_OR TOK_XOR
%left TOK_DIV TOK_MOD TOK_REAL_DIV
TOK_TIMES
TOK_AND TOK_ANDOR
TOK_CONCAT_OP /*direction doesn't really matter, just priority */
%right TOK_EXP
%left TOK_NOT
%nonassoc TOK_DOT TOK_BACKSLASH TOK_LEFT_BRACKET
%token TOK_ABSTRACT TOK_AGGREGATE TOK_ALIAS
TOK_ALL_IN TOK_ARRAY TOK_AS
TOK_ASSIGNMENT TOK_BACKSLASH TOK_BAG
TOK_BEGIN TOK_BINARY TOK_BOOLEAN
TOK_BY TOK_CASE TOK_COLON
TOK_COMMA TOK_CONSTANT TOK_E
TOK_DERIVE TOK_DOT TOK_ELSE
TOK_END TOK_END_ALIAS TOK_END_CASE
TOK_END_CONSTANT TOK_END_ENTITY TOK_END_FUNCTION
TOK_END_IF TOK_END_LOCAL TOK_END_PROCEDURE
TOK_END_REPEAT TOK_END_RULE TOK_END_SCHEMA
TOK_END_TYPE TOK_ENTITY TOK_ENUMERATION
TOK_ESCAPE TOK_FIXED TOK_FOR
TOK_FROM TOK_FUNCTION TOK_GENERIC
TOK_IF TOK_INCLUDE TOK_INTEGER
TOK_INVERSE TOK_LEFT_BRACKET TOK_LEFT_CURL
TOK_LEFT_PAREN TOK_LIST TOK_LOCAL
TOK_LOGICAL TOK_NUMBER TOK_OF
TOK_ONEOF TOK_OPTIONAL TOK_OTHERWISE
TOK_PI TOK_PROCEDURE TOK_QUERY
TOK_QUESTION_MARK TOK_REAL TOK_REFERENCE
TOK_REPEAT TOK_RETURN TOK_RIGHT_BRACKET
TOK_RIGHT_CURL TOK_RIGHT_PAREN TOK_RULE
TOK_SCHEMA TOK_SELECT TOK_SET
TOK_SKIP TOK_STRING TOK_SUBTYPE
TOK_SUCH_THAT TOK_SUPERTYPE TOK_THEN
TOK_TO TOK_TYPE TOK_UNIQUE
TOK_UNTIL TOK_USE TOK_VAR
TOK_WHERE TOK_WHILE
/* TOK_CONTEXT TOK_END_CONTEXT TOK_END_MODEL TOK_MODEL */
%token <string> TOK_STRING_LITERAL TOK_STRING_LITERAL_ENCODED
%token <symbol> TOK_BUILTIN_FUNCTION TOK_BUILTIN_PROCEDURE
TOK_IDENTIFIER TOK_SELF
%token <iVal> TOK_INTEGER_LITERAL
%token <rVal> TOK_REAL_LITERAL
%token <logical> TOK_LOGICAL_LITERAL
%token <binary> TOK_BINARY_LITERAL
%token <string> TOK_SEMICOLON
%start express_file
%union {
/* simple (single-valued) node types */
Binary binary;
Case_Item case_item;
Expression expression;
Integer iVal;
Linked_List list;
Logical logical;
Op_Code op_code;
Qualified_Attr * qualified_attr;
Real rVal;
Statement statement;
Symbol * symbol;
char * string;
Type type;
TypeBody typebody;
Variable variable;
Where where;
struct type_either {
Type type;
TypeBody body;
} type_either; /* either one of these can be returned */
struct {
unsigned optional:1;
unsigned unique:1;
unsigned fixed:1;
unsigned var:1; /* when formal is "VAR" */
} type_flags;
struct {
Linked_List attributes;
Linked_List unique;
Linked_List where;
} entity_body;
struct {
Expression subtypes;
Linked_List supertypes;
bool abstract;
} subsuper_decl;
struct {
Expression subtypes;
bool abstract;
} subtypes;
struct {
Expression lower_limit;
Expression upper_limit;
} upper_lower;
struct {
Expression expr; /* overall expression for qualifier */
Expression first; /* first [syntactic] qualifier (if more */
/* than one is contained in this */
/* [semantic] qualifier - used for */
/* group_ref + attr_ref - see rule for */
/* qualifier) */
} qualifier;
}
%%
action_body : action_body_item_rep statement_rep
{ $$ = $2; }
;
/* this should be rewritten to force order, see comment on next production */
action_body_item : declaration
| constant_decl
| local_decl
/* | error */
;
/* this corresponds to 'algorithm_head' in N14-ese
but it should be rewritten to force
declarations followed by
constants followed by
local_decls
*/
action_body_item_rep : /* NULL item */
| action_body_item action_body_item_rep
;
/* NOTE: can actually go to NULL, but it's a semantic problem */
/* to disambiguate this from a simple identifier, so let a call */
/* with no parameters be parsed as an identifier for now. */
/* another problem is that x() is always an entity. func/proc calls */
/* with no args are called as "x". By the time resolution occurs */
/* and we find out whether or not x is an entity or func/proc, we will */
/* no longer have the information about whether there were parens! */
/* EXPRESS is simply wrong to handle these two cases differently. */
actual_parameters : TOK_LEFT_PAREN expression_list TOK_RIGHT_PAREN
{ $$ = $2; }
| TOK_LEFT_PAREN TOK_RIGHT_PAREN
{ $$ = 0; /*LISTcreate();*/
/* NULL would do, except that we'll end */
/* up stuff the call name in as the 1st */
/* arg, so we might as well create the */
/* list now */
}
;
/*Part 11 ed1 line 159, ed2 line 169
* aggregate_initializer = '[' [ element { ',' element } ] ']' . */
/* I give up - why does 2nd parm of AGGR_LIT have to be non-null? */
aggregate_initializer : TOK_LEFT_BRACKET TOK_RIGHT_BRACKET
{ $$ = EXPcreate(Type_Aggregate);
$$->u.list = LISTcreate();}
| TOK_LEFT_BRACKET aggregate_init_body TOK_RIGHT_BRACKET
{ $$ = EXPcreate(Type_Aggregate);
$$->u.list = $2;}
;
/* part of aggregate_initializer */
aggregate_init_element : expression
{ $$ = $1; }
;
/* part of aggregate_initializer */
aggregate_init_body : aggregate_init_element
{ $$ = LISTcreate();
LISTadd($$, (Generic)$1); }
| aggregate_init_element TOK_COLON expression
{ /* Part 11 ed1 line 193, ed2 line 203
* element = expression [ ':' repetition ] . */
$$ = LISTcreate();
LISTadd($$, (Generic)$1);
LISTadd($$, (Generic)$3);
$1->type->u.type->body->flags.repeat = 1; }
| aggregate_init_body TOK_COMMA aggregate_init_element
{ $$ = $1;
LISTadd_last($$, (Generic)$3); }
| aggregate_init_body TOK_COMMA aggregate_init_element TOK_COLON expression
{ $$ = $1;
LISTadd_last($$, (Generic)$3);
LISTadd_last($$, (Generic)$5);
$3->type->u.type->body->flags.repeat = 1;}
;
/* Part 11 ed1 line 161, ed2 line 171
* aggregate_type = AGGREGATE [ ':' type_label ] OF parameter_type . */
aggregate_type : TOK_AGGREGATE TOK_OF parameter_type
{ $$ = TYPEBODYcreate(aggregate_);
$$->base = $3;
if (tag_count < 0) {
Symbol sym;
sym.line = yylineno;
sym.filename = current_filename;
ERRORreport_with_symbol(ERROR_unlabelled_param_type, &sym, CURRENT_SCOPE_NAME);
}
}
| TOK_AGGREGATE TOK_COLON TOK_IDENTIFIER TOK_OF
parameter_type
{ Type t = TYPEcreate_user_defined_tag($5,CURRENT_SCOPE,$3);
if (t) {
SCOPEadd_super(t);
$$ = TYPEBODYcreate(aggregate_);
$$->tag = t;
$$->base = $5;
}
}
;
aggregation_type : array_type
{ $$ = $1; }
| bag_type
{ $$ = $1; }
| list_type
{ $$ = $1; }
| set_type
{ $$ = $1; }
;
alias_statement : TOK_ALIAS TOK_IDENTIFIER TOK_FOR general_ref semicolon
{ struct Scope_ *s = SCOPEcreate_tiny(OBJ_ALIAS);
/* scope doesn't really have/need a name */
/* I suppose that naming it by the alias is fine */
PUSH_SCOPE(s,(Symbol *)0,OBJ_ALIAS);}
statement_rep
TOK_END_ALIAS semicolon
{ Expression e = EXPcreate_from_symbol(Type_Attribute,$2);
Variable v = VARcreate(e,Type_Unknown);
v->initializer = $4;
DICTdefine(CURRENT_SCOPE->symbol_table,$2->name,
(Generic)v,$2,OBJ_VARIABLE);
$$ = ALIAScreate(CURRENT_SCOPE,v,$7);
POP_SCOPE(); }
;
array_type : TOK_ARRAY index_spec TOK_OF optional_or_unique
attribute_type
{ $$ = TYPEBODYcreate(array_);
$$->flags.optional = $4.optional;
$$->flags.unique = $4.unique;
$$->upper = $2.upper_limit;
$$->lower = $2.lower_limit;
$$->base = $5;}
;
/* this is anything that can be assigned to */
assignable : assignable qualifier
{ $2.first->e.op1 = $1;
$$ = $2.expr;}
| identifier
{ $$ = $1; }
;
assignment_statement : assignable TOK_ASSIGNMENT expression semicolon
{ $$ = ASSIGNcreate($1,$3);}
;
attribute_type : aggregation_type
{ $$ = TYPEcreate_from_body_anonymously($1);
SCOPEadd_super($$);}
| basic_type
{ $$ = TYPEcreate_from_body_anonymously($1);
SCOPEadd_super($$);}
| defined_type
{ $$ = $1; }
;
explicit_attr_list : /* NULL body */
{ $$ = LISTcreate();}
| explicit_attr_list explicit_attribute
{ $$ = $1;
LISTadd_last($$, (Generic)$2); }
;
bag_type : TOK_BAG limit_spec TOK_OF attribute_type
{ $$ = TYPEBODYcreate(bag_);
$$->base = $4;
$$->upper = $2.upper_limit;
$$->lower = $2.lower_limit;}
| TOK_BAG TOK_OF attribute_type
{ $$ = TYPEBODYcreate(bag_);
$$->base = $3; }
;
basic_type : TOK_BOOLEAN
{ $$ = TYPEBODYcreate(boolean_);}
| TOK_INTEGER precision_spec
{ $$ = TYPEBODYcreate(integer_);
$$->precision = $2;}
| TOK_REAL precision_spec
{ $$ = TYPEBODYcreate(real_);
$$->precision = $2;}
| TOK_NUMBER
{ $$ = TYPEBODYcreate(number_);}
| TOK_LOGICAL
{ $$ = TYPEBODYcreate(logical_);}
| TOK_BINARY precision_spec optional_fixed
{ $$ = TYPEBODYcreate(binary_);
$$->precision = $2;
$$->flags.fixed = $3.fixed;}
| TOK_STRING precision_spec optional_fixed
{ $$ = TYPEBODYcreate(string_);
$$->precision = $2;
$$->flags.fixed = $3.fixed;}
;
block_list : /*NULL*/
| block_list block_member
;
block_member : declaration
| include_directive
| rule_decl
;
by_expression : /* NULL by_expression */
{ $$ = LITERAL_ONE;}
| TOK_BY expression
{ $$ = $2; }
;
cardinality_op : TOK_LEFT_CURL expression TOK_COLON expression TOK_RIGHT_CURL
{ $$.lower_limit = $2;
$$.upper_limit = $4; }
;
case_action : case_labels TOK_COLON statement
{ $$ = CASE_ITcreate($1, $3);
SYMBOLset($$);}
;
case_action_list : /* no case_actions */
{ $$ = LISTcreate();}
| case_action_list case_action
{ yyerrok;
$$ = $1;
LISTadd_last($$, (Generic)$2); }
/* | error
{ ERROR(ERROR_empty_case);
$$ = LISTcreate(); }*/
;
case_block : case_action_list case_otherwise
{ $$ = $1;
if ($2) LISTadd_last($$, (Generic)$2); }
;
case_labels : expression
{ $$ = LISTcreate();
LISTadd_last($$, (Generic)$1); }
| case_labels TOK_COMMA expression
{ yyerrok;
$$ = $1;
LISTadd_last($$, (Generic)$3); }
/* | case_labels error
{ ERROR(ERROR_comma_expected);
$$ = $1; }
| case_labels error
{ ERROR(ERROR_comma_expected); }
expression
{ yyerrok;
$$ = $1; }
| case_labels TOK_COMMA error
{ ERROR(ERROR_case_labels);
$$ = $1; }*/
;
case_otherwise : /* no otherwise clause */
{ $$ = (Case_Item)0; }
| TOK_OTHERWISE TOK_COLON statement
{ $$ = CASE_ITcreate(LIST_NULL, $3);
SYMBOLset($$);}
;
case_statement : TOK_CASE expression TOK_OF case_block TOK_END_CASE semicolon
{ $$ = CASEcreate($2, $4);}
;
compound_statement : TOK_BEGIN statement_rep TOK_END semicolon
{ $$ = COMP_STMTcreate($2);}
;
constant : TOK_PI
{ $$ = LITERAL_PI; }
| TOK_E
{ $$ = LITERAL_E; }
;
/* package this up as an attribute */
constant_body : identifier TOK_COLON attribute_type TOK_ASSIGNMENT
expression semicolon
{ Variable v;
$1->type = $3;
v = VARcreate($1,$3);
v->initializer = $5;
v->flags.constant = 1;
DICTdefine(CURRENT_SCOPE->symbol_table,
$1->symbol.name,
(Generic)v,&$1->symbol,OBJ_VARIABLE);
}
;
constant_body_list : /* NULL */
| constant_body constant_body_list
;
constant_decl :
TOK_CONSTANT constant_body_list TOK_END_CONSTANT
semicolon
;
declaration : entity_decl
| function_decl
| procedure_decl
| type_decl
;
derive_decl : /* NULL body */
{ $$ = LISTcreate(); }
| TOK_DERIVE derived_attribute_rep
{ $$ = $2; }
;
derived_attribute : attribute_decl TOK_COLON attribute_type initializer semicolon
{ $$ = VARcreate($1,$3);
$$->initializer = $4;
$$->flags.attribute = true;
}
;
derived_attribute_rep : derived_attribute
{ $$ = LISTcreate();
LISTadd_last($$, (Generic)$1); }
| derived_attribute_rep derived_attribute
{ $$ = $1;
LISTadd_last($$, (Generic)$2); }
/* | error
{ ERROR(ERROR_missing_derive);
$$ = LISTcreate(); }
| derived_attribute_rep error
{ ERROR(ERROR_derived_attribute);
$$ = $1; }*/
;
entity_body : explicit_attr_list derive_decl inverse_clause
unique_clause where_rule_OPT
{ $$.attributes = $1;
/* this is flattened out in entity_decl - DEL */
LISTadd_last($$.attributes, (Generic)$2);
if ($3 != LIST_NULL) {
LISTadd_last($$.attributes, (Generic)$3);
}
$$.unique = $4;
$$.where = $5; }
;
entity_decl : entity_header subsuper_decl semicolon
entity_body TOK_END_ENTITY semicolon
{ CURRENT_SCOPE->u.entity->subtype_expression = $2.subtypes;
CURRENT_SCOPE->u.entity->supertype_symbols = $2.supertypes;
LISTdo ($4.attributes, l, Linked_List)
LISTdo (l, a, Variable)
ENTITYadd_attribute(CURRENT_SCOPE, a);
LISTod;
LISTod;
CURRENT_SCOPE->u.entity->abstract = $2.abstract;
CURRENT_SCOPE->u.entity->unique = $4.unique;
CURRENT_SCOPE->where = $4.where;
POP_SCOPE();}
/* | entity_header error TOK_END_ENTITY semicolon
{ POP_SCOPE();}*/
;
entity_header : TOK_ENTITY TOK_IDENTIFIER
{ Entity e = ENTITYcreate($2);
if (print_objects_while_running & OBJ_ENTITY_BITS){
fprintf(stdout,"parse: %s (entity)\n",$2->name);
}
PUSH_SCOPE(e,$2,OBJ_ENTITY);}
;
enumeration_type : TOK_ENUMERATION TOK_OF nested_id_list
{ int value = 0; Expression x; Symbol *tmp;
TypeBody tb;
tb = TYPEBODYcreate(enumeration_);
CURRENT_SCOPE->u.type->head = 0;
CURRENT_SCOPE->u.type->body = tb;
tb->list = $3;
if (!CURRENT_SCOPE->symbol_table) {
CURRENT_SCOPE->symbol_table = DICTcreate(25);
}
if (!PREVIOUS_SCOPE->enum_table) {
PREVIOUS_SCOPE->enum_table = DICTcreate(25);
}
LISTdo_links($3, id) {
tmp = (Symbol *)id->data;
id->data = (Generic)(x = EXPcreate(CURRENT_SCOPE));
x->symbol = *(tmp);
x->u.integer = ++value;
/* define both in enum scope and scope of */
/* 1st visibility */
DICT_define(CURRENT_SCOPE->symbol_table, x->symbol.name,
(Generic)x,&x->symbol,OBJ_EXPRESSION);
DICTdefine(PREVIOUS_SCOPE->enum_table,x->symbol.name,
(Generic)x,&x->symbol,OBJ_EXPRESSION);
SYMBOL_destroy(tmp);
} LISTod;
}
;
escape_statement : TOK_ESCAPE semicolon
{ $$ = STATEMENT_ESCAPE; }
;
attribute_decl : TOK_IDENTIFIER
{ $$ = EXPcreate(Type_Attribute);
$$->symbol = *$1;SYMBOL_destroy($1);
}
| TOK_SELF TOK_BACKSLASH TOK_IDENTIFIER TOK_DOT TOK_IDENTIFIER
{ $$ = EXPcreate(Type_Expression);
$$->e.op1 = EXPcreate(Type_Expression);
$$->e.op1->e.op_code = OP_GROUP;
$$->e.op1->e.op1 = EXPcreate(Type_Self);
$$->e.op1->e.op2 = EXPcreate_from_symbol(Type_Entity,$3);
SYMBOL_destroy($3);
$$->e.op_code = OP_DOT;
$$->e.op2 = EXPcreate_from_symbol(Type_Attribute,$5);
SYMBOL_destroy($5);
}
;
attribute_decl_list : attribute_decl
{ $$ = LISTcreate();
LISTadd_last($$, (Generic)$1); }
| attribute_decl_list TOK_COMMA attribute_decl
{ $$ = $1;
LISTadd_last($$, (Generic)$3); }
;
optional : /*NULL*/
{ $$.optional = 0;}
| TOK_OPTIONAL
{ $$.optional = 1;}
;
explicit_attribute : attribute_decl_list TOK_COLON optional
attribute_type semicolon
{ Variable v;
LISTdo_links ($1, attr)
v = VARcreate((Expression)attr->data,$4);
v->flags.optional = $3.optional;
v->flags.attribute = true;
attr->data = (Generic)v;
LISTod;
}
;
express_file : { scope = scopes;
/* no need to define scope->this */
scope->this_ = yyexpresult;
scope->pscope = scope;
scope->type = OBJ_EXPRESS;
yyexpresult->symbol.name = yyexpresult->u.express->filename;
yyexpresult->symbol.filename = yyexpresult->u.express->filename;
yyexpresult->symbol.line = 1;
}
schema_decl_list
;
schema_decl_list : schema_decl
| schema_decl_list schema_decl
;
expression : simple_expression
{ $$ = $1; }
| expression TOK_AND expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_AND, $1, $3);}
| expression TOK_OR expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_OR, $1, $3);}
| expression TOK_XOR expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_XOR, $1, $3);}
| expression TOK_LESS_THAN expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_LESS_THAN, $1, $3);}
| expression TOK_GREATER_THAN expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_GREATER_THAN, $1, $3);}
| expression TOK_EQUAL expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_EQUAL, $1, $3);}
| expression TOK_LESS_EQUAL expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_LESS_EQUAL, $1, $3);}
| expression TOK_GREATER_EQUAL expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_GREATER_EQUAL, $1, $3);}
| expression TOK_NOT_EQUAL expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_NOT_EQUAL, $1, $3);}
| expression TOK_INST_EQUAL expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_INST_EQUAL, $1, $3);}
| expression TOK_INST_NOT_EQUAL expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_INST_NOT_EQUAL, $1, $3);}
| expression TOK_IN expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_IN, $1, $3);}
| expression TOK_LIKE expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_LIKE, $1, $3);}
| simple_expression cardinality_op simple_expression
{ yyerrok; }
/* | expression error
{ ERROR;
$$ = EXPRESSION_NULL; }*/
;
/* part 11 - ed1 line 287, ed2 line 305
* simple_expression = term { add_like_op term } .
*/
simple_expression : unary_expression
{ $$ = $1; }
/* | unary_expression group_ref
{ $2->e.op1 = $1;
$$ = $2; }*/
| simple_expression TOK_CONCAT_OP simple_expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_CONCAT, $1, $3);}
| simple_expression TOK_EXP simple_expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_EXP, $1, $3);}
| simple_expression TOK_TIMES simple_expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_TIMES, $1, $3);}
| simple_expression TOK_DIV simple_expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_DIV, $1, $3);}
| simple_expression TOK_REAL_DIV simple_expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_REAL_DIV, $1, $3);}
| simple_expression TOK_MOD simple_expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_MOD, $1, $3);}
| simple_expression TOK_PLUS simple_expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_PLUS, $1, $3);}
| simple_expression TOK_MINUS simple_expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_MINUS, $1, $3);}
/* this would be for string concatenation, but the parser can't tell whether
something is a string or not, so let it be tagged as just arithmetic plus.
| simple_expression TOK_PLUS simple_expression
{ yyerrok;
$$ = BIN_EXPcreate(OP_CONCAT, $1, $3);}
*/
/* | simple_expression error
{ ERROR;
$$ = EXPRESSION_NULL; }*/
;
expression_list : expression
{ $$ = LISTcreate();
LISTadd_last($$, (Generic)$1); }
| expression_list TOK_COMMA expression
{ $$ = $1;
LISTadd_last($$, (Generic)$3); }
;
var : /*NULL*/
{ $$.var = 1;}
| TOK_VAR
{ $$.var = 0;}
;
formal_parameter : var id_list TOK_COLON parameter_type
{ Symbol *tmp; Expression e; Variable v;
$$ = $2;
LISTdo_links($$, param)
tmp = (Symbol *)param->data;
/* e = EXPcreate_from_symbol($4,tmp);*/
e = EXPcreate_from_symbol(Type_Attribute,tmp);
v = VARcreate(e,$4);
v->flags.optional = $1.var;
v->flags.parameter = true;
param->data = (Generic)v;
/* link it in to the current scope's dict */
DICTdefine(CURRENT_SCOPE->symbol_table,
tmp->name,(Generic)v,
tmp,OBJ_VARIABLE);
/* see explanation of this in TYPEresolve func */
/* $4->refcount++; */
LISTod;
}
;
formal_parameter_list : /* no parameters */
{ $$ = LIST_NULL; }
| TOK_LEFT_PAREN formal_parameter_rep TOK_RIGHT_PAREN
{ $$ = $2; }
;
formal_parameter_rep : formal_parameter
{ $$ = $1; }
| formal_parameter_rep semicolon formal_parameter
{ $$ = $1;
LISTadd_all($$, $3); }