sdl92.g 40.9 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
        CONSTANTS;
        DCL;
Maxime Perrotin's avatar
Maxime Perrotin committed
43
        MONITOR;
dbarbera's avatar
dbarbera committed
44
45
        DECISION;
        DIGITS;
Maxime Perrotin's avatar
Maxime Perrotin committed
46
        ELSE;
dbarbera's avatar
dbarbera committed
47
48
49
50
        EMPTYSTR;
        ENDNEWTYPE;
        ENDSYNTYPE;
        ENDTEXT;
51
        ENTRY_POINT;
dbarbera's avatar
dbarbera committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
        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;
76
        LITERAL;
dbarbera's avatar
dbarbera committed
77
78
79
80
81
82
        NEG;
        NEWTYPE;
        NEXTSTATE;
        NUMBER_OF_INSTANCES;
        OCTSTR;
        OPEN_RANGE;
Maxime Perrotin's avatar
Maxime Perrotin committed
83
84
        OUTPUT;
        OUTPUT_BODY;
dbarbera's avatar
dbarbera committed
85
86
        PARAM;
        PARAMNAMES;
Maxime Perrotin's avatar
Maxime Perrotin committed
87
        PARAMS;
88
        PAREN;
89
        PFPAR;
90
        POINT;
Maxime Perrotin's avatar
Maxime Perrotin committed
91
        PRIMARY;
dbarbera's avatar
dbarbera committed
92
93
94
95
96
        PROCEDURE;
        PROCEDURE_CALL;
        PROCEDURE_NAME;
        PROCESS;
        PROVIDED;
Maxime Perrotin's avatar
Maxime Perrotin committed
97
        QUESTION;
dbarbera's avatar
dbarbera committed
98
99
100
        RANGE;
        RESET;
        RETURN;
101
        RETURNS;
Maxime Perrotin's avatar
Maxime Perrotin committed
102
        ROUTE;
dbarbera's avatar
dbarbera committed
103
        SAVE;
104
        SELECTOR;
dbarbera's avatar
dbarbera committed
105
106
107
108
109
110
111
        SEQOF;
        SEQUENCE;
        SET;
        SIGNAL;
        SIGNAL_LIST;
        SORT;
        STATE;
112
113
        STATE_AGGREGATION;
        STATE_PARTITION_CONNECTION;
dbarbera's avatar
dbarbera committed
114
115
116
        STATELIST;
        STIMULUS;
        STOP;
Maxime Perrotin's avatar
Maxime Perrotin committed
117
        STOPIF;
dbarbera's avatar
dbarbera committed
118
        STRING;
119
        STRUCT;
120
121
        SYNONYM;
        SYNONYM_LIST;
dbarbera's avatar
dbarbera committed
122
123
124
125
126
127
128
129
130
131
132
133
        SYNTYPE;
        SYSTEM;
        TASK;
        TASK_BODY;
        TERMINATOR;
        TEXT;
        TEXTAREA;
        TEXTAREA_CONTENT;
        THEN;
        TIMER;
        TO;
        TRANSITION;
134
        TYPE_INSTANCE;
dbarbera's avatar
dbarbera committed
135
136
137
138
139
140
        USE;
        VALUE;
        VARIABLE;
        VARIABLES;
        VIA;
        VIAPATH;
141
142
        INPUT_EXPRESSION;
        OUTPUT_EXPRESSION;
Maxime Perrotin's avatar
Maxime Perrotin committed
143
144
145
146
147
148
149
150
151
}


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


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


use_clause
        :       use_asn1?
166
167
168
                USE package_name
                ('/' def_selection_list )?
                end
169
170
171
        ->      ^(USE use_asn1? end? package_name def_selection_list?)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
172

173
174
175
176
/*
    In USE clause: USE package/X, Y, Z;
*/
def_selection_list
177
178
179
        :       ID (','! ID)*
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
180
181
182
183
184
185

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

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


channel
        :       CHANNEL channel_id
                route+
                ENDCHANNEL end
