sdl92.g 39 KB
Newer Older
dbarbera's avatar
dbarbera committed
1
/*
Maxime Perrotin's avatar
Maxime Perrotin committed
2
3
    OpenGEODE
    ANTLR 3.1.3 grammar for the SDL92 langage
4
5
    Includes the following features from SDL2000+:
    - FOR loops in TASKs
6
    - Composite states (nested and agreggation/parallel states)
Maxime Perrotin's avatar
Maxime Perrotin committed
7
8

    author: Maxime Perrotin
9
    with contributions from Diego Barbera, Laurent Meyer
Maxime Perrotin's avatar
Maxime Perrotin committed
10
11
12
13
14
*/

grammar sdl92;

options {
Maxime Perrotin's avatar
Maxime Perrotin committed
15
    language=Python3;
Maxime Perrotin's avatar
Maxime Perrotin committed
16
17
18
19
20
21
22
    output=AST;
    ASTLabelType=CommonTree;
    backtrack=true;
}

tokens {
        ACTION;
dbarbera's avatar
dbarbera committed
23
        ALL;
Maxime Perrotin's avatar
Maxime Perrotin committed
24
25
        ALTERNATIVE;
        ANSWER;
dbarbera's avatar
dbarbera committed
26
27
28
29
30
31
32
33
        ARRAY;
        ASN1;
        ASSIGN;
        BITSTR;
        BLOCK;
        CHANNEL;
        CHOICE;
        CIF;
Maxime Perrotin's avatar
Maxime Perrotin committed
34
        CLOSED_RANGE;
dbarbera's avatar
dbarbera committed
35
36
        COMMENT;
        COMPOSITE_STATE;
37
        CONDITIONAL;
dbarbera's avatar
dbarbera committed
38
39
        CONNECT;
        CONNECTION;
Maxime Perrotin's avatar
Maxime Perrotin committed
40
        CONSTANT;
dbarbera's avatar
dbarbera committed
41
42
43
44
        CONSTANTS;
        DCL;
        DECISION;
        DIGITS;
Maxime Perrotin's avatar
Maxime Perrotin committed
45
        ELSE;
dbarbera's avatar
dbarbera committed
46
47
48
49
        EMPTYSTR;
        ENDNEWTYPE;
        ENDSYNTYPE;
        ENDTEXT;
50
        ENTRY_POINT;
dbarbera's avatar
dbarbera committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        EXPORT;
        EXPRESSION;
        EXTERNAL;
        FI;
        FIELD;
        FIELD_NAME;
        FIELDS;
        FLOAT2;
        FLOAT;
        FLOATING_LABEL;
        FOR;
        FPAR;
        GROUND;
        HYPERLINK;
        IF;
        IFTHENELSE;
        IN;
        INFORMAL_TEXT;
        INOUT;
        INPUT;
        INPUT_NONE;
        INPUTLIST;
        JOIN;
        LABEL;
75
        LITERAL;
dbarbera's avatar
dbarbera committed
76
77
78
79
80
81
        NEG;
        NEWTYPE;
        NEXTSTATE;
        NUMBER_OF_INSTANCES;
        OCTSTR;
        OPEN_RANGE;
Maxime Perrotin's avatar
Maxime Perrotin committed
82
83
        OUTPUT;
        OUTPUT_BODY;
dbarbera's avatar
dbarbera committed
84
85
        PARAM;
        PARAMNAMES;
Maxime Perrotin's avatar
Maxime Perrotin committed
86
        PARAMS;
87
        PAREN;
88
        PFPAR;
89
        POINT;
Maxime Perrotin's avatar
Maxime Perrotin committed
90
        PRIMARY;
dbarbera's avatar
dbarbera committed
91
92
93
94
95
        PROCEDURE;
        PROCEDURE_CALL;
        PROCEDURE_NAME;
        PROCESS;
        PROVIDED;
Maxime Perrotin's avatar
Maxime Perrotin committed
96
        QUESTION;
dbarbera's avatar
dbarbera committed
97
98
99
        RANGE;
        RESET;
        RETURN;
100
        RETURNS;
Maxime Perrotin's avatar
Maxime Perrotin committed
101
        ROUTE;
dbarbera's avatar
dbarbera committed
102
        SAVE;
103
        SELECTOR;
dbarbera's avatar
dbarbera committed
104
105
106
107
108
109
110
        SEQOF;
        SEQUENCE;
        SET;
        SIGNAL;
        SIGNAL_LIST;
        SORT;
        STATE;
111
112
        STATE_AGGREGATION;
        STATE_PARTITION_CONNECTION;
dbarbera's avatar
dbarbera committed
113
114
115
        STATELIST;
        STIMULUS;
        STOP;
Maxime Perrotin's avatar
Maxime Perrotin committed
116
        STOPIF;
dbarbera's avatar
dbarbera committed
117
        STRING;
118
        STRUCT;
119
120
        SYNONYM;
        SYNONYM_LIST;
dbarbera's avatar
dbarbera committed
121
122
123
124
125
126
127
128
129
130
131
132
        SYNTYPE;
        SYSTEM;
        TASK;
        TASK_BODY;
        TERMINATOR;
        TEXT;
        TEXTAREA;
        TEXTAREA_CONTENT;
        THEN;
        TIMER;
        TO;
        TRANSITION;
133
        TYPE_INSTANCE;
dbarbera's avatar
dbarbera committed
134
135
136
137
138
139
        USE;
        VALUE;
        VARIABLE;
        VARIABLES;
        VIA;
        VIAPATH;
Maxime Perrotin's avatar
Maxime Perrotin committed
140
141
142
143
144
145
146
147
148
}


