-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
express_parser.jison
711 lines (616 loc) · 21.5 KB
/
express_parser.jison
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
%lex
var expressSchemaBuilder = require("expressSchemaBuiler");
%%
\s+ /* skip whitespace */
"'"([^\']*)"'" return 'QUOTED_STRING';
"(*"([^\*]|\n|\r)*"*)" /* ignore multiline comment */ console.log(" Comment - ",yytext);
"--".* /* ignore end of line comment */;
ABSTRACT return 'ABSTRACT';
ANDOR return 'ANDOR';
AND return 'AND';
ARRAY return 'ARRAY';
BAG return 'BAG';
BEGIN return 'BEGIN';
BY return 'BY';
CASE return 'CASE';
CONSTANT return 'CONSTANT';
DERIVE return 'DERIVE';
ELSE return 'ELSE';
END_CASE return 'END_CASE';
END_CONSTANT return 'END_CONSTANT';
END_ENTITY return 'END_ENTITY';
END_FUNCTION return 'END_FUNCTION';
END_IF return 'END_IF';
END_LOCAL return 'END_LOCAL';
END_RULE return 'END_RULE';
END_REPEAT return 'END_REPEAT';
END_TYPE return 'END_TYPE';
END_SCHEMA return 'END_SCHEMA';
END return 'END';
ENTITY return 'ENTITY';
ENUMERATION return 'ENUMERATION';
ESCAPE return 'ESCAPE';
EXISTS return 'EXISTS';
FIXED return 'FIXED';
FOR return 'FOR';
FUNCTION return 'FUNCTION';
GENERIC return 'GENERIC';
IF return 'IF';
INTEGER return 'INTEGER';
INVERSE return 'INVERSE';
IN return 'IN';
LIST return 'LIST';
LIKE return 'LIKE';
LOCAL return 'LOCAL';
LOGICAL return 'LOGICAL';
MOD return 'MOD';
NUMBER return 'NUMBER';
NOT return 'NOT';
NVL return 'NVL';
OF return 'OF';
ONEOF return 'ONEOF';
OPTIONAL return 'OPTIONAL';
OR return 'OR';
OTHERWISE return 'OTHERWISE';
QUERY return 'QUERY';
REAL return 'REAL';
REPEAT return 'REPEAT';
RETURN return 'RETURN';
RULE return 'RULE';
SCHEMA return 'SCHEMA';
SELECT return 'SELECT';
SELF return 'SELF';
SET return 'SET';
STRING return 'STRING';
SIZEOF return 'SIZEOF';
SUBTYPE return 'SUBTYPE';
SUPERTYPE return 'SUPERTYPE';
THEN return 'THEN';
TYPEOF return 'TYPEOF';
TO return 'TO';
TYPE return 'TYPE';
UNIQUE return 'UNIQUE';
USEDIN return 'USEDIN';
WHERE return 'WHERE';
XOR return 'XOR';
[a-zA-Z_][a-zA-Z0-9_]* return 'identifier';
(\-)?[0-9]+"."[0-9]*(E(\-)?[0-9]+)? return 'FLOAT';
[0-9]+ return 'NUMBER';
':<>:' return ':<>:';
'?' return '?';
':=:' return ':=:';
':=' return ':=';
'=' return '=';
';' return ';';
':' return ':';
')' return ')';
'(' return '(';
'||' return '||';
"'" return "'";
',' return ',';
'<=' return '<=';
'>=' return '>=';
'<>' return '<>';
'<*' return '<*';
'<' return '<';
'>' return '>';
']' return ']';
'[' return '[';
'.' return '.';
'|' return '|';
'*' return '*';
'/' return '/';
'-' return '-';
'+' return '+';
'\\' return '\\';
'{' return '{';
'}' return '}';
<<EOF>> return 'EOF';
/lex
%left '<=' '>=' '<' '>' '<*' '|' '=' '*' '/' '\\' ':<>:' ':=:' '||' '+' '-' '<>'
%left AND OR IN ANDOR XOR MOD LIKE
/* %left ')'*/
%left UNOT
%start expressions
%% /* language grammar */
_expressions : expression
| _expressions expression
;
expressions :
_expressions EOF
;
bag_or_set : BAG
| SET
;
inverse : identifier ':' bag_or_set range OF identifier FOR identifier ';'
| identifier ':' identifier FOR identifier ';'
;
inverse_list : inverse |inverse inverse_list
;
optional_inverse:| INVERSE inverse_list
;
abstract_el : ABSTRACT SUPERTYPE
{
$$ = {
abstract: "ABSTRACT_SUPERTYPE",
};
}
| SUBTYPE OF '(' list_id ')'
{
list_id = $4;
$$ = {
abstract: "SUBTYPE_OF",
list_id: list_id
};
}
| SUBTYPE OF '(' ONEOF '(' list_id ')' ')'
{
list_id = $6;
$$ = {
abstract: "SUBTYPE_OF_ONEOF",
list_id: list_id
};
}
| SUPERTYPE OF '(' list_id ')'
{
list_id = $4;
$$ = {
abstract: "SUPERTYPE_OF",
list_id: list_id
};
}
| SUPERTYPE OF '(' ONEOF '(' list_id ')' ')'
{
list_id = $6;
$$ = {
abstract: "SUBTYPE_OF_ONEOF",
list_id: list_id
};
}
| ABSTRACT SUPERTYPE OF '(' ONEOF '(' list_id ')' ')'
{
list_id = $6;
$$ = {
abstract: "SUBTYPE_OF_ONEOF",
list_id: list_id
};
}
| SUPERTYPE OF '(' ONEOF '(' list_id ')' ANDOR identifier ')'
{
list_id = $6;
identifier = $9;
$$ = {
abstract: "SUBTYPE_OF_ONEOF_ANDOR",
list_id: list_id,
andor: identifier
};
}
| SUPERTYPE OF '(' ONEOF '(' list_id ')' ANDOR ONEOF '(' list_id ')' ')'
{
list_id = $6;
identifier_list_id = $11;
$$ = {
abstract: "SUBTYPE_OF_ONEOF_ANDOR_ONEOF",
list_id: list_id,
andor: identifier_list_id
};
}
;
optional_derive :| DERIVE list_der
;
optional_sections :| DERIVE list_der optional_sections
| UNIQUE unique_list optional_sections
| INVERSE inverse_list optional_sections
;
list_der : list_der_item
| list_der_item list_der
;
list_der_item : identifier ':' composite_type ':=' expr2 ';'
| SELF '\\' identifier ':' composite_type ':=' expr2 ';'
| SELF '\\' identifier '.' identifier ':' composite_type ':=' expr2 ';'
| LIST range OF identifier ':=' expr2 ';'
;
optional_abstract : /* nothing */
{
$$ = null;
}
| abstract_el
{
$$ = [ $1 ];
}
| abstract_el abstract_el
{
$$ = [ $1 , $2 ];
}
| abstract_el abstract_el abstract_el
{
$$ = [ $1 , $2 , $3 ];
}
;
expression:
SCHEMA identifier ';'
{
}
| END_SCHEMA';'
| CONSTANT constants END_CONSTANT ';'
| TYPE type END_TYPE ';'
| ENTITY identifier optional_abstract ';'
entity_description
optional_sections
optional_where_rules
END_ENTITY ';'
{
var name = $2;
var abstract = $3;
options = {}
options.properties = $5;
if (abstract != null) {
options.abstract = abstract;
}
yy.grammar.add_entity(name,options);
}
| ENTITY identifier optional_abstract';'
optional_sections
optional_where_rules
END_ENTITY ';'
{
// console.log(" ENTITY-B" , $2);
var name = $2 ;
var abstract = $3;
options = {}
options.properties = [];
if (abstract != null) {
options.abstract = abstract;
}
yy.grammar.add_entity(name,options);
}
| RULE identifier FOR '(' list_id ')' ';'
optional_function_local_declarations
function_statements
optional_where_rules
END_RULE ';'
| FUNCTION identifier '(' function_args_declaration ')' ':' function_argument_type ';'
optional_function_local_declarations
function_statements
END_FUNCTION ';'
;
local_declaration : list_identifiers ':' function_argument_type ':=' expr2 ';'
| list_identifiers ':' function_argument_type ';'
;
local_declarations :| local_declaration local_declarations
;
function_local_declarations : LOCAL local_declarations END_LOCAL ';'
;
optional_function_local_declarations :| function_local_declarations
;
function_argument_type: composite_type
;
list_identifiers: identifier
| identifier ',' list_identifiers
;
function_args: list_identifiers ':'function_argument_type
;
function_args_declaration:| function_args
| function_args ';' function_args_declaration
;
function_statements :| function_statement function_statements ;
repeat_opt_by :| BY expr2 ;
cases : expr2 ':' function_statement
;
list_cases : cases
| cases list_cases
;
function_statement:
IF expr2 THEN function_statements END_IF ';'
| IF expr2 THEN function_statements ELSE function_statements END_IF ';'
| id2 ':=' expr2 ';'
| REPEAT identifier ':=' expr2 TO expr2 ';' function_statements END_REPEAT ';'
| REPEAT identifier ':=' expr2 TO expr2 BY expr2 ';' function_statements END_REPEAT ';'
| RETURN expr2 ';'
| CASE id3 OF list_cases OTHERWISE ':' function_statement END_CASE';'
| CASE id3 OF list_cases END_CASE';'
| ESCAPE ';'
| BEGIN function_statements END ';'
;
optional_where_rules: | WHERE rules;
unique : identifier ':' list_id ';'
;
unique_list : unique
| unique unique_list
;
optional_unique: | UNIQUE unique_list
;
optional_OPTIONAL :
| OPTIONAL
;
composite_type : basic_type
{
$$ = $1;
}
| identifier
{
$$ = $1;
}
| GENERIC ':' composite_type
{
composite_type = $3;
$$ = {
type: "GENERIC",
composite_type: composite_type
};
}
| ARRAY OF composite_type
{
composite_type = $3;
$$ = {
type: "GENERIC",
composite_type: composite_type
};
}
| ARRAY range OF composite_type
{
composite_type = $4;
$$ = {
type: "GENERIC",
composite_type: composite_type
};
}
| BAG OF composite_type
{
composite_type = $3;
$$ = {
type: "BAG_OF",
composite_type: composite_type
};
}
| LIST range OF composite_type
{
composite_type = $4;
$$ = {
type: "LIST_RANGE_OF",
composite_type: composite_type
};
}
| LIST OF composite_type
{
composite_type = $3;
$$ = {
type: "LIST_OF",
composite_type: composite_type
};
}
| LIST range OF UNIQUE composite_type
{
composite_type = $5;
$$ = {
type: "LIST_RANGE_OF_UNIQUE",
composite_type: composite_type
};
}
| SET range OF composite_type
{
composite_type = $4;
$$ = {
type: "SET_OF",
composite_type: composite_type
};
}
| SET OF composite_type
{
composite_type = $3;
$$ = {
type: "SET_OF",
composite_type: composite_type
};
}
;
entity_prop : identifier ':' composite_type ';'
{
identifier = $1;
composite_type = $3;
$$ = {
identifier: identifier,
composite_type: composite_type,
optional: false
}
}
| identifier ':' OPTIONAL composite_type ';'
{
identifier = $1;
composite_type = $4;
$$ = {
identifier: identifier,
composite_type: composite_type,
optional: true
}
}
;
entity_description : entity_prop
{
$$ = [ $1 ];
}
| entity_prop entity_description
{
$$ = $2;
$$.unshift($1);
}
;
constants: constant
| constant constants
;
args :
| expr
| args ',' expr
;
stuff : string
| identifier
| NUMBER
;
expr : stuff
{
console.log("suff=",$1);
}
| identifier '(' args ')'
| identifier '[' args ']'
| expr '||' expr
| expr '+' expr
| expr '-' expr
| expr '*' expr
| expr '/' expr
| '(' expr ')'
| '[' expr ':' expr ']'
| '[' expr ']'
;
string : QUOTED_STRING
;
constant_b : identifier ':=' expr ';'
;
constant : identifier ":" constant_b
;
list_id : identifier
{
$$ = [ $1 ];
}
| identifier ANDOR identifier
{
$$ = [ $1 , $2 ]
}
| identifier ',' list_id
{
$$ = $3
$3.unshift($1);
}
;
basic_type : REAL
| INTEGER
| NUMBER
| STRING
| STRING '(' NUMBER ')' FIXED
| STRING '(' NUMBER ')'
| LOGICAL
;
basic_type2 : basic_type
| identifier
;
op : '<=' | '>=' | AND | OR | XOR | IN | '<*'
;
function : EXISTS | QUERY | SIZEOF | TYPEOF | NVL | USEDIN
;
list_item : "'" identifier '.' identifier "'"
| NUMBER
;
list : list_item
| list ',' list_item
;
id3 : identifier
| id3 '[' expr2 ']'
| id3 '.' identifier
;
id2 : id3
| id3 '\' id3
| SELF '.' id3
| SELF '\' id3
| SELF
| "'" identifier '.' identifier "'"
| "'" identifier '.' identifier '.' "'"
| "'" identifier '.' "'"
| "'" identifier "'"
| "'" "'"
| SELF '[' expr2 ']'
;
variable : SELF
| identifier
| "'" identifier '.' identifier "'"
;
list_arguments :| expr2
| expr2 ',' list_arguments
;
less_op : '<' | '<='
;
expr2 : expr2 '<=' expr2
| expr2 '>=' expr2
| expr2 '<' expr2
| expr2 '>' expr2
| '{' NUMBER '<' expr2 '<=' NUMBER '}'
| '{' NUMBER '<=' expr2 '<=' NUMBER '}'
| '{' FLOAT '<' expr2 '<=' FLOAT '}'
| '{' FLOAT '<=' expr2 '<=' FLOAT '}'
| expr2 AND expr2
| expr2 ANDOR expr2
| expr2 OR expr2
| expr2 XOR expr2
| expr2 MOD expr2
| expr2 IN expr2
| expr2 LIKE expr2
| expr2 '<*' expr2
| expr2 '|' expr2
| expr2 '||' expr2
| expr2 '<>' expr2
| expr2 '*' expr2
| expr2 '/' expr2
| expr2 '+' expr2
| expr2 '-' expr2
| expr2 '=' expr2
| expr2 '\\' expr2
| expr2 ':<>:' expr2
| expr2 ':=:' expr2
| NUMBER
| FLOAT
| string
| '?'
| function '(' list_arguments ')'
| function '(' list_arguments ')' '.' id2
| identifier '(' list_arguments ')'
| identifier '(' list_arguments ')' '.' id2
| id2
| '[' list_arguments ']'
| '[' expr2 ':' expr2 ']'
| '(' expr2 ')'
| NOT expr2 %prec UNOT
| '-' expr2 %prec UNOT
;
rule : identifier ':' expr2 ';'
| identifier ':' ';'
;
rules : rule
| rule rules
;
range : '[' NUMBER ':' '?' ']'
{
}
| '[' NUMBER ':' NUMBER ']'
| '[' NUMBER ':' identifier ']'
| '[' identifier ':' identifier ']'
;
type_declaration : identifier "=" ENUMERATION OF '(' list_id ')' ';'
{
var name = $1;
var values = $6;
yy.grammar.add_enumeration(name,values);
}
| identifier "=" ARRAY range OF basic_type2 ';'
| identifier "=" MLIST range OF basic_type2 ';'
| identifier "=" LIST range OF basic_type2 ';'
| identifier "=" SET range OF basic_type2 ';'
| identifier "=" SELECT '(' list_id ')' ';'
{
var name = $1;
var values = $5;
yy.grammar.add_select(name,values);
}
| identifier "=" basic_type ';'
{
var name = $1;
var type = $3;
yy.grammar.add_type(name,type);
}
| identifier "=" identifier ';'
{
var name = $1;
var type = $3;
yy.grammar.add_type(name,type);
}
;
type : type_declaration
| type_declaration WHERE rules
;