206
207
        ->      ^(CHANNEL channel_id route+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
208
209
210
211


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


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


/* 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
233
234
                | process_definition
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
235

236
237
238
// 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
239
signalroute
240
241
242
        :       SIGNALROUTE route_id end?
                route*
        ->      ^(SIGNALROUTE route_id route*)
243
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
244
245
246
247


connection
        :       CONNECT channel_id AND route_id end
248
249
        ->      ^(CONNECTION channel_id route_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
250
251


252
253
254
255
256
257
258
259
/* 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
260
process_definition
261
        :       cif?
Maxime Perrotin's avatar
Maxime Perrotin committed
262
                PROCESS t=TYPE? process_id
263
                number_of_instances? (':' type_inst)? REFERENCED? a=end
264
                pfpar?
265
                (text_area | procedure | (composite_state_preamble) =>composite_state)*
Maxime Perrotin's avatar
Maxime Perrotin committed
266
                processBody? ENDPROCESS? TYPE? process_id?
267
268
                end?
        ->      ^(PROCESS cif? process_id number_of_instances? type_inst?
Maxime Perrotin's avatar
Maxime Perrotin committed
269
                $t? REFERENCED? $a? pfpar? text_area* procedure*
270
                composite_state* processBody?)
271
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
272

273

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

282
283
284

parameters_of_sort
        :       variable_id (',' variable_id)* sort
285
286
        ->      ^(PARAM variable_id+ sort)
        ;
287

Maxime Perrotin's avatar
Maxime Perrotin committed
288

289
// procedure
290
291
// 2021-03 Added EXPORTED and REFEERENCED keywords
// needed to declare a synchronous provided interface at system level
Maxime Perrotin's avatar
Maxime Perrotin committed
292
293
procedure
        :       cif?
294
                EXPORTED? PROCEDURE procedure_id (e1=end | SEMI)
Maxime Perrotin's avatar
Maxime Perrotin committed
295
                fpar?
296
                res=procedure_result?
Maxime Perrotin's avatar
Maxime Perrotin committed
297
                (text_area | procedure)*
298
299
                ((processBody? ENDPROCEDURE procedure_id?)
                 | EXTERNAL | REFERENCED)
300
                e2=end
301
        ->      ^(PROCEDURE cif? procedure_id $e1? $e2? fpar? $res?
302
                text_area* procedure* processBody? EXTERNAL? EXPORTED? REFERENCED?)
303
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
304

305
306
307
308
// Procedure result / optional return type
procedure_result
        :       ('->' | RETURNS)
                variable_id?
309
                sort end?
310
311
        ->      ^(RETURNS variable_id? sort)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
312
313
314
315
316

// Procedure formal parameters
fpar
        :       FPAR formal_variable_param
                (',' formal_variable_param)*
317
                end
318
319
        ->      ^(FPAR formal_variable_param+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
320
321
322


formal_variable_param
323
        :       (INOUT | IN | OUT)?
Maxime Perrotin's avatar
Maxime Perrotin committed
324
                variable_id (',' variable_id)* sort
325
326
        ->      ^(PARAM INOUT? IN? OUT? variable_id+ sort)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
327
328
329
330
331
332
333


// text_area: TODO add operator description in content
text_area
        :       cif
                content?
                cif_end_text
334
335
        ->      ^(TEXTAREA cif content? cif_end_text)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
336
337
338
339
340
341


// Text areas can contain textual procedures, FPAR declarations,
// and variable or timer declarations
content
        :        (procedure
342
343
                 | use_clause
                 | signal_declaration
Maxime Perrotin's avatar
Maxime Perrotin committed
344
                 | fpar
345
                 | res=procedure_result
Maxime Perrotin's avatar
Maxime Perrotin committed
346
                 | timer_declaration
347
348
                 | syntype_definition
                 | newtype_definition
349
                 | variable_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
350
                 | monitor_definition
351
                 | synonym_definition)*
352
        ->       ^(TEXTAREA_CONTENT fpar* $res? procedure* variable_definition*
Maxime Perrotin's avatar
Maxime Perrotin committed
353
354
355
                   monitor_definition* syntype_definition* newtype_definition*
                   timer_declaration* signal_declaration* use_clause*
                   synonym_definition*)
356
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
357
358
359
360
361
362


timer_declaration
        :       TIMER timer_id
                (',' timer_id)*
                end
363
364
365
        ->      ^(TIMER timer_id+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
366

367
syntype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
368
369
370
        :       SYNTYPE syntype_name '=' parent_sort
                (CONSTANTS (range_condition (',' range_condition)* ))?
                ENDSYNTYPE syntype_name? end
371
372
373
        ->      ^(SYNTYPE syntype_name parent_sort range_condition*)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
374
375

syntype_name
376
377
378
        :       sort
        ;

379
380

parent_sort
381
382
383
        :       sort
        ;

384
385

newtype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
386
387
        :       NEWTYPE type_name (array_definition|structure_definition)?
                ENDNEWTYPE type_name? end
388
389
        ->      ^(NEWTYPE type_name array_definition* structure_definition*)
        ;
390
391
392


type_name
393
394
395
        :       sort
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
396

397
array_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
398
        :       ARRAY '(' sort ',' sort ')'
399
400
401
        ->      ^(ARRAY sort sort)
        ;

402
403

structure_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
404
        :       STRUCT field_list end
405
406
407
        ->      ^(STRUCT field_list)
        ;

408
409

field_list
Maxime Perrotin's avatar
Maxime Perrotin committed
410
        :       field_definition (end field_definition)*
411
412
413
        ->      ^(FIELDS field_definition+)
        ;

414
415

field_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
416
        :       field_name (',' field_name)* sort
417
418
419
        ->      ^(FIELD field_name+ sort)
        ;

420

Maxime Perrotin's avatar
Maxime Perrotin committed
421
422
423
424
variable_definition
        :       DCL variables_of_sort
                (',' variables_of_sort)*
                end
425
426
427
        ->      ^(DCL variables_of_sort+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
428
429
430
431
432
433
434
435
/* Monitors are an extension used when creating observers for model checking */
monitor_definition
        :       MONITOR variables_of_sort
                (',' variables_of_sort)*
                end
        ->      ^(MONITOR variables_of_sort+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
436

Maxime Perrotin's avatar
Maxime Perrotin committed
437
synonym_definition
438
439
440
        :       internal_synonym_definition
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
441

442
internal_synonym_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
443
444
        :       SYNONYM synonym_definition_item (',' synonym_definition_item)*
                end
445
446
447
        ->      ^(SYNONYM_LIST synonym_definition_item+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
448

449
synonym_definition_item
Maxime Perrotin's avatar
Maxime Perrotin committed
450
        :       sort sort '=' ground_expression
451
452
453
        ->      ^(SYNONYM sort sort ground_expression)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
454
455
456

variables_of_sort
        :       variable_id (',' variable_id)* sort (':=' ground_expression)?
457
458
        ->      ^(VARIABLES variable_id+ sort ground_expression?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
459
460
461
462


ground_expression
        :       expression
463
464
        ->      ^(GROUND expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
465
466
467
468


number_of_instances
        :       '(' initial_number=INT ',' maximum_number=INT ')'
469
470
        ->      ^(NUMBER_OF_INSTANCES $initial_number $maximum_number)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
471
472
473


processBody
474
475
        :       start? (state | floating_label)*
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
476
477
478
479
480


start
        :       cif?
                hyperlink?
481
                START name=state_entry_point_name? end
Maxime Perrotin's avatar
Maxime Perrotin committed
482
                transition?
483
484
        ->      ^(START cif? hyperlink? $name? end? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
485
486
487
488
489
490
491
492
493


floating_label
        :       cif?
                hyperlink?
                CONNECTION connector_name ':'
                transition?
                cif_end_label?
                ENDCONNECTION SEMI
494
495
        ->      ^(FLOATING_LABEL cif? hyperlink? connector_name transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
496

497
// state is either a full state definition, or a state instance
Maxime Perrotin's avatar
Maxime Perrotin committed
498
state
499
500
501
502
        : state_definition
          | state_instance
        ;

503
// the "via" part is needed to allow the graphical merge with a nextstate
504
state_definition
505
        :       cif?
Maxime Perrotin's avatar
Maxime Perrotin committed
506
                hyperlink?
507
                STATE statelist via? (e=end | SEMI)
Maxime Perrotin's avatar
Maxime Perrotin committed
508
509
                (state_part)*
                ENDSTATE statename? f=end
510
        ->      ^(STATE cif? hyperlink? $e? statelist via? state_part*)
511
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
512
513


514
515
516
state_instance
        :       cif?
                hyperlink?
517
518
                STATE statename ':' type_inst via? (e=end | SEMI)
                (state_part)*
519
                ENDSTATE statename? f=end
520
        ->      ^(STATE cif? hyperlink? $e? statename via? type_inst state_part*)
521
522
523
        ;


Maxime Perrotin's avatar
Maxime Perrotin committed
524
525
statelist
        :       ((statename)(',' statename)*)
526
        ->      ^(STATELIST statename+)
Maxime Perrotin's avatar
Maxime Perrotin committed
527
                | ASTERISK exception_state?
528
529
        ->      ^(ASTERISK exception_state?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
530
531
532


exception_state
533
        :       '(' statename (',' statename)* ')'
534
535
        ->      statename+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
536
537


538
// 11.11 State Machine and Composite State (SDL2000)
539
composite_state
540
541
542
543
        :       composite_state_graph
                | state_aggregation
        ;

544
545
546
547
548
// used for syntactic predicate
composite_state_preamble
        :       STATE AGGREGATION? statename end
                SUBSTRUCTURE
        ;
549
550

composite_state_graph
551
552
        :       STATE statename e=end
                SUBSTRUCTURE
553
                connection_points*
554
555
                body=composite_state_body
                ENDSUBSTRUCTURE statename? f=end
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
        ->      ^(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
581
        :       (state_partitioning | state_partition_connection)*
582
                state*
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
        ;


// 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?)
        ;
611
612


613
// 11.11.1 and 11.11.2 Composite State (SDL2000)
614
connection_points
615
616
617
        :       IN state_entry_exit_points end
        ->      ^(IN state_entry_exit_points end?)
                | OUT state_entry_exit_points end
618
619
        ->      ^(OUT state_entry_exit_points end?)
        ;
620
621


622
// 11.11.1 and 11.11.2 Composite State (SDL2000)
623
624
state_entry_exit_points
        :       '(' statename (',' statename)* ')'
625
626
        ->      statename+
        ;
627
628


629
// 11.11.1 Composite State graph content (SDL2000)
630
631
// 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.
632
composite_state_body
633
634
635
636
        :  (text_area
            | procedure
            | (composite_state_preamble) =>composite_state)*
           start* (state | floating_label)*
637
           EOF?
638
        ;
639
640


Maxime Perrotin's avatar
Maxime Perrotin committed
641
642
643
644
645
state_part
        :       input_part
                //| priority_input        // Not supported
                | save_part               // Not supported in openGEODE
                | spontaneous_transition
646
                | continuous_signal
647
648
                | connect_part
        ;
649
650
651
652


// connect part is used to connect nested state exit points to a transition
connect_part
Maxime Perrotin's avatar
Maxime Perrotin committed
653
654
655
656
        :       cif?
                hyperlink?
                CONNECT connect_list? end
                transition?
657
658
        ->      ^(CONNECT cif? hyperlink? connect_list? end? transition?)
        ;
659
660
661
662
663


connect_list
        :       state_exit_point_name (',' state_exit_point_name)*
                -> state_exit_point_name+
664
665
                | ASTERISK
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
666
667
668
669
670
671
672
673


spontaneous_transition
        :       cif?
                hyperlink?
                INPUT NONE end
                enabling_condition?
                transition
674
675
        ->      ^(INPUT_NONE cif? hyperlink? transition)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
676
677
678
679


enabling_condition
        :       PROVIDED expression end
680
681
        ->      ^(PROVIDED expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
682
683
684


continuous_signal
685
686
687
688
        :       cif?
                hyperlink?
                PROVIDED expression e=end
                (PRIORITY p=INT end)?
689
690
                transition?
        ->      ^(PROVIDED expression cif? hyperlink? $p? $e? transition?)
691
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
692
693
694
695
696


save_part
        :       SAVE save_list
                end
697
698
        ->      ^(SAVE save_list)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
699
700
701
702


save_list
        :       signal_list
703
704
                | asterisk_save_list
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
705
706
707
708
709
710
711
712


asterisk_save_list
        :       ASTERISK;


signal_list
        :       signal_item (',' signal_item)*
713
714
        ->      ^(SIGNAL_LIST signal_item+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
715
716
717
718
719
720
721
722
723
724
725



// 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
726
/*   Not considered for the moment
Maxime Perrotin's avatar
Maxime Perrotin committed
727
728
     (irrelevant in the scope of the generation of code for a single process)
priority_input
dbarbera's avatar
dbarbera committed
729
        :       PRIORITY INPUT priority_input_list end transition;
Maxime Perrotin's avatar
Maxime Perrotin committed
730
731
732
733
734
735
736
737
738
739
740
741
742
743


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
744
745
                INPUT inputlist end
                enabling_condition?
Maxime Perrotin's avatar
Maxime Perrotin committed
746
747
                transition?
        ->      ^(INPUT cif? hyperlink? end?
748
749
                inputlist enabling_condition? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
750
751
752
753
754
755
756


// asterisk means: all signals not excplicitely specified
// (semantic is different from asterisk state)
inputlist
        :       ASTERISK
                | (stimulus (',' stimulus)*)
757
758
        ->      ^(INPUTLIST stimulus+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
759
760
761


stimulus
762
763
        :       stimulus_id input_params?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
764
765
766
767


input_params
        :       L_PAREN variable_id (',' variable_id)* R_PAREN
768
769
        ->      ^(PARAMS variable_id+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
770
771
772
773
774
775


transition
        :       action+ label? terminator_statement?
        ->      ^(TRANSITION action+ label? terminator_statement?)
                | terminator_statement
776
777
        ->      ^(TRANSITION terminator_statement)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
778
779
780
781
782
783
784
785
786
787
788
789
790


action
        :       label?
                (task
                | task_body
                | output
                | create_request
                | decision
                | transition_option
                | set_timer
                | reset_timer
                | export     // Not supported in OpenGEODE
791
792
793
                | procedure_call)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
794
795
796
797
798

export
        :       EXPORT
                L_PAREN variable_id (COMMA variable_id)* R_PAREN
                end
799
800
801
        ->      ^(EXPORT variable_id+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
802
803
804

/*
remote_procedure_call
dbarbera's avatar
dbarbera committed
805
        :       CALL remote_procedure_call_body;
Maxime Perrotin's avatar
Maxime Perrotin committed
806
807

remote_procedure_call_body
dbarbera's avatar
dbarbera committed
808
        :       remote_procedure_id actual_parameters? (TO destination)?;
Maxime Perrotin's avatar
Maxime Perrotin committed
809
810
811
812
813
*/
procedure_call
        :       cif?
                hyperlink?
                CALL procedure_call_body end
814
815
        ->      ^(PROCEDURE_CALL cif? hyperlink? end? procedure_call_body)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
816
817
818


procedure_call_body
dbarbera's avatar
dbarbera committed
819
        :       procedure_id actual_parameters?
820
821
        ->      ^(OUTPUT_BODY procedure_id actual_parameters?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
822
823
824
825
826


set_timer
        :       SET set_statement (COMMA set_statement)*
                end
827
828
        ->      set_statement+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
829
830
831
832


set_statement
        :       L_PAREN (expression COMMA)? timer_id R_PAREN
833
834
        ->      ^(SET expression? timer_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
835
836
837
838
839
840
        // ('('expression_list')')? ')'; (removed because of non-LL(*) problem)


reset_timer
        :       RESET reset_statement (',' reset_statement)*
                end
841
842
        ->      reset_statement+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
843
844
845
846


reset_statement
        :       timer_id ('(' expression_list ')')?
847
848
        ->      ^(RESET timer_id expression_list?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
849
850
851
852
853
854
855


transition_option
        :       ALTERNATIVE alternative_question e=end
                answer_part
                alternative_part
                ENDALTERNATIVE f=end
856
857
        ->      ^(ALTERNATIVE answer_part alternative_part)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
858
859
860
861
862
863


alternative_part
        :       (answer_part+ else_part?)
        ->      answer_part+ else_part?
                | else_part
864
865
        ->      else_part
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
866
867
868
869


alternative_question
        :       expression
870
871
                | informal_text
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
872
873
874
875
876
877
878
879
880
881


decision
        :       cif?
                hyperlink?
                DECISION question e=end
                answer_part?
                alternative_part?
                ENDDECISION f=end
        ->      ^(DECISION cif? hyperlink? $e? question
882
883
                answer_part? alternative_part?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
884
885
886
887
888
889


answer_part
        :       cif?
                hyperlink?
                L_PAREN answer R_PAREN ':' transition?
890
891
        ->      ^(ANSWER cif? hyperlink? answer transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
892
893
894
895


answer
        :       range_condition
896
897
                | informal_text
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
898
899
900
901
902
903


else_part
        :       cif?
                hyperlink?
                ELSE ':' transition?
904
905
        ->      ^(ELSE cif? hyperlink? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
906
907
908


question
909
910
        :       informal_text
                | expression
Maxime Perrotin's avatar
Maxime Perrotin committed
911
912
        ->      ^(QUESTION expression)
                | ANY
913
914
        ->      ^(ANY)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
915
916
917


range_condition
918
919
        :       (closed_range | open_range)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
920
921
922
923
                //(',' (closed_range|open_range))*;


closed_range
924
        :       a=expression ':' b=expression
925
926
        ->      ^(CLOSED_RANGE $a $b)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
927
928
929
930
931
932


open_range
        :       constant
        ->      constant
                | ( (EQ|NEQ|GT|LT|LE|GE) constant)
933
934
        ->      ^(OPEN_RANGE EQ? NEQ? GT? LT? LE? GE? constant)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
935
936
937
938


constant
        :       expression
939
940
        ->      ^(CONSTANT expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
941
942
943


create_request
dbarbera's avatar
dbarbera committed
944
        :       CREATE
Maxime Perrotin's avatar
Maxime Perrotin committed
945
946
947
                createbody
                actual_parameters?
                end
948
949
        ->      ^(CREATE createbody actual_parameters?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
950
951
952
953


createbody
        :       process_id
954
955
                | THIS
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
956
957
958
959
960
961


output
        :       cif?
                hyperlink?
                OUTPUT outputbody end
962
963
        ->      ^(OUTPUT cif? hyperlink? end? outputbody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
964
965
966


outputbody
967
        :       outputstmt (',' outputstmt)* to_part?
968
969
        ->      ^(OUTPUT_BODY outputstmt+ to_part?)
        ;
970
971
 //               via_part?
 //     -> (signal_id actual_parameters?)+ to_part? via_part?;
Maxime Perrotin's avatar
Maxime Perrotin committed
972
973
974


outputstmt
dbarbera's avatar
dbarbera committed
975
        :       signal_id
976
977
                actual_parameters?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
978

979
to_part
Maxime Perrotin's avatar
Maxime Perrotin committed
980
        :       (TO destination)
981
982
        ->      ^(TO destination)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
983

984
via_part
dbarbera's avatar
dbarbera committed
985
        :       VIA viabody
986
987
        ->      ^(VIA viabody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
988
989
990
991


// ambiguous in SDL92, added OR between ALL and via_path
viabody
dbarbera's avatar
dbarbera committed
992
        :       ALL
Maxime Perrotin's avatar
Maxime Perrotin committed
993
994
        ->      ^(ALL)
                | via_path
995
996
        ->      ^(VIAPATH via_path)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
997
998
999
1000
1001


destination
        :       pid_expression
                | process_id
1002
1003
                | THIS
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1004
1005
1006
1007


via_path
        :       via_path_element (',' via_path_element)*
1008
1009
        ->      via_path_element+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1010
1011
1012


via_path_element
1013
1014
        :       ID
        ; // signal_route_id | channel_id | gate_id;
Maxime Perrotin's avatar
Maxime Perrotin committed
1015
1016
1017
1018


actual_parameters
        :      '(' expression (',' expression)* ')'
1019
1020
        ->     ^(PARAMS expression+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1021
1022
1023
1024
1025


task
        :       cif?
                hyperlink?
1026
                TASK task_body? end
1027
1028
        ->      ^(TASK cif? hyperlink? end? task_body?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039


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

1040

Maxime Perrotin's avatar
Maxime Perrotin committed
1041
1042
// SDL extension - FOR loop in TASKs
forloop
1043
        :       FOR variable_id IN (range | variable) ':'
Maxime Perrotin's avatar
Maxime Perrotin committed
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
                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
1062
        :       postfix_expression
dbarbera's avatar
dbarbera committed
1063
1064
        |       ID                     ->  ^(VARIABLE ID);

Maxime Perrotin's avatar
Maxime Perrotin committed
1065
1066

field_selection
1067
        :       (('!' | DOT) field_name);
Maxime Perrotin's avatar
Maxime Perrotin committed
1068

1069

dbarbera's avatar
dbarbera committed
1070
expression
1071
1072
        :       binary_expression;

1073

1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
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)*;

1087

1088
unary_expression
1089
1090
        :       postfix_expression
        |       primary_expression
1091
        |       NOT^ unary_expression
1092
1093
        |       DASH unary_expression    -> ^(NEG unary_expression)
        |       CALL procedure_call_body -> ^(PROCEDURE_CALL procedure_call_body)
1094
1095
        |       input_expression            // used in observers
        |       output_expression           // used in observers
1096
1097
1098
1099
1100
        ;


postfix_expression
        :       (ID -> ^(PRIMARY ^(VARIABLE ID)))
1101
1102
1103
1104
                (   '(' params=expression_list ')'
                -> ^(CALL $postfix_expression ^(PARAMS $params))
                |   ('!' | DOT) field_name
                -> ^(SELECTOR $postfix_expression field_name)
1105
1106
1107
                )+
        ;

1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
//  input and output expression allow observers (for model checking) to
//  monitor the sending and receiving of messages with a nice syntax
//  (e.g. event = output msg from foo)
input_expression
        :       INPUT
                -> ^(INPUT_EXPRESSION)
                | INPUT (msg=ID)? (FROM src=ID)? TO dest=ID
                -> ^(INPUT_EXPRESSION $msg? ^(FROM $src)? ^(TO $dest))
        ;


output_expression
        :       OUTPUT
                -> ^(OUTPUT_EXPRESSION)
                | OUTPUT (msg=ID)? (FROM src=ID) (TO dest=ID)?
                -> ^(OUTPUT_EXPRESSION  $msg? ^(FROM $src) ^(TO $dest)?)
        ;
1125
1126
1127

primary_expression
        :       primary                       -> ^(PRIMARY primary)
1128
        |       '(' expression ')'            -> ^(PAREN expression)
1129
        |       conditional_expression
1130
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1131

Maxime Perrotin's avatar
Maxime Perrotin committed
1132
1133
1134
1135
//  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
1136
primary
1137
        :       TRUE^
Maxime Perrotin's avatar
Maxime Perrotin committed
1138
        |       FALSE^
1139
        |       STRING
Maxime Perrotin's avatar
Maxime Perrotin committed
1140
1141
        |       PLUS_INFINITY^
        |       MINUS_INFINITY^
1142
1143
        |       INT^
        |       FLOAT^
1144
        |       ID ':' expression           -> ^(CHOICE ID expression)
dbarbera's avatar
dbarbera committed
1145
        |       ID                          -> ^(VARIABLE ID)
1146
1147
        |       '{' '}'                     -> ^(EMPTYSTR)
        |       '{'
Maxime Perrotin's avatar
Maxime Perrotin committed
1148
1149
                MANTISSA mant=INT COMMA
                BASE bas=INT COMMA
dbarbera's avatar
dbarbera committed
1150
                EXPONENT exp=INT
1151
1152
                '}'                         -> ^(FLOAT2 $mant $bas $exp)
        |       '{'
1153
1154
                named_value (COMMA named_value)*
                '}'                         -> ^(SEQUENCE named_value+)
1155
        |       '{'
1156
1157
                expression (COMMA expression)*
                '}'                         -> ^(SEQOF expression+)
Maxime Perrotin's avatar
Maxime Perrotin committed
1158
1159
        |       MKSTRING '(' expression (COMMA expression)* ')'
                                            -> ^(SEQOF expression+)
1160
        |       STATE^
Maxime Perrotin's avatar
Maxime Perrotin committed
1161
1162
        ;

1163

Maxime Perrotin's avatar
Maxime Perrotin committed
1164
informal_text
1165
        :        STRING
1166
1167
        ->       ^(INFORMAL_TEXT STRING)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1168
1169
1170


// { a 5 } (SEQUENCE field value)
1171
named_value
1172
1173
        :       ID expression
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1174

Alexandre Esteves's avatar
Alexandre Esteves committed
1175
/*
Maxime Perrotin's avatar
Maxime Perrotin committed
1176
1177
1178
1179
primary_params
        :      '(' expression_list ')'
        ->     ^(PARAMS expression_list)
               | '!' literal_id
1180
1181
        ->     ^(FIELD_NAME literal_id)
        ;
Alexandre Esteves's avatar
Alexandre Esteves committed
1182
*/
Maxime Perrotin's avatar
Maxime Perrotin committed
1183

dbarbera's avatar
dbarbera committed
1184
/* All cases are covered by the ground primary
Maxime Perrotin's avatar
Maxime Perrotin committed
1185
1186
1187
1188
1189
   above (Except structure primary, but we favour ASN.1 notation)
extended_primary
        :       synonym         |
                indexed_primary |
                field_primary   |
1190
1191
                structure_primary
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1192
1193
1194
1195
*/


indexed_primary
1196
1197
        :       primary '(' expression_list ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1198
1199
1200


field_primary
1201
1202
        :       primary field_selection
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1203
1204
1205


structure_primary
1206
1207
        :       '(.' expression_list '.)'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1208
1209
1210
// Removed "qualifier" from the standard
// (to be put later, but never used in practice)

Alexandre Esteves's avatar
Alexandre Esteves committed
1211
/*
Maxime Perrotin's avatar
Maxime Perrotin committed
1212
active_expression
1213
1214
        :       active_primary
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1215
1216
1217
1218
1219
1220
1221
1222


active_primary
        :       variable_access
                | operator_application
                | conditional_expression
                | imperative_operator
                | '(' active_expression ')'
1223
1224
                | 'ERROR'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1225
1226
1227
1228
1229
1230
1231
1232
1233
   // active_extended_primary removed because not defined in the standard


imperative_operator
        :       now_expression
                | import_expression
                | pid_expression
                | view_expression
                | timer_active_expression
1234
1235
                | anyvalue_expression
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1236
1237
1238


timer_active_expression
1239
1240
        :       ACTIVE '(' timer_id ('(' expression_list ')')? ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1241
1242
1243


anyvalue_expression
1244
1245
        :       ANY '(' sort ')'
        ;
Alexandre Esteves's avatar
Alexandre Esteves committed
1246
*/
Maxime Perrotin's avatar
Maxime Perrotin committed
1247
1248

sort    :       sort_id
1249
1250
1251
        ->      ^(SORT sort_id)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
1252

1253
1254
type_inst
        :       type_id
1255
1256
        ->      ^(TYPE_INSTANCE type_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1257

1258
1259
1260

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

Alexandre Esteves's avatar
Alexandre Esteves committed
1262
/*
Maxime Perrotin's avatar
Maxime Perrotin committed
1263
import_expression
1264
1265
        :       IMPORT '(' remote_variable_id (',' destination)? ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1266
1267
1268


view_expression
1269
1270
        :       VIEW '(' view_id (',' pid_expression)? ')'
        ;
Alexandre Esteves's avatar
Alexandre Esteves committed
1271
*/
Maxime Perrotin's avatar
Maxime Perrotin committed
1272
1273

variable_access
1274
1275
        :       variable_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1276

1277
/*
Maxime Perrotin's avatar
Maxime Perrotin committed
1278
operator_application
1279
1280
        :       operator_id '('active_expression_list ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1281

1282

dbarbera's avatar
dbarbera committed
1283
active_expression_list
1284
1285
        :       active_expression (',' expression_list)?
        ;
Alexandre Esteves's avatar
Alexandre Esteves committed
1286
// 	| ground_expression ',' active_expression_list;   // Will not work (recursion)
Maxime Perrotin's avatar
Maxime Perrotin committed
1287

Alexandre Esteves's avatar
Alexandre Esteves committed
1288
*/
Maxime Perrotin's avatar
Maxime Perrotin committed
1289

1290
//synonym :       ID; // synonym_id | external_synonym;
Maxime Perrotin's avatar
Maxime Perrotin committed
1291
1292

external_synonym
1293
1294
        :       external_synonym_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1295
1296


1297
conditional_expression
Maxime Perrotin's avatar
Maxime Perrotin committed
1298
1299
1300
        :       IF ifexpr=expression
                THEN thenexpr=expression
                ELSE elseexpr=expression FI
1301
1302
        ->      ^(CONDITIONAL $ifexpr $thenexpr $elseexpr)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1303
1304


dbarbera's avatar