-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathexpparse.y
More file actions
2445 lines (2136 loc) · 55.3 KB
/
expparse.y
File metadata and controls
2445 lines (2136 loc) · 55.3 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
/** Lemon grammar for Express parser, based on SCL's expparse.y. */
%include {
#include <assert.h>
#include "token_type.h"
#include "parse_data.h"
int yyerrstatus = 0;
#define yyerrok (yyerrstatus = 0)
YYSTYPE yylval;
/*
* 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
*
* ** 22 older revision log records removed 3 January 2014 **
*/
#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"
#include "expscan.h"
#include <float.h>
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). Hey, as long as there's a gross hack sitting
* around, we might as well milk it for all it's worth!
* - snc
*/
int local_var_count; /**< used to keep LOCAL variables in order
* used in combination with Variable.offset
*/
Express yyexpresult; /* hook to everything built by parser */
Symbol *interface_schema; /* schema of interest in use/ref clauses */
void (*interface_func)(struct Scope_ *, Symbol *, Symbol *, Symbol *); /* 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(perplex_t scanner);
int yylineno;
bool yyeof = false;
#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)
void parserInitState( void )
{
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;
}
} /* include */
%extra_argument { parse_data_t parseData }
%destructor statement_list {
if (parseData.scanner == NULL) {
$$.string = (char*)NULL;
}
}
%type case_action { Case_Item }
%type case_otherwise { Case_Item }
%type entity_body { struct entity_body }
%type aggregate_init_element { Expression }
%type aggregate_initializer { Expression }
%type assignable { Expression }
%type attribute_decl { Expression }
%type by_expression { Expression }
%type constant { Expression }
%type expression { Expression }
%type function_call { Expression }
%type general_ref { Expression }
%type group_ref { Expression }
%type identifier { Expression }
%type initializer { Expression }
%type interval { Expression }
%type literal { Expression }
%type local_initializer { Expression }
%type precision_spec { Expression }
%type query_expression { Expression }
%type query_start { Expression }
%type simple_expression { Expression }
%type unary_expression { Expression }
%type supertype_expression { Expression }
%type until_control { Expression }
%type while_control { Expression }
%type function_header { Integer }
%type fh_lineno { Integer }
%type rule_header { Integer }
%type rh_start { Integer }
%type rh_get_line { Integer }
%type procedure_header { Integer }
%type ph_get_line { Integer }
%type action_body { Linked_List }
%type actual_parameters { Linked_List }
%type aggregate_init_body { Linked_List }
%type explicit_attr_list { Linked_List }
%type case_action_list { Linked_List }
%type case_block { Linked_List }
%type case_labels { Linked_List }
%type where_clause_list { Linked_List }
%type derive_decl { Linked_List }
%type explicit_attribute { Linked_List }
%type expression_list { Linked_List }
%type formal_parameter { Linked_List }
%type formal_parameter_list { Linked_List }
%type formal_parameter_rep { Linked_List }
%type id_list { Linked_List }
%type defined_type_list { Linked_List }
%type nested_id_list { Linked_List }
/*repeat_control_list*/
%type statement_rep { Linked_List }
%type subtype_decl { Linked_List }
%type where_rule { Linked_List }
%type where_rule_OPT { Linked_List }
%type supertype_expression_list { Linked_List }
%type labelled_attrib_list_list { Linked_List }
%type labelled_attrib_list { Linked_List }
%type inverse_attr_list { Linked_List }
%type inverse_clause { Linked_List }
%type attribute_decl_list { Linked_List }
%type derived_attribute_rep { Linked_List }
%type unique_clause { Linked_List }
%type rule_formal_parameter_list { Linked_List }
%type qualified_attr_list { Linked_List }
/* remove labelled_attrib_list if this works */
%type rel_op { Op_Code }
%type optional_or_unique { struct type_flags }
%type optional_fixed { struct type_flags }
%type optional { struct type_flags }
%type var { struct type_flags }
%type unique { struct type_flags }
%type qualified_attr { Expression }
%type qualifier { struct qualifier }
%type alias_statement { Statement }
%type assignment_statement { Statement }
%type case_statement { Statement }
%type compound_statement { Statement }
%type escape_statement { Statement }
%type if_statement { Statement }
%type proc_call_statement { Statement }
%type repeat_statement { Statement }
%type return_statement { Statement }
%type skip_statement { Statement }
%type statement { Statement }
%type subsuper_decl { struct subsuper_decl }
%type supertype_decl { struct subtypes }
%type supertype_factor { struct subtypes }
%type function_id { Symbol* }
%type procedure_id { Symbol* }
%type attribute_type { Type }
%type defined_type { Type }
%type parameter_type { Type }
%type generic_type { Type }
%type basic_type { TypeBody }
%type select_type { TypeBody }
%type aggregate_type { TypeBody }
%type aggregation_type { TypeBody }
%type array_type { TypeBody }
%type bag_type { TypeBody }
%type conformant_aggregation { TypeBody }
%type list_type { TypeBody }
%type set_type { TypeBody }
%type set_or_bag_of_entity { struct type_either }
%type type { struct type_either }
%type cardinality_op { struct upper_lower }
%type bound_spec { struct upper_lower }
%type inverse_attr { Variable }
%type derived_attribute { Variable }
%type rule_formal_parameter { Variable }
%type where_clause { Where }
%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.
%right TOK_EXP.
%left TOK_NOT.
%nonassoc TOK_DOT
TOK_BACKSLASH
TOK_LEFT_BRACKET.
%start_symbol express_file
%token_type { YYSTYPE }
action_body(A) ::= action_body_item_rep statement_rep(B).
{
A = B;
}
/* this should be rewritten to force order, see comment on next production */
action_body_item(A) ::= declaration(B).
{
A = B;
}
action_body_item(A) ::= constant_decl(B).
{
A = B;
}
action_body_item(A) ::= local_decl(B).
{
A = B;
}
/* 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_rep(A) ::= action_body_item(B) action_body_item_rep.
{
A = B;
}
/* 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(A) ::= TOK_LEFT_PAREN expression_list(B) TOK_RIGHT_PAREN.
{
A = B;
}
actual_parameters(A) ::= TOK_LEFT_PAREN TOK_RIGHT_PAREN.
{
A = 0;
}
/* I give up - why does 2nd parm of AGGR_LIT have to be non-null? */
aggregate_initializer(A) ::= TOK_LEFT_BRACKET TOK_RIGHT_BRACKET.
{
A = EXPcreate(Type_Aggregate);
A->u.list = LISTcreate();
}
aggregate_initializer(A) ::= TOK_LEFT_BRACKET aggregate_init_body(B)
TOK_RIGHT_BRACKET.
{
A = EXPcreate(Type_Aggregate);
A->u.list = B;
}
aggregate_init_element(A) ::= expression(B).
{
A = B;
}
aggregate_init_body(A) ::= aggregate_init_element(B).
{
A = LISTcreate();
LISTadd_last(A, (Generic)B);
}
aggregate_init_body(A) ::= aggregate_init_element(B) TOK_COLON expression(C).
{
A = LISTcreate();
LISTadd_last(A, (Generic)B);
LISTadd_last(A, (Generic)C);
C->type = Type_Repeat;
}
aggregate_init_body(A) ::= aggregate_init_body(B) TOK_COMMA
aggregate_init_element(C).
{
A = B;
LISTadd_last(A, (Generic)C);
}
aggregate_init_body(A) ::= aggregate_init_body(B) TOK_COMMA
aggregate_init_element(C) TOK_COLON expression(D).
{
A = B;
LISTadd_last(A, (Generic)C);
LISTadd_last(A, (Generic)D);
D->type = Type_Repeat;
}
aggregate_type(A) ::= TOK_AGGREGATE TOK_OF parameter_type(B).
{
A = TYPEBODYcreate(aggregate_);
A->base = B;
if (tag_count < 0) {
Symbol sym;
sym.line = yylineno;
sym.filename = current_filename;
ERRORreport_with_symbol(UNLABELLED_PARAM_TYPE, &sym, CURRENT_SCOPE_NAME);
}
}
aggregate_type(A) ::= TOK_AGGREGATE TOK_COLON TOK_IDENTIFIER(B) TOK_OF
parameter_type(C).
{
Type t = TYPEcreate_user_defined_tag(C, CURRENT_SCOPE, B.symbol);
if (t) {
SCOPEadd_super(t);
A = TYPEBODYcreate(aggregate_);
A->tag = t;
A->base = C;
}
}
aggregation_type(A) ::= array_type(B).
{
A = B;
}
aggregation_type(A) ::= bag_type(B).
{
A = B;
}
aggregation_type(A) ::= list_type(B).
{
A = B;
}
aggregation_type(A) ::= set_type(B).
{
A = B;
}
alias_statement(A) ::= TOK_ALIAS TOK_IDENTIFIER(B) TOK_FOR general_ref(C)
semicolon alias_push_scope statement_rep(D)
TOK_END_ALIAS semicolon.
{
Expression e = EXPcreate_from_symbol(Type_Attribute, B.symbol);
Variable v = VARcreate(e, Type_Unknown);
v->initializer = C;
DICTdefine(CURRENT_SCOPE->symbol_table, B.symbol->name, (Generic)v,
B.symbol, OBJ_VARIABLE);
A = ALIAScreate(CURRENT_SCOPE, v, D);
POP_SCOPE();
}
alias_push_scope ::= /* subroutine */.
{
struct Scope_ *s = SCOPEcreate_tiny(OBJ_ALIAS);
PUSH_SCOPE(s, (Symbol *)0, OBJ_ALIAS);
}
array_type(A) ::= TOK_ARRAY bound_spec(B) TOK_OF optional_or_unique(C)
attribute_type(D).
{
A = TYPEBODYcreate(array_);
A->flags.optional = C.optional;
A->flags.unique = C.unique;
A->upper = B.upper_limit;
A->lower = B.lower_limit;
A->base = D;
}
/* this is anything that can be assigned to */
assignable(A) ::= assignable(B) qualifier(C).
{
C.first->e.op1 = B;
A = C.expr;
}
assignable(A) ::= identifier(B).
{
A = B;
}
assignment_statement(A) ::= assignable(B) TOK_ASSIGNMENT expression(C)
semicolon.
{
A = ASSIGNcreate(B, C);
}
attribute_type(A) ::= aggregation_type(B).
{
A = TYPEcreate_from_body_anonymously(B);
SCOPEadd_super(A);
}
attribute_type(A) ::= basic_type(B).
{
A = TYPEcreate_from_body_anonymously(B);
SCOPEadd_super(A);
}
attribute_type(A) ::= defined_type(B).
{
A = B;
}
explicit_attr_list(A) ::= /* NULL body */.
{
A = LISTcreate();
}
explicit_attr_list(A) ::= explicit_attr_list(B) explicit_attribute(C).
{
A = B;
LISTadd_last(A, (Generic)C);
}
bag_type(A) ::= TOK_BAG bound_spec(B) TOK_OF attribute_type(C).
{
A = TYPEBODYcreate(bag_);
A->base = C;
A->upper = B.upper_limit;
A->lower = B.lower_limit;
}
bag_type(A) ::= TOK_BAG TOK_OF attribute_type(B).
{
A = TYPEBODYcreate(bag_);
A->base = B;
}
basic_type(A) ::= TOK_BOOLEAN.
{
A = TYPEBODYcreate(boolean_);
}
basic_type(A) ::= TOK_INTEGER precision_spec(B).
{
A = TYPEBODYcreate(integer_);
A->precision = B;
}
basic_type(A) ::= TOK_REAL precision_spec(B).
{
A = TYPEBODYcreate(real_);
A->precision = B;
}
basic_type(A) ::= TOK_NUMBER.
{
A = TYPEBODYcreate(number_);
}
basic_type(A) ::= TOK_LOGICAL.
{
A = TYPEBODYcreate(logical_);
}
basic_type(A) ::= TOK_BINARY precision_spec(B) optional_fixed(C).
{
A = TYPEBODYcreate(binary_);
A->precision = B;
A->flags.fixed = C.fixed;
}
basic_type(A) ::= TOK_STRING precision_spec(B) optional_fixed(C).
{
A = TYPEBODYcreate(string_);
A->precision = B;
A->flags.fixed = C.fixed;
}
block_list ::= /* NULL */.
block_list(A) ::= block_list(B) block_member.
{
A = B;
}
block_member(A) ::= declaration(B).
{
A = B;
}
block_member(A) ::= include_directive(B).
{
A = B;
}
block_member(A) ::= rule_decl(B).
{
A = B;
}
by_expression(A) ::= /* NULL by_expression */.
{
A = LITERAL_ONE;
}
by_expression(A) ::= TOK_BY expression(B).
{
A = B;
}
cardinality_op(A) ::= TOK_LEFT_CURL expression(B) TOK_COLON expression(C)
TOK_RIGHT_CURL.
{
A.lower_limit = B;
A.upper_limit = C;
}
case_action(A) ::= case_labels(B) TOK_COLON statement(C).
{
A = CASE_ITcreate(B, C);
SYMBOLset(A);
}
case_action_list(A) ::= /* no case_actions */.
{
A = LISTcreate();
}
case_action_list(A) ::= case_action_list(B) case_action(C).
{
yyerrok;
A = B;
LISTadd_last(A, (Generic)C);
}
case_block(A) ::= case_action_list(B) case_otherwise(C).
{
A = B;
if (C) {
LISTadd_last(A,
(Generic)C);
}
}
case_labels(A) ::= expression(B).
{
A = LISTcreate();
LISTadd_last(A, (Generic)B);
}
case_labels(A) ::= case_labels(B) TOK_COMMA expression(C).
{
yyerrok;
A = B;
LISTadd_last(A, (Generic)C);
}
case_otherwise(A) ::= /* no otherwise clause */.
{
A = (Case_Item)0;
}
case_otherwise(A) ::= TOK_OTHERWISE TOK_COLON statement(B).
{
A = CASE_ITcreate(LIST_NULL, B);
SYMBOLset(A);
}
case_statement(A) ::= TOK_CASE expression(B) TOK_OF case_block(C) TOK_END_CASE
semicolon.
{
A = CASEcreate(B, C);
}
compound_statement(A) ::= TOK_BEGIN statement_rep(B) TOK_END semicolon.
{
A = COMP_STMTcreate(B);
}
constant(A) ::= TOK_PI.
{
A = LITERAL_PI;
}
constant(A) ::= TOK_E.
{
A = LITERAL_E;
}
/* package this up as an attribute */
constant_body ::= identifier(A) TOK_COLON attribute_type(B) TOK_ASSIGNMENT
expression(C) semicolon.
{
Variable v;
A->type = B;
v = VARcreate(A, B);
v->initializer = C;
v->flags.constant = 1;
DICTdefine(CURRENT_SCOPE->symbol_table, A->symbol.name, (Generic)v,
&A->symbol, OBJ_VARIABLE);
}
constant_body_list ::= /* NULL */.
constant_body_list(A) ::= constant_body(B) constant_body_list.
{
A = B;
}
constant_decl(A) ::= TOK_CONSTANT(B) constant_body_list TOK_END_CONSTANT
semicolon.
{
A = B;
}
declaration(A) ::= entity_decl(B).
{
A = B;
}
declaration(A) ::= function_decl(B).
{
A = B;
}
declaration(A) ::= procedure_decl(B).
{
A = B;
}
declaration(A) ::= type_decl(B).
{
A = B;
}
derive_decl(A) ::= /* NULL body */.
{
A = LISTcreate();
}
derive_decl(A) ::= TOK_DERIVE derived_attribute_rep(B).
{
A = B;
}
derived_attribute(A) ::= attribute_decl(B) TOK_COLON attribute_type(C)
initializer(D) semicolon.
{
A = VARcreate(B, C);
A->initializer = D;
A->flags.attribute = true;
}
derived_attribute_rep(A) ::= derived_attribute(B).
{
A = LISTcreate();
LISTadd_last(A, (Generic)B);
}
derived_attribute_rep(A) ::= derived_attribute_rep(B) derived_attribute(C).
{
A = B;
LISTadd_last(A, (Generic)C);
}
entity_body(A) ::= explicit_attr_list(B) derive_decl(C) inverse_clause(D)
unique_clause(E) where_rule_OPT(F).
{
A.attributes = B;
/* this is flattened out in entity_decl - DEL */
LISTadd_last(A.attributes, (Generic)C);
if (D != LIST_NULL) {
LISTadd_last(A.attributes, (Generic)D);
}
A.unique = E;
A.where = F;
}
entity_decl ::= entity_header subsuper_decl(A) semicolon entity_body(B)
TOK_END_ENTITY semicolon.
{
CURRENT_SCOPE->u.entity->subtype_expression = A.subtypes;
CURRENT_SCOPE->u.entity->supertype_symbols = A.supertypes;
LISTdo( B.attributes, l, Linked_List ) {
LISTdo_n( l, a, Variable, b ) {
ENTITYadd_attribute(CURRENT_SCOPE, a);
} LISTod;
} LISTod;
CURRENT_SCOPE->u.entity->abstract = A.abstract;
CURRENT_SCOPE->u.entity->unique = B.unique;
CURRENT_SCOPE->where = B.where;
POP_SCOPE();
}
entity_header ::= TOK_ENTITY TOK_IDENTIFIER(A).
{
Entity e = ENTITYcreate(A.symbol);
if (print_objects_while_running & OBJ_ENTITY_BITS) {
fprintf( stderr, "parse: %s (entity)\n", A.symbol->name);
}
PUSH_SCOPE(e, A.symbol, OBJ_ENTITY);
}
enumeration_type ::= TOK_ENUMERATION TOK_OF nested_id_list(A).
{
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 = A;
if (!CURRENT_SCOPE->symbol_table) {
CURRENT_SCOPE->symbol_table = DICTcreate(25);
}
if (!PREVIOUS_SCOPE->enum_table) {
PREVIOUS_SCOPE->enum_table = DICTcreate(25);
}
LISTdo_links(A, 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(A) ::= TOK_ESCAPE semicolon.
{
A = STATEMENT_ESCAPE;
}
/* 10303-11:2004 production 177
* attribute_decl = attribute_id | redeclared_attribute .
*
* also
* 178 attribute_id = simple_id .
* 279 redeclared_attribute = qualified_attribute [ RENAMED attribute_id ] .
* 275 qualified_attribute = SELF group_qualifier attribute_qualifier .
*
* NOTE - production 279 isn't implemented
*/
attribute_decl(A) ::= TOK_IDENTIFIER(B).
{
A = EXPcreate(Type_Attribute);
A->symbol = *B.symbol;
SYMBOL_destroy(B.symbol);
}
attribute_decl(A) ::= TOK_SELF TOK_BACKSLASH TOK_IDENTIFIER(B) TOK_DOT
TOK_IDENTIFIER(C).
{
A = EXPcreate(Type_Expression);
A->e.op1 = EXPcreate(Type_Expression);
A->e.op1->e.op_code = OP_GROUP;
A->e.op1->e.op1 = EXPcreate(Type_Self);
A->e.op1->e.op2 = EXPcreate_from_symbol(Type_Entity, B.symbol);
SYMBOL_destroy(B.symbol);
A->e.op_code = OP_DOT;
A->e.op2 = EXPcreate_from_symbol(Type_Attribute, C.symbol);
SYMBOL_destroy(C.symbol);
}
attribute_decl_list(A) ::= attribute_decl(B).
{
A = LISTcreate();
LISTadd_last(A, (Generic)B);
}
attribute_decl_list(A) ::= attribute_decl_list(B) TOK_COMMA
attribute_decl(C).
{
A = B;
LISTadd_last(A, (Generic)C);
}
optional(A) ::= /*NULL*/.
{
A.optional = 0;
}
optional(A) ::= TOK_OPTIONAL.
{
A.optional = 1;
}
explicit_attribute(A) ::= attribute_decl_list(B) TOK_COLON optional(C)
attribute_type(D) semicolon.
{
Variable v;
LISTdo_links (B, attr)
v = VARcreate((Expression)attr->data, D);
v->flags.optional = C.optional;
v->flags.attribute = true;
attr->data = (Generic)v;
LISTod;
A = B;
}
express_file ::= schema_decl_list.
schema_decl_list(A) ::= schema_decl(B).
{
A = B;
}
schema_decl_list(A) ::= schema_decl_list(B) schema_decl.
{
A = B;
}
expression(A) ::= simple_expression(B).
{
A = B;
}
expression(A) ::= expression(B) TOK_AND expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_AND, B, C);
}
expression(A) ::= expression(B) TOK_OR expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_OR, B, C);
}
expression(A) ::= expression(B) TOK_XOR expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_XOR, B, C);
}
expression(A) ::= expression(B) TOK_LESS_THAN expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_LESS_THAN, B, C);
}
expression(A) ::= expression(B) TOK_GREATER_THAN expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_GREATER_THAN, B, C);
}
expression(A) ::= expression(B) TOK_EQUAL expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_EQUAL, B, C);
}
expression(A) ::= expression(B) TOK_LESS_EQUAL expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_LESS_EQUAL, B, C);
}
expression(A) ::= expression(B) TOK_GREATER_EQUAL expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_GREATER_EQUAL, B, C);
}
expression(A) ::= expression(B) TOK_NOT_EQUAL expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_NOT_EQUAL, B, C);
}
expression(A) ::= expression(B) TOK_INST_EQUAL expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_INST_EQUAL, B, C);
}
expression(A) ::= expression(B) TOK_INST_NOT_EQUAL expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_INST_NOT_EQUAL, B, C);
}
expression(A) ::= expression(B) TOK_IN expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_IN, B, C);
}
expression(A) ::= expression(B) TOK_LIKE expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_LIKE, B, C);
}
expression ::= simple_expression cardinality_op simple_expression.
{
yyerrok;
}
simple_expression(A) ::= unary_expression(B).
{
A = B;
}
simple_expression(A) ::= simple_expression(B) TOK_CONCAT_OP
simple_expression(C).
{
yyerrok;
A = BIN_EXPcreate(OP_CONCAT, B, C);
}
simple_expression(A) ::= simple_expression(B) TOK_EXP simple_expression(C).
{