/*
    Top level: any .pr file
*/
pr_file
        :       (use_clause
                | system_definition
149
150
                | process_definition)+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
151
152
153
154
155
156


system_definition
        :       SYSTEM system_name end
                entity_in_system*
                ENDSYSTEM system_name? end
157
158
        ->      ^(SYSTEM system_name entity_in_system*)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
159
160
161
162


use_clause
        :       use_asn1?
163
164
165
                USE package_name
                ('/' def_selection_list )?
                end
166
167
168
        ->      ^(USE use_asn1? end? package_name def_selection_list?)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
169

170
171
172
173
/*
    In USE clause: USE package/X, Y, Z;
*/
def_selection_list
174
175
176
        :       ID (','! ID)*
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
177
178
179
180
181
182

/* Entity in system:
   Declare signals, external procedures, connections and blocks
*/
entity_in_system
        :       signal_declaration
183
                | text_area
Maxime Perrotin's avatar
Maxime Perrotin committed
184
185
                | procedure
                | channel
186
187
                | block_definition
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
188
189
190
191
192
193
194

/* signal_declaration:
   e.g. SIGNAL open_door(typeA, typeB);
*/
signal_declaration
        :       paramnames?
                SIGNAL signal_id input_params? end
195
196
        ->      ^(SIGNAL paramnames? signal_id input_params?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
197
198
199
200
201
202


channel
        :       CHANNEL channel_id
                route+
                ENDCHANNEL end
203
204
        ->      ^(CHANNEL channel_id route+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
205
206
207
208


route
        :       FROM source_id TO dest_id WITH signal_id (',' signal_id)* end
209
210
        ->      ^(ROUTE source_id dest_id signal_id+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
211
212
213
214


block_definition
        :       BLOCK block_id end
dbarbera's avatar
dbarbera committed
215
                entity_in_block*
Maxime Perrotin's avatar
Maxime Perrotin committed
216
                ENDBLOCK end
217
218
        ->      ^(BLOCK block_id entity_in_block*)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
219
220
221
222
223
224
225
226
227
228
229


/* Inside a SDL block:
   there can be nested blocks, processes, signalroutes and connections
   to above channels
*/
entity_in_block
        :       signal_declaration
                | signalroute
                | connection
                | block_definition
230
231
                | process_definition
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
232

233
234
235
// There should be at least one route in the signal route
// However it is now optional (* and not +) to appease the
// syntax checker in the tool.
Maxime Perrotin's avatar
Maxime Perrotin committed
236
signalroute
237
238
239
        :       SIGNALROUTE route_id end?
                route*
        ->      ^(SIGNALROUTE route_id route*)
240
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
241
242
243
244


connection
        :       CONNECT channel_id AND route_id end
245
246
        ->      ^(CONNECTION channel_id route_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
247
248


249
250
251
252
253
254
255
256
/* process_definition
   Covers various cases such as:
   PROCESS name REFERENCED;
   PROCESS name;
      <body>
   ENDPROCESS <name>;
   Etc. The grammar is tolerant, semantic checks are done in the code.
*/
Maxime Perrotin's avatar
Maxime Perrotin committed
257
process_definition
258
        :       cif?
Maxime Perrotin's avatar
Maxime Perrotin committed
259
                PROCESS t=TYPE? process_id
260
                number_of_instances? (':' type_inst)? REFERENCED? a=end
261
                pfpar?
262
                (text_area | procedure | (composite_state_preamble) =>composite_state)*
Maxime Perrotin's avatar
Maxime Perrotin committed
263
                processBody? ENDPROCESS? TYPE? process_id?
264
265
                end?
        ->      ^(PROCESS cif? process_id number_of_instances? type_inst?
Maxime Perrotin's avatar
Maxime Perrotin committed
266
                $t? REFERENCED? $a? pfpar? text_area* procedure*
267
                composite_state* processBody?)
268
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
269

270

271
272
273
274
// Process formal parameters
pfpar
        :       FPAR parameters_of_sort
                (',' parameters_of_sort)*
275
                end?
276
277
278
        ->      ^(PFPAR parameters_of_sort+)
        ;

279
280
281

parameters_of_sort
        :       variable_id (',' variable_id)* sort
282
283
        ->      ^(PARAM variable_id+ sort)
        ;
284

Maxime Perrotin's avatar
Maxime Perrotin committed
285

286
// procedure
Maxime Perrotin's avatar
Maxime Perrotin committed
287
288
procedure
        :       cif?
289
                PROCEDURE procedure_id (e1=end | SEMI)
Maxime Perrotin's avatar
Maxime Perrotin committed
290
                fpar?
291
                res=procedure_result?
Maxime Perrotin's avatar
Maxime Perrotin committed
292
293
                (text_area | procedure)*
                ((processBody? ENDPROCEDURE procedure_id?) | EXTERNAL)
294
                e2=end
295
        ->      ^(PROCEDURE cif? procedure_id $e1? $e2? fpar? $res?
296
297
                text_area* procedure* processBody? EXTERNAL?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
298

299
300
301
302
// Procedure result / optional return type
procedure_result
        :       ('->' | RETURNS)
                variable_id?
303
                sort end?
304
305
        ->      ^(RETURNS variable_id? sort)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
306
307
308
309
310

// Procedure formal parameters
fpar
        :       FPAR formal_variable_param
                (',' formal_variable_param)*
311
                end
312
313
        ->      ^(FPAR formal_variable_param+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
314
315
316


formal_variable_param
317
        :       (INOUT | IN | OUT)?
Maxime Perrotin's avatar
Maxime Perrotin committed
318
                variable_id (',' variable_id)* sort
319
320
        ->      ^(PARAM INOUT? IN? OUT? variable_id+ sort)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
321
322
323
324
325
326
327


// text_area: TODO add operator description in content
text_area
        :       cif
                content?
                cif_end_text
328
329
        ->      ^(TEXTAREA cif content? cif_end_text)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
330
331
332
333
334
335


// Text areas can contain textual procedures, FPAR declarations,
// and variable or timer declarations
content
        :        (procedure
336
337
                 | use_clause
                 | signal_declaration
Maxime Perrotin's avatar
Maxime Perrotin committed
338
                 | fpar
339
                 | res=procedure_result
Maxime Perrotin's avatar
Maxime Perrotin committed
340
                 | timer_declaration
341
342
                 | syntype_definition
                 | newtype_definition
343
344
                 | variable_definition
                 | synonym_definition)*
345
        ->       ^(TEXTAREA_CONTENT fpar* $res? procedure* variable_definition*
Maxime Perrotin's avatar
Maxime Perrotin committed
346
                   syntype_definition* newtype_definition* timer_declaration*
347
348
                   signal_declaration* use_clause* synonym_definition*)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
349
350
351
352
353
354


timer_declaration
        :       TIMER timer_id
                (',' timer_id)*
                end
355
356
357
        ->      ^(TIMER timer_id+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
358

359
syntype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
360
361
362
        :       SYNTYPE syntype_name '=' parent_sort
                (CONSTANTS (range_condition (',' range_condition)* ))?
                ENDSYNTYPE syntype_name? end
363
364
365
        ->      ^(SYNTYPE syntype_name parent_sort range_condition*)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
366
367

syntype_name
368
369
370
        :       sort
        ;

371
372

parent_sort
373
374
375
        :       sort
        ;

376
377

newtype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
378
379
        :       NEWTYPE type_name (array_definition|structure_definition)?
                ENDNEWTYPE type_name? end
380
381
        ->      ^(NEWTYPE type_name array_definition* structure_definition*)
        ;
382
383
384


type_name
385
386
387
        :       sort
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
388

389
array_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
390
        :       ARRAY '(' sort ',' sort ')'
391
392
393
        ->      ^(ARRAY sort sort)
        ;

394
395

structure_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
396
        :       STRUCT field_list end
397
398
399
        ->      ^(STRUCT field_list)
        ;

400
401

field_list
Maxime Perrotin's avatar
Maxime Perrotin committed
402
        :       field_definition (end field_definition)*
403
404
405
        ->      ^(FIELDS field_definition+)
        ;

406
407

field_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
408
        :       field_name (',' field_name)* sort
409
410
411
        ->      ^(FIELD field_name+ sort)
        ;

412

Maxime Perrotin's avatar
Maxime Perrotin committed
413
414
415
416
variable_definition
        :       DCL variables_of_sort
                (',' variables_of_sort)*
                end
417
418
419
        ->      ^(DCL variables_of_sort+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
420

Maxime Perrotin's avatar
Maxime Perrotin committed
421
synonym_definition
422
423
424
        :       internal_synonym_definition
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
425

426
internal_synonym_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
427
428
        :       SYNONYM synonym_definition_item (',' synonym_definition_item)*
                end
429
430
431
        ->      ^(SYNONYM_LIST synonym_definition_item+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
432

433
synonym_definition_item
Maxime Perrotin's avatar
Maxime Perrotin committed
434
        :       sort sort '=' ground_expression
435
436
437
        ->      ^(SYNONYM sort sort ground_expression)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
438
439
440

variables_of_sort
        :       variable_id (',' variable_id)* sort (':=' ground_expression)?
441
442
        ->      ^(VARIABLES variable_id+ sort ground_expression?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
443
444
445
446


ground_expression
        :       expression
447
448
        ->      ^(GROUND expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
449
450
451
452


number_of_instances
        :       '(' initial_number=INT ',' maximum_number=INT ')'
453
454
        ->      ^(NUMBER_OF_INSTANCES $initial_number $maximum_number)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
455
456
457


processBody
458
459
        :       start? (state | floating_label)*
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
460
461
462
463
464


start
        :       cif?
                hyperlink?
465
                START name=state_entry_point_name? end
Maxime Perrotin's avatar
Maxime Perrotin committed
466
                transition?
467
468
        ->      ^(START cif? hyperlink? $name? end? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
469
470
471
472
473
474
475
476
477


floating_label
        :       cif?
                hyperlink?
                CONNECTION connector_name ':'
                transition?
                cif_end_label?
                ENDCONNECTION SEMI
478
479
        ->      ^(FLOATING_LABEL cif? hyperlink? connector_name transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
480
481
482


state
483
        :       cif?
Maxime Perrotin's avatar
Maxime Perrotin committed
484
                hyperlink?
485
                STATE statelist via? (e=end | SEMI) // "via" part may be in NEXTSTATE
Maxime Perrotin's avatar
Maxime Perrotin committed
486
487
                (state_part)*
                ENDSTATE statename? f=end
488
        ->      ^(STATE cif? hyperlink? $e? statelist via? state_part*)
489
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
490
491
492
493


statelist
        :       ((statename)(',' statename)*)
494
        ->      ^(STATELIST statename+)
Maxime Perrotin's avatar
Maxime Perrotin committed
495
                | ASTERISK exception_state?
496
497
        ->      ^(ASTERISK exception_state?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
498
499
500


exception_state
501
        :       '(' statename (',' statename)* ')'
502
503
        ->      statename+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
504
505


506
// 11.11 State Machine and Composite State (SDL2000)
507
composite_state
508
509
510
511
        :       composite_state_graph
                | state_aggregation
        ;

512
513
514
515
516
// used for syntactic predicate
composite_state_preamble
        :       STATE AGGREGATION? statename end
                SUBSTRUCTURE
        ;
517
518

composite_state_graph
519
520
        :       STATE statename e=end
                SUBSTRUCTURE
521
                connection_points*
522
523
                body=composite_state_body
                ENDSUBSTRUCTURE statename? f=end
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
        ->      ^(COMPOSITE_STATE statename connection_points* $body $e?)
        ;


// 11.11.2 State Aggregation (SDL2000)
state_aggregation
        :       STATE AGGREGATION statename e=end
                SUBSTRUCTURE
                connection_points*
                entities=entity_in_composite_state*
                body=state_aggregation_body
                ENDSUBSTRUCTURE statename? f=end
        ->      ^(STATE_AGGREGATION statename connection_points*
                                    $entities* $body $e?)
        ;


// 11.11.2 State Aggregation (SDL2000)
entity_in_composite_state
        :       (text_area | procedure)
        ;


// 11.11.2 State Aggregation (SDL2000)
state_aggregation_body
549
        :       (state_partitioning | state_partition_connection)*
550
                state*
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
        ;


// 11.11.2 State Aggregation (SDL2000)
state_partitioning
        :       composite_state
        ;


// 11.11.2 State Aggregation (SDL2000)
state_partition_connection
        :       CONNECT outer=entry_point AND inner=entry_point end
        ->      ^(STATE_PARTITION_CONNECTION $outer $inner end?)
        ;


// 11.11.2 State Aggregation (SDL2000)
entry_point
        :       state_part_id=ID VIA point
        ->      ^(ENTRY_POINT $state_part_id point)
        ;


// 11.11.2 State Aggregation (SDL2000)
point
        :       (state_point=ID | DEFAULT)
        ->      ^(POINT $state_point? DEFAULT?)
        ;
579
580


581
// 11.11.1 and 11.11.2 Composite State (SDL2000)
582
connection_points
583
584
585
        :       IN state_entry_exit_points end
        ->      ^(IN state_entry_exit_points end?)
                | OUT state_entry_exit_points end
586
587
        ->      ^(OUT state_entry_exit_points end?)
        ;
588
589


590
// 11.11.1 and 11.11.2 Composite State (SDL2000)
591
592
state_entry_exit_points
        :       '(' statename (',' statename)* ')'
593
594
        ->      statename+
        ;
595
596


597
// 11.11.1 Composite State graph content (SDL2000)
598
599
// Use a syntactic predicate to disambiguate the parsing of the composite
// state vs a normal state, in the case of a syntax error in the composite.
600
composite_state_body
601
602
603
604
        :  (text_area
            | procedure
            | (composite_state_preamble) =>composite_state)*
           start* (state | floating_label)*
605
           EOF?
606
        ;
607
608


Maxime Perrotin's avatar
Maxime Perrotin committed
609
610
611
612
613
state_part
        :       input_part
                //| priority_input        // Not supported
                | save_part               // Not supported in openGEODE
                | spontaneous_transition
614
                | continuous_signal
615
616
                | connect_part
        ;
617
618
619
620


// connect part is used to connect nested state exit points to a transition
connect_part
Maxime Perrotin's avatar
Maxime Perrotin committed
621
622
623
624
        :       cif?
                hyperlink?
                CONNECT connect_list? end
                transition?
625
626
        ->      ^(CONNECT cif? hyperlink? connect_list? end? transition?)
        ;
627
628
629
630
631


connect_list
        :       state_exit_point_name (',' state_exit_point_name)*
                -> state_exit_point_name+
632
633
                | ASTERISK
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
634
635
636
637
638
639
640
641


spontaneous_transition
        :       cif?
                hyperlink?
                INPUT NONE end
                enabling_condition?
                transition
642
643
        ->      ^(INPUT_NONE cif? hyperlink? transition)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
644
645
646
647


enabling_condition
        :       PROVIDED expression end
648
649
        ->      ^(PROVIDED expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
650
651
652


continuous_signal
653
654
655
656
        :       cif?
                hyperlink?
                PROVIDED expression e=end
                (PRIORITY p=INT end)?
657
658
                transition?
        ->      ^(PROVIDED expression cif? hyperlink? $p? $e? transition?)
659
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
660
661
662
663
664


save_part
        :       SAVE save_list
                end
665
666
        ->      ^(SAVE save_list)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
667
668
669
670


save_list
        :       signal_list
671
672
                | asterisk_save_list
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
673
674
675
676
677
678
679
680


asterisk_save_list
        :       ASTERISK;


signal_list
        :       signal_item (',' signal_item)*
681
682
        ->      ^(SIGNAL_LIST signal_item+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
683
684
685
686
687
688
689
690
691
692
693



// Signal_item alternatives are all of the same ID type.
// Should be resolved at semantic analysis.
signal_item
        :       signal_id; /* |
                priority_signal_id |
                signal_list_id |
                timer_id;*/

dbarbera's avatar
dbarbera committed
694
/*   Not considered for the moment
Maxime Perrotin's avatar
Maxime Perrotin committed
695
696
     (irrelevant in the scope of the generation of code for a single process)
priority_input
dbarbera's avatar
dbarbera committed
697
        :       PRIORITY INPUT priority_input_list end transition;
Maxime Perrotin's avatar
Maxime Perrotin committed
698
699
700
701
702
703
704
705
706
707
708
709
710
711


priority_input_list
        :       priority_stimulus (',' priority_stimulus)*;

priority_stimulus
        :       priority_signal_id ( '(' variable_id (',' variable_id)* ')');
*/


// this is only the "basic input part" from SDL92
input_part
        :       cif?
                hyperlink?
Maxime Perrotin's avatar
Maxime Perrotin committed
712
713
                INPUT inputlist end
                enabling_condition?
Maxime Perrotin's avatar
Maxime Perrotin committed
714
715
                transition?
        ->      ^(INPUT cif? hyperlink? end?
716
717
                inputlist enabling_condition? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
718
719
720
721
722
723
724


// asterisk means: all signals not excplicitely specified
// (semantic is different from asterisk state)
inputlist
        :       ASTERISK
                | (stimulus (',' stimulus)*)
725
726
        ->      ^(INPUTLIST stimulus+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
727
728
729


stimulus
730
731
        :       stimulus_id input_params?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
732
733
734
735


input_params
        :       L_PAREN variable_id (',' variable_id)* R_PAREN
736
737
        ->      ^(PARAMS variable_id+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
738
739
740
741
742
743


transition
        :       action+ label? terminator_statement?
        ->      ^(TRANSITION action+ label? terminator_statement?)
                | terminator_statement
744
745
        ->      ^(TRANSITION terminator_statement)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
746
747
748
749
750
751
752
753
754
755
756
757
758


action
        :       label?
                (task
                | task_body
                | output
                | create_request
                | decision
                | transition_option
                | set_timer
                | reset_timer
                | export     // Not supported in OpenGEODE
759
760
761
                | procedure_call)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
762
763
764
765
766

export
        :       EXPORT
                L_PAREN variable_id (COMMA variable_id)* R_PAREN
                end
767
768
769
        ->      ^(EXPORT variable_id+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
770
771
772

/*
remote_procedure_call
dbarbera's avatar
dbarbera committed
773
        :       CALL remote_procedure_call_body;
Maxime Perrotin's avatar
Maxime Perrotin committed
774
775

remote_procedure_call_body
dbarbera's avatar
dbarbera committed
776
        :       remote_procedure_id actual_parameters? (TO destination)?;
Maxime Perrotin's avatar
Maxime Perrotin committed
777
778
779
780
781
*/
procedure_call
        :       cif?
                hyperlink?
                CALL procedure_call_body end
782
783
        ->      ^(PROCEDURE_CALL cif? hyperlink? end? procedure_call_body)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
784
785
786


procedure_call_body
dbarbera's avatar
dbarbera committed
787
        :       procedure_id actual_parameters?
788
789
        ->      ^(OUTPUT_BODY procedure_id actual_parameters?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
790
791
792
793
794


set_timer
        :       SET set_statement (COMMA set_statement)*
                end
795
796
        ->      set_statement+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
797
798
799
800


set_statement
        :       L_PAREN (expression COMMA)? timer_id R_PAREN
801
802
        ->      ^(SET expression? timer_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
803
804
805
806
807
808
        // ('('expression_list')')? ')'; (removed because of non-LL(*) problem)


reset_timer
        :       RESET reset_statement (',' reset_statement)*
                end
809
810
        ->      reset_statement+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
811
812
813
814


reset_statement
        :       timer_id ('(' expression_list ')')?
815
816
        ->      ^(RESET timer_id expression_list?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
817
818
819
820
821
822
823


transition_option
        :       ALTERNATIVE alternative_question e=end
                answer_part
                alternative_part
                ENDALTERNATIVE f=end
824
825
        ->      ^(ALTERNATIVE answer_part alternative_part)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
826
827
828
829
830
831


alternative_part
        :       (answer_part+ else_part?)
        ->      answer_part+ else_part?
                | else_part
832
833
        ->      else_part
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
834
835
836
837


alternative_question
        :       expression
838
839
                | informal_text
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
840
841
842
843
844
845
846
847
848
849


decision
        :       cif?
                hyperlink?
                DECISION question e=end
                answer_part?
                alternative_part?
                ENDDECISION f=end
        ->      ^(DECISION cif? hyperlink? $e? question
850
851
                answer_part? alternative_part?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
852
853
854
855
856
857


answer_part
        :       cif?
                hyperlink?
                L_PAREN answer R_PAREN ':' transition?
858
859
        ->      ^(ANSWER cif? hyperlink? answer transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
860
861
862
863


answer
        :       range_condition
864
865
                | informal_text
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
866
867
868
869
870
871


else_part
        :       cif?
                hyperlink?
                ELSE ':' transition?
872
873
        ->      ^(ELSE cif? hyperlink? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
874
875
876


question
877
878
        :       informal_text
                | expression
Maxime Perrotin's avatar
Maxime Perrotin committed
879
880
        ->      ^(QUESTION expression)
                | ANY
881
882
        ->      ^(ANY)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
883
884
885


range_condition
886
887
        :       (closed_range | open_range)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
888
889
890
891
                //(',' (closed_range|open_range))*;


closed_range
892
        :       a=expression ':' b=expression
893
894
        ->      ^(CLOSED_RANGE $a $b)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
895
896
897
898
899
900


open_range
        :       constant
        ->      constant
                | ( (EQ|NEQ|GT|LT|LE|GE) constant)
901
902
        ->      ^(OPEN_RANGE EQ? NEQ? GT? LT? LE? GE? constant)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
903
904
905
906


constant
        :       expression
907
908
        ->      ^(CONSTANT expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
909
910
911


create_request
dbarbera's avatar
dbarbera committed
912
        :       CREATE
Maxime Perrotin's avatar
Maxime Perrotin committed
913
914
915
                createbody
                actual_parameters?
                end
916
917
        ->      ^(CREATE createbody actual_parameters?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
918
919
920
921


createbody
        :       process_id
922
923
                | THIS
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
924
925
926
927
928
929


output
        :       cif?
                hyperlink?
                OUTPUT outputbody end
930
931
        ->      ^(OUTPUT cif? hyperlink? end? outputbody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
932
933
934


outputbody
935
        :       outputstmt (',' outputstmt)* to_part?
936
937
        ->      ^(OUTPUT_BODY outputstmt+ to_part?)
        ;
938
939
 //               via_part?
 //     -> (signal_id actual_parameters?)+ to_part? via_part?;
Maxime Perrotin's avatar
Maxime Perrotin committed
940
941
942


outputstmt
dbarbera's avatar
dbarbera committed
943
        :       signal_id
944
945
                actual_parameters?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
946

947
to_part
Maxime Perrotin's avatar
Maxime Perrotin committed
948
        :       (TO destination)
949
950
        ->      ^(TO destination)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
951

952
via_part
dbarbera's avatar
dbarbera committed
953
        :       VIA viabody
954
955
        ->      ^(VIA viabody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
956
957
958
959


// ambiguous in SDL92, added OR between ALL and via_path
viabody
dbarbera's avatar
dbarbera committed
960
        :       ALL
Maxime Perrotin's avatar
Maxime Perrotin committed
961
962
        ->      ^(ALL)
                | via_path
963
964
        ->      ^(VIAPATH via_path)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
965
966
967
968
969


destination
        :       pid_expression
                | process_id
970
971
                | THIS
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
972
973
974
975


via_path
        :       via_path_element (',' via_path_element)*
976
977
        ->      via_path_element+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
978
979
980


via_path_element
981
982
        :       ID
        ; // signal_route_id | channel_id | gate_id;
Maxime Perrotin's avatar
Maxime Perrotin committed
983
984
985
986


actual_parameters
        :      '(' expression (',' expression)* ')'
987
988
        ->     ^(PARAMS expression+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
989
990
991
992
993


task
        :       cif?
                hyperlink?
994
                TASK task_body? end
995
996
        ->      ^(TASK cif? hyperlink? end? task_body?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007


task_body
        :       (assignement_statement (',' assignement_statement)*)
        ->      ^(TASK_BODY assignement_statement+)
                | (informal_text (',' informal_text)*)
        ->      ^(TASK_BODY informal_text+)
                | (forloop (',' forloop)*)
        ->      ^(TASK_BODY forloop+)
        ;

1008

Maxime Perrotin's avatar
Maxime Perrotin committed
1009
1010
// SDL extension - FOR loop in TASKs
forloop
1011
        :       FOR variable_id IN (range | variable) ':'
Maxime Perrotin's avatar
Maxime Perrotin committed
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
                transition?
                ENDFOR
        ->      ^(FOR variable_id variable? range? transition?);

range
        :       RANGE
                L_PAREN a=ground_expression
                (COMMA b=ground_expression)? (COMMA step=INT)?
                R_PAREN
        ->      ^(RANGE $a $b? $step?);

assignement_statement
        :       variable ':=' expression
        ->      ^(ASSIGN variable expression);


// Variable: covers eg. toto(5)(4)!titi(3)!tutu!yoyo
variable
1030
        :       postfix_expression
dbarbera's avatar
dbarbera committed
1031
1032
        |       ID                     ->  ^(VARIABLE ID);

Maxime Perrotin's avatar
Maxime Perrotin committed
1033
1034

field_selection
1035
        :       (('!' | DOT) field_name);
Maxime Perrotin's avatar
Maxime Perrotin committed
1036

1037

dbarbera's avatar
dbarbera committed
1038
expression
1039
1040
        :       binary_expression;

1041

1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
binary_expression
        :       binary_expression_0 ( IMPLIES^ binary_expression_0)*;
binary_expression_0
        :       binary_expression_1 (( (OR^ ELSE?) | XOR^ ) binary_expression_1)*;
binary_expression_1
        :       binary_expression_2 ( AND^ THEN? binary_expression_2)*;
binary_expression_2
        :       binary_expression_3 (( EQ^ | NEQ^ | GT^ | GE^ | LT^ | LE^ | IN^ ) binary_expression_3)*;
binary_expression_3
        :       binary_expression_4 (( PLUS^ | DASH^ | APPEND^ ) binary_expression_4)*;
binary_expression_4
        :       unary_expression (( ASTERISK^ | DIV^ | MOD^ | REM^ ) unary_expression)*;

1055

1056
unary_expression
1057
1058
        :       postfix_expression
        |       primary_expression
1059
        |       NOT^ unary_expression
1060
1061
        |       DASH unary_expression    -> ^(NEG unary_expression)
        |       CALL procedure_call_body -> ^(PROCEDURE_CALL procedure_call_body)
1062
1063
1064
1065
1066
        ;


postfix_expression
        :       (ID -> ^(PRIMARY ^(VARIABLE ID)))
1067
1068
1069
1070
                (   '(' params=expression_list ')'
                -> ^(CALL $postfix_expression ^(PARAMS $params))
                |   ('!' | DOT) field_name
                -> ^(SELECTOR $postfix_expression field_name)
1071
1072
1073
                )+
        ;

1074
1075
1076

primary_expression
        :       primary                       -> ^(PRIMARY primary)
1077
        |       '(' expression ')'            -> ^(PAREN expression)
1078
        |       conditional_expression
1079
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1080

Maxime Perrotin's avatar
Maxime Perrotin committed
1081
1082
1083
1084
//  primary covers most expressions with ASN.1 value notation
//  note that mkstring is the SDL operator transforming an element
//  into an array. The regular sytanx { hello(1) } is ambiguous because
//  it could be a record element with value 1 as well as an array with index 1
1085
primary
1086
        :       TRUE^
Maxime Perrotin's avatar
Maxime Perrotin committed
1087
        |       FALSE^
1088
        |       STRING
Maxime Perrotin's avatar
Maxime Perrotin committed
1089
1090
        |       PLUS_INFINITY^
        |       MINUS_INFINITY^
1091
1092
        |       INT^
        |       FLOAT^
1093
        |       ID ':' expression           -> ^(CHOICE ID expression)
dbarbera's avatar
dbarbera committed
1094
        |       ID                          -> ^(VARIABLE ID)
1095
1096
        |       '{' '}'                     -> ^(EMPTYSTR)
        |       '{'
Maxime Perrotin's avatar
Maxime Perrotin committed
1097
1098
                MANTISSA mant=INT COMMA
                BASE bas=INT COMMA
dbarbera's avatar
dbarbera committed
1099
                EXPONENT exp=INT
1100
1101
                '}'                         -> ^(FLOAT2 $mant $bas $exp)
        |       '{'
1102
1103
                named_value (COMMA named_value)*
                '}'                         -> ^(SEQUENCE named_value+)
1104
        |       '{'
1105
1106
                expression (COMMA expression)*
                '}'                         -> ^(SEQOF expression+)
Maxime Perrotin's avatar
Maxime Perrotin committed
1107
1108
        |       MKSTRING '(' expression (COMMA expression)* ')'
                                            -> ^(SEQOF expression+)
1109
        |       STATE^
Maxime Perrotin's avatar
Maxime Perrotin committed
1110
1111
        ;

1112

Maxime Perrotin's avatar
Maxime Perrotin committed
1113
informal_text
1114
        :        STRING
1115
1116
        ->       ^(INFORMAL_TEXT STRING)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1117
1118
1119


// { a 5 } (SEQUENCE field value)
1120
named_value
1121
1122
        :       ID expression
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1123

Alexandre Esteves's avatar
Alexandre Esteves committed
1124
/*
Maxime Perrotin's avatar
Maxime Perrotin committed
1125
1126
1127
1128
primary_params
        :      '(' expression_list ')'
        ->     ^(PARAMS expression_list)
               | '!' literal_id
1129
1130
        ->     ^(FIELD_NAME literal_id)
        ;
Alexandre Esteves's avatar
Alexandre Esteves committed
1131
*/
Maxime Perrotin's avatar
Maxime Perrotin committed
1132

dbarbera's avatar
dbarbera committed
1133
/* All cases are covered by the ground primary
Maxime Perrotin's avatar
Maxime Perrotin committed
1134
1135
1136
1137
1138
   above (Except structure primary, but we favour ASN.1 notation)
extended_primary
        :       synonym         |
                indexed_primary |
                field_primary   |
1139
1140
                structure_primary
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1141
1142
1143
1144
*/


indexed_primary
1145
1146
        :       primary '(' expression_list ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1147
1148
1149


field_primary
1150
1151
        :       primary field_selection
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1152
1153
1154


structure_primary
1155
1156
        :       '(.' expression_list '.)'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1157
1158
1159
// Removed "qualifier" from the standard
// (to be put later, but never used in practice)

Alexandre Esteves's avatar
Alexandre Esteves committed
1160
/*
Maxime Perrotin's avatar
Maxime Perrotin committed
1161
active_expression
1162
1163
        :       active_primary
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1164
1165
1166
1167
1168
1169
1170
1171


active_primary
        :       variable_access
                | operator_application
                | conditional_expression
                | imperative_operator
                | '(' active_expression ')'
1172
1173
                | 'ERROR'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1174
1175
1176
1177
1178
1179
1180
1181
1182
   // active_extended_primary removed because not defined in the standard


imperative_operator
        :       now_expression
                | import_expression
                | pid_expression
                | view_expression
                | timer_active_expression
1183
1184
                | anyvalue_expression
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1185
1186
1187


timer_active_expression
1188
1189
        :       ACTIVE '(' timer_id ('(' expression_list ')')? ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1190
1191
1192


anyvalue_expression
1193
1194
        :       ANY '(' sort ')'
        ;
Alexandre Esteves's avatar
Alexandre Esteves committed
1195
*/
Maxime Perrotin's avatar
Maxime Perrotin committed
1196
1197

sort    :       sort_id
1198
1199
1200
        ->      ^(SORT sort_id)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
1201

1202
1203
type_inst
        :       type_id
1204
1205
        ->      ^(TYPE_INSTANCE type_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1206

1207
1208
1209

syntype :       syntype_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1210

Alexandre Esteves's avatar
Alexandre Esteves committed
1211
/*
Maxime Perrotin's avatar
Maxime Perrotin committed
1212
import_expression
1213
1214
        :       IMPORT '(' remote_variable_id (',' destination)? ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1215
1216
1217


view_expression
1218
1219
        :       VIEW '(' view_id (',' pid_expression)? ')'
        ;
Alexandre Esteves's avatar
Alexandre Esteves committed
1220
*/
Maxime Perrotin's avatar
Maxime Perrotin committed
1221
1222

variable_access
1223
1224
        :       variable_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1225

1226
/*
Maxime Perrotin's avatar
Maxime Perrotin committed
1227
operator_application
1228
1229
        :       operator_id '('active_expression_list ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1230

1231

dbarbera's avatar
dbarbera committed
1232
active_expression_list
1233
1234
        :       active_expression (',' expression_list)?
        ;
Alexandre Esteves's avatar
Alexandre Esteves committed
1235
// 	| ground_expression ',' active_expression_list;   // Will not work (recursion)
Maxime Perrotin's avatar
Maxime Perrotin committed
1236

Alexandre Esteves's avatar
Alexandre Esteves committed
1237
*/
Maxime Perrotin's avatar
Maxime Perrotin committed
1238

1239
//synonym :       ID; // synonym_id | external_synonym;
Maxime Perrotin's avatar
Maxime Perrotin committed
1240
1241

external_synonym
1242
1243
        :       external_synonym_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1244
1245


1246
conditional_expression
Maxime Perrotin's avatar
Maxime Perrotin committed
1247
1248
1249
        :       IF ifexpr=expression
                THEN thenexpr=expression
                ELSE elseexpr=expression FI
1250
1251
        ->      ^(CONDITIONAL $ifexpr $thenexpr $elseexpr)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1252
1253


dbarbera's avatar
dbarbera committed
1254
expression_list
Maxime Perrotin's avatar
Maxime Perrotin committed
1255
        :       expression (',' expression)*