sdl92.g 37.6 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
15
16
17
18
19
20
21
22
*/

grammar sdl92;

options {
    language=Python;
    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;
Maxime Perrotin's avatar
Maxime Perrotin committed
100
        ROUTE;
dbarbera's avatar
dbarbera committed
101
        SAVE;
102
        SELECTOR;
dbarbera's avatar
dbarbera committed
103
104
105
106
107
108
109
        SEQOF;
        SEQUENCE;
        SET;
        SIGNAL;
        SIGNAL_LIST;
        SORT;
        STATE;
110
111
        STATE_AGGREGATION;
        STATE_PARTITION_CONNECTION;
dbarbera's avatar
dbarbera committed
112
113
114
        STATELIST;
        STIMULUS;
        STOP;
Maxime Perrotin's avatar
Maxime Perrotin committed
115
        STOPIF;
dbarbera's avatar
dbarbera committed
116
        STRING;
117
        STRUCT;
118
119
        SYNONYM;
        SYNONYM_LIST;
dbarbera's avatar
dbarbera committed
120
121
122
123
124
125
126
127
128
129
130
131
        SYNTYPE;
        SYSTEM;
        TASK;
        TASK_BODY;
        TERMINATOR;
        TEXT;
        TEXTAREA;
        TEXTAREA_CONTENT;
        THEN;
        TIMER;
        TO;
        TRANSITION;
132
        TYPE_INSTANCE;
dbarbera's avatar
dbarbera committed
133
134
135
136
137
138
        USE;
        VALUE;
        VARIABLE;
        VARIABLES;
        VIA;
        VIAPATH;
Maxime Perrotin's avatar
Maxime Perrotin committed
139
140
141
142
143
144
145
146
147
}


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


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


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

Maxime Perrotin's avatar
Maxime Perrotin committed
168

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

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

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

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


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


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


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


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


signalroute
        :       SIGNALROUTE route_id
                route+
236
237
        ->      ^(SIGNALROUTE route_id route+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
238
239
240
241


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


process_definition
        :       PROCESS process_id number_of_instances? REFERENCED end
        ->      ^(PROCESS process_id number_of_instances? REFERENCED)
249
                | cif? PROCESS process_id number_of_instances? end
250
                pfpar?
251
                (text_area | procedure | composite_state)*
Maxime Perrotin's avatar
Maxime Perrotin committed
252
253
                processBody? ENDPROCESS process_id?
                end
254
255
256
257
258
259
        ->      ^(PROCESS cif? process_id number_of_instances? end?
                pfpar? text_area* procedure* composite_state* processBody?)
                | cif? PROCESS process_id number_of_instances? (':' type_inst)?
                end
        ->      ^(PROCESS cif? process_id type_inst? number_of_instances? end?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
260

261

262
263
264
265
266
// Process formal parameters
pfpar
        :       FPAR parameters_of_sort
                (',' parameters_of_sort)*
                end
267
268
269
        ->      ^(PFPAR parameters_of_sort+)
        ;

270
271
272

parameters_of_sort
        :       variable_id (',' variable_id)* sort
273
274
        ->      ^(PARAM variable_id+ sort)
        ;
275

Maxime Perrotin's avatar
Maxime Perrotin committed
276

277
278
// procedure: missing the RETURNS statement
// (TODO - but check new SDL2000 syntax that has no RETURNS token)
Maxime Perrotin's avatar
Maxime Perrotin committed
279
280
procedure
        :       cif?
281
                PROCEDURE procedure_id e1=end
Maxime Perrotin's avatar
Maxime Perrotin committed
282
283
284
                fpar?
                (text_area | procedure)*
                ((processBody? ENDPROCEDURE procedure_id?) | EXTERNAL)
285
286
                e2=end
        ->      ^(PROCEDURE cif? procedure_id $e1? $e2? fpar?
287
288
                text_area* procedure* processBody? EXTERNAL?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
289
290
291
292
293
294
295


// Procedure formal parameters
fpar
        :       FPAR formal_variable_param
                (',' formal_variable_param)*
                end
296
297
        ->      ^(FPAR formal_variable_param+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
298
299
300


formal_variable_param
301
        :       (INOUT | IN | OUT)?
Maxime Perrotin's avatar
Maxime Perrotin committed
302
                variable_id (',' variable_id)* sort
303
304
        ->      ^(PARAM INOUT? IN? OUT? variable_id+ sort)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
305
306
307
308
309
310
311


// text_area: TODO add operator description in content
text_area
        :       cif
                content?
                cif_end_text
312
313
        ->      ^(TEXTAREA cif content? cif_end_text)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
314
315
316
317
318
319


// Text areas can contain textual procedures, FPAR declarations,
// and variable or timer declarations
content
        :        (procedure
320
321
                 | use_clause
                 | signal_declaration
Maxime Perrotin's avatar
Maxime Perrotin committed
322
323
                 | fpar
                 | timer_declaration
324
325
                 | syntype_definition
                 | newtype_definition
326
327
                 | variable_definition
                 | synonym_definition)*
Maxime Perrotin's avatar
Maxime Perrotin committed
328
329
        ->       ^(TEXTAREA_CONTENT fpar* procedure* variable_definition*
                   syntype_definition* newtype_definition* timer_declaration*
330
331
                   signal_declaration* use_clause* synonym_definition*)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
332
333
334
335
336
337


timer_declaration
        :       TIMER timer_id
                (',' timer_id)*
                end
338
339
340
        ->      ^(TIMER timer_id+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
341

342
syntype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
343
344
345
        :       SYNTYPE syntype_name '=' parent_sort
                (CONSTANTS (range_condition (',' range_condition)* ))?
                ENDSYNTYPE syntype_name? end
346
347
348
        ->      ^(SYNTYPE syntype_name parent_sort range_condition*)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
349
350

syntype_name
351
352
353
        :       sort
        ;

354
355

parent_sort
356
357
358
        :       sort
        ;

359
360

newtype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
361
362
        :       NEWTYPE type_name (array_definition|structure_definition)?
                ENDNEWTYPE type_name? end
363
364
        ->      ^(NEWTYPE type_name array_definition* structure_definition*)
        ;
365
366
367


type_name
368
369
370
        :       sort
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
371

372
array_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
373
        :       ARRAY '(' sort ',' sort ')'
374
375
376
        ->      ^(ARRAY sort sort)
        ;

377
378

structure_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
379
        :       STRUCT field_list end
380
381
382
        ->      ^(STRUCT field_list)
        ;

383
384

field_list
Maxime Perrotin's avatar
Maxime Perrotin committed
385
        :       field_definition (end field_definition)*
386
387
388
        ->      ^(FIELDS field_definition+)
        ;

389
390

field_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
391
        :       field_name (',' field_name)* sort
392
393
394
        ->      ^(FIELD field_name+ sort)
        ;

395

Maxime Perrotin's avatar
Maxime Perrotin committed
396
397
398
399
variable_definition
        :       DCL variables_of_sort
                (',' variables_of_sort)*
                end
400
401
402
        ->      ^(DCL variables_of_sort+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
403

Maxime Perrotin's avatar
Maxime Perrotin committed
404
synonym_definition
405
406
407
        :       internal_synonym_definition
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
408

409
internal_synonym_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
410
411
        :       SYNONYM synonym_definition_item (',' synonym_definition_item)*
                end
412
413
414
        ->      ^(SYNONYM_LIST synonym_definition_item+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
415

416
synonym_definition_item
Maxime Perrotin's avatar
Maxime Perrotin committed
417
        :       sort sort '=' ground_expression
418
419
420
        ->      ^(SYNONYM sort sort ground_expression)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
421
422
423

variables_of_sort
        :       variable_id (',' variable_id)* sort (':=' ground_expression)?
424
425
        ->      ^(VARIABLES variable_id+ sort ground_expression?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
426
427
428
429


ground_expression
        :       expression
430
431
        ->      ^(GROUND expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
432
433
434
435


number_of_instances
        :       '(' initial_number=INT ',' maximum_number=INT ')'
436
437
        ->      ^(NUMBER_OF_INSTANCES $initial_number $maximum_number)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
438
439
440


processBody
441
442
        :       start? (state | floating_label)*
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
443
444
445
446
447


start
        :       cif?
                hyperlink?
448
                START name=state_entry_point_name? end
Maxime Perrotin's avatar
Maxime Perrotin committed
449
                transition?
450
451
        ->      ^(START cif? hyperlink? $name? end? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
452
453
454
455
456
457
458
459
460


floating_label
        :       cif?
                hyperlink?
                CONNECTION connector_name ':'
                transition?
                cif_end_label?
                ENDCONNECTION SEMI
461
462
        ->      ^(FLOATING_LABEL cif? hyperlink? connector_name transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
463
464
465


state
466
        :       cif?
Maxime Perrotin's avatar
Maxime Perrotin committed
467
468
469
470
                hyperlink?
                STATE statelist e=end
                (state_part)*
                ENDSTATE statename? f=end
471
472
        ->      ^(STATE cif? hyperlink? $e? statelist state_part*)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
473
474
475
476


statelist
        :       ((statename)(',' statename)*)
477
        ->      ^(STATELIST statename+)
Maxime Perrotin's avatar
Maxime Perrotin committed
478
                | ASTERISK exception_state?
479
480
        ->      ^(ASTERISK exception_state?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
481
482
483


exception_state
484
        :       '(' statename (',' statename)* ')'
485
486
        ->      statename+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
487
488


489
// 11.11 State Machine and Composite State (SDL2000)
490
composite_state
491
492
493
494
495
496
        :       composite_state_graph
                | state_aggregation
        ;


composite_state_graph
497
498
        :       STATE statename e=end
                SUBSTRUCTURE
499
                connection_points*
500
501
                body=composite_state_body
                ENDSUBSTRUCTURE statename? f=end
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
        ->      ^(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
        :       (state_partitioning | state_partition_connection)+
        ;


// 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?)
        ;
556
557


558
// 11.11.1 and 11.11.2 Composite State (SDL2000)
559
connection_points
560
561
562
        :       IN state_entry_exit_points end
        ->      ^(IN state_entry_exit_points end?)
                | OUT state_entry_exit_points end
563
564
        ->      ^(OUT state_entry_exit_points end?)
        ;
565
566


567
// 11.11.1 and 11.11.2 Composite State (SDL2000)
568
569
state_entry_exit_points
        :       '(' statename (',' statename)* ')'
570
571
        ->      statename+
        ;
572
573


574
// 11.11.1 Composite State graph content (SDL2000)
575
576
composite_state_body
        :       (text_area | procedure | composite_state)*
577
578
                start* (state | floating_label)*
        ;
579
580


Maxime Perrotin's avatar
Maxime Perrotin committed
581
582
583
584
585
state_part
        :       input_part
                //| priority_input        // Not supported
                | save_part               // Not supported in openGEODE
                | spontaneous_transition
586
                | continuous_signal       // Not supoorted in openGEODE
587
588
                | connect_part
        ;
589
590
591
592


// connect part is used to connect nested state exit points to a transition
connect_part
Maxime Perrotin's avatar
Maxime Perrotin committed
593
594
595
596
        :       cif?
                hyperlink?
                CONNECT connect_list? end
                transition?
597
598
        ->      ^(CONNECT cif? hyperlink? connect_list? end? transition?)
        ;
599
600
601
602
603


connect_list
        :       state_exit_point_name (',' state_exit_point_name)*
                -> state_exit_point_name+
604
605
                | ASTERISK
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
606
607
608
609
610
611
612
613


spontaneous_transition
        :       cif?
                hyperlink?
                INPUT NONE end
                enabling_condition?
                transition
614
615
        ->      ^(INPUT_NONE cif? hyperlink? transition)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
616
617
618
619


enabling_condition
        :       PROVIDED expression end
620
621
        ->      ^(PROVIDED expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
622
623
624


continuous_signal
dbarbera's avatar
dbarbera committed
625
        :       PROVIDED expression end
626
                (PRIORITY integer_literal_name=INT end)?
Maxime Perrotin's avatar
Maxime Perrotin committed
627
                transition
628
629
        ->      ^(PROVIDED expression $integer_literal_name? transition)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
630
631
632
633
634


save_part
        :       SAVE save_list
                end
635
636
        ->      ^(SAVE save_list)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
637
638
639
640


save_list
        :       signal_list
641
642
                | asterisk_save_list
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
643
644
645
646
647
648
649
650


asterisk_save_list
        :       ASTERISK;


signal_list
        :       signal_item (',' signal_item)*
651
652
        ->      ^(SIGNAL_LIST signal_item+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
653
654
655
656
657
658
659
660
661
662
663



// 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
664
/*   Not considered for the moment
Maxime Perrotin's avatar
Maxime Perrotin committed
665
666
     (irrelevant in the scope of the generation of code for a single process)
priority_input
dbarbera's avatar
dbarbera committed
667
        :       PRIORITY INPUT priority_input_list end transition;
Maxime Perrotin's avatar
Maxime Perrotin committed
668
669
670
671
672
673
674
675
676
677
678
679
680
681


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
682
683
                INPUT inputlist end
                enabling_condition?
Maxime Perrotin's avatar
Maxime Perrotin committed
684
685
                transition?
        ->      ^(INPUT cif? hyperlink? end?
686
687
                inputlist enabling_condition? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
688
689
690
691
692
693
694


// asterisk means: all signals not excplicitely specified
// (semantic is different from asterisk state)
inputlist
        :       ASTERISK
                | (stimulus (',' stimulus)*)
695
696
        ->      ^(INPUTLIST stimulus+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
697
698
699


stimulus
700
701
        :       stimulus_id input_params?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
702
703
704
705


input_params
        :       L_PAREN variable_id (',' variable_id)* R_PAREN
706
707
        ->      ^(PARAMS variable_id+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
708
709
710
711
712
713


transition
        :       action+ label? terminator_statement?
        ->      ^(TRANSITION action+ label? terminator_statement?)
                | terminator_statement
714
715
        ->      ^(TRANSITION terminator_statement)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
716
717
718
719
720
721
722
723
724
725
726
727
728


action
        :       label?
                (task
                | task_body
                | output
                | create_request
                | decision
                | transition_option
                | set_timer
                | reset_timer
                | export     // Not supported in OpenGEODE
729
730
731
                | procedure_call)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
732
733
734
735
736

export
        :       EXPORT
                L_PAREN variable_id (COMMA variable_id)* R_PAREN
                end
737
738
739
        ->      ^(EXPORT variable_id+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
740
741
742

/*
remote_procedure_call
dbarbera's avatar
dbarbera committed
743
        :       CALL remote_procedure_call_body;
Maxime Perrotin's avatar
Maxime Perrotin committed
744
745

remote_procedure_call_body
dbarbera's avatar
dbarbera committed
746
        :       remote_procedure_id actual_parameters? (TO destination)?;
Maxime Perrotin's avatar
Maxime Perrotin committed
747
748
749
750
751
*/
procedure_call
        :       cif?
                hyperlink?
                CALL procedure_call_body end
752
753
        ->      ^(PROCEDURE_CALL cif? hyperlink? end? procedure_call_body)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
754
755
756


procedure_call_body
dbarbera's avatar
dbarbera committed
757
        :       procedure_id actual_parameters?
758
759
        ->      ^(OUTPUT_BODY procedure_id actual_parameters?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
760
761
762
763
764


set_timer
        :       SET set_statement (COMMA set_statement)*
                end
765
766
        ->      set_statement+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
767
768
769
770


set_statement
        :       L_PAREN (expression COMMA)? timer_id R_PAREN
771
772
        ->      ^(SET expression? timer_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
773
774
775
776
777
778
        // ('('expression_list')')? ')'; (removed because of non-LL(*) problem)


reset_timer
        :       RESET reset_statement (',' reset_statement)*
                end
779
780
        ->      reset_statement+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
781
782
783
784


reset_statement
        :       timer_id ('(' expression_list ')')?
785
786
        ->      ^(RESET timer_id expression_list?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
787
788
789
790
791
792
793


transition_option
        :       ALTERNATIVE alternative_question e=end
                answer_part
                alternative_part
                ENDALTERNATIVE f=end
794
795
        ->      ^(ALTERNATIVE answer_part alternative_part)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
796
797
798
799
800
801


alternative_part
        :       (answer_part+ else_part?)
        ->      answer_part+ else_part?
                | else_part
802
803
        ->      else_part
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
804
805
806
807


alternative_question
        :       expression
808
809
                | informal_text
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
810
811
812
813
814
815
816
817
818
819


decision
        :       cif?
                hyperlink?
                DECISION question e=end
                answer_part?
                alternative_part?
                ENDDECISION f=end
        ->      ^(DECISION cif? hyperlink? $e? question
820
821
                answer_part? alternative_part?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
822
823
824
825
826
827


answer_part
        :       cif?
                hyperlink?
                L_PAREN answer R_PAREN ':' transition?
828
829
        ->      ^(ANSWER cif? hyperlink? answer transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
830
831
832
833


answer
        :       range_condition
834
835
                | informal_text
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
836
837
838
839
840
841


else_part
        :       cif?
                hyperlink?
                ELSE ':' transition?
842
843
        ->      ^(ELSE cif? hyperlink? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
844
845
846


question
847
848
        :       informal_text
                | expression
Maxime Perrotin's avatar
Maxime Perrotin committed
849
850
        ->      ^(QUESTION expression)
                | ANY
851
852
        ->      ^(ANY)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
853
854
855


range_condition
856
857
        :       (closed_range | open_range)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
858
859
860
861
                //(',' (closed_range|open_range))*;


closed_range
862
        :       a=expression ':' b=expression
863
864
        ->      ^(CLOSED_RANGE $a $b)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
865
866
867
868
869
870


open_range
        :       constant
        ->      constant
                | ( (EQ|NEQ|GT|LT|LE|GE) constant)
871
872
        ->      ^(OPEN_RANGE EQ? NEQ? GT? LT? LE? GE? constant)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
873
874
875
876


constant
        :       expression
877
878
        ->      ^(CONSTANT expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
879
880
881


create_request
dbarbera's avatar
dbarbera committed
882
        :       CREATE
Maxime Perrotin's avatar
Maxime Perrotin committed
883
884
885
                createbody
                actual_parameters?
                end
886
887
        ->      ^(CREATE createbody actual_parameters?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
888
889
890
891


createbody
        :       process_id
892
893
                | THIS
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
894
895
896
897
898
899


output
        :       cif?
                hyperlink?
                OUTPUT outputbody end
900
901
        ->      ^(OUTPUT cif? hyperlink? end? outputbody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
902
903
904


outputbody
905
        :       outputstmt (',' outputstmt)* to_part?
906
907
        ->      ^(OUTPUT_BODY outputstmt+ to_part?)
        ;
908
909
 //               via_part?
 //     -> (signal_id actual_parameters?)+ to_part? via_part?;
Maxime Perrotin's avatar
Maxime Perrotin committed
910
911
912


outputstmt
dbarbera's avatar
dbarbera committed
913
        :       signal_id
914
915
                actual_parameters?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
916

917
to_part
Maxime Perrotin's avatar
Maxime Perrotin committed
918
        :       (TO destination)
919
920
        ->      ^(TO destination)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
921

922
via_part
dbarbera's avatar
dbarbera committed
923
        :       VIA viabody
924
925
        ->      ^(VIA viabody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
926
927
928
929


// ambiguous in SDL92, added OR between ALL and via_path
viabody
dbarbera's avatar
dbarbera committed
930
        :       ALL
Maxime Perrotin's avatar
Maxime Perrotin committed
931
932
        ->      ^(ALL)
                | via_path
933
934
        ->      ^(VIAPATH via_path)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
935
936
937
938
939


destination
        :       pid_expression
                | process_id
940
941
                | THIS
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
942
943
944
945


via_path
        :       via_path_element (',' via_path_element)*
946
947
        ->      via_path_element+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
948
949
950


via_path_element
951
952
        :       ID
        ; // signal_route_id | channel_id | gate_id;
Maxime Perrotin's avatar
Maxime Perrotin committed
953
954
955
956


actual_parameters
        :      '(' expression (',' expression)* ')'
957
958
        ->     ^(PARAMS expression+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
959
960
961
962
963


task
        :       cif?
                hyperlink?
964
                TASK task_body? end
965
966
        ->      ^(TASK cif? hyperlink? end? task_body?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
967
968
969
970
971
972
973
974
975
976
977


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

978

Maxime Perrotin's avatar
Maxime Perrotin committed
979
980
// SDL extension - FOR loop in TASKs
forloop
981
        :       FOR variable_id IN (range | variable) ':'
Maxime Perrotin's avatar
Maxime Perrotin committed
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
                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
1000
        :       postfix_expression
dbarbera's avatar
dbarbera committed
1001
1002
        |       ID                     ->  ^(VARIABLE ID);

Maxime Perrotin's avatar
Maxime Perrotin committed
1003
1004
1005
1006

field_selection
        :       (('!'|'.') field_name);

1007

dbarbera's avatar
dbarbera committed
1008
expression
1009
1010
        :       binary_expression;

1011

1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
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)*;

1025

1026
unary_expression
1027
1028
        :       postfix_expression
        |       primary_expression
1029
        |       NOT^ unary_expression
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
        |       DASH unary_expression -> ^(NEG unary_expression)
        ;


postfix_expression
        :       (ID -> ^(PRIMARY ^(VARIABLE ID)))
                (   '(' params=expression_list ')' -> ^(CALL $postfix_expression ^(PARAMS $params))
                |   '!' field_name  -> ^(SELECTOR $postfix_expression field_name)
                )+
        ;

1041
1042
1043

primary_expression
        :       primary                       -> ^(PRIMARY primary)
1044
        |       '(' expression ')'            -> ^(PAREN expression)
1045
        |       conditional_expression
1046
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1047

1048

1049
primary
1050
        :       TRUE^
Maxime Perrotin's avatar
Maxime Perrotin committed
1051
        |       FALSE^
1052
        |       STRING
Maxime Perrotin's avatar
Maxime Perrotin committed
1053
1054
1055
        |       NULL^
        |       PLUS_INFINITY^
        |       MINUS_INFINITY^
1056
1057
        |       INT^
        |       FLOAT^
1058
        |       ID ':' expression           -> ^(CHOICE ID expression)
dbarbera's avatar
dbarbera committed
1059
        |       ID                          -> ^(VARIABLE ID)
1060
1061
        |       '{' '}'                     -> ^(EMPTYSTR)
        |       '{'
Maxime Perrotin's avatar
Maxime Perrotin committed
1062
1063
                MANTISSA mant=INT COMMA
                BASE bas=INT COMMA
dbarbera's avatar
dbarbera committed
1064
                EXPONENT exp=INT
1065
1066
                '}'                         -> ^(FLOAT2 $mant $bas $exp)
        |       '{'
1067
1068
                named_value (COMMA named_value)*
                '}'                         -> ^(SEQUENCE named_value+)
1069
        |       '{'
1070
1071
                primary (COMMA primary)*
                '}'                         -> ^(SEQOF primary+)
1072
        |       STATE^
Maxime Perrotin's avatar
Maxime Perrotin committed
1073
1074
        ;

1075

Maxime Perrotin's avatar
Maxime Perrotin committed
1076
informal_text
1077
        :        STRING
1078
1079
        ->       ^(INFORMAL_TEXT STRING)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1080
1081
1082


// { a 5 } (SEQUENCE field value)
1083
named_value
1084
1085
        :       ID expression
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1086
1087
1088
1089
1090
1091


primary_params
        :      '(' expression_list ')'
        ->     ^(PARAMS expression_list)
               | '!' literal_id
1092
1093
        ->     ^(FIELD_NAME literal_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1094
1095


dbarbera's avatar
dbarbera committed
1096
/* All cases are covered by the ground primary
Maxime Perrotin's avatar
Maxime Perrotin committed
1097
1098
1099
1100
1101
   above (Except structure primary, but we favour ASN.1 notation)
extended_primary
        :       synonym         |
                indexed_primary |
                field_primary   |
1102
1103
                structure_primary
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1104
1105
1106
1107
*/


indexed_primary
1108
1109
        :       primary '(' expression_list ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1110
1111
1112


field_primary
1113
1114
        :       primary field_selection
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1115
1116
1117


structure_primary
1118
1119
        :       '(.' expression_list '.)'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1120
1121
1122
1123
1124
// Removed "qualifier" from the standard
// (to be put later, but never used in practice)


active_expression
1125
1126
        :       active_primary
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1127
1128
1129
1130
1131
1132
1133
1134


active_primary
        :       variable_access
                | operator_application
                | conditional_expression
                | imperative_operator
                | '(' active_expression ')'
1135
1136
                | 'ERROR'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1137
1138
1139
1140
1141
1142
1143
1144
1145
   // active_extended_primary removed because not defined in the standard


imperative_operator
        :       now_expression
                | import_expression
                | pid_expression
                | view_expression
                | timer_active_expression
1146
1147
                | anyvalue_expression
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1148
1149
1150


timer_active_expression
1151
1152
        :       ACTIVE '(' timer_id ('(' expression_list ')')? ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1153
1154
1155


anyvalue_expression
1156
1157
        :       ANY '(' sort ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1158
1159
1160


sort    :       sort_id
1161
1162
1163
        ->      ^(SORT sort_id)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
1164

1165
1166
type_inst
        :       type_id
1167
1168
        ->      ^(TYPE_INSTANCE type_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1169

1170
1171
1172

syntype :       syntype_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1173
1174
1175


import_expression
1176
1177
        :       IMPORT '(' remote_variable_id (',' destination)? ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1178
1179
1180


view_expression
1181
1182
        :       VIEW '(' view_id (',' pid_expression)? ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1183
1184
1185


variable_access
1186
1187
        :       variable_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1188
1189
1190


operator_application
1191
1192
        :       operator_id '('active_expression_list ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1193
1194


dbarbera's avatar
dbarbera committed
1195
active_expression_list
1196
1197
1198
        :       active_expression (',' expression_list)?
        ;
/* |
Maxime Perrotin's avatar
Maxime Perrotin committed
1199
1200
1201
                ground_expression ',' active_expression_list;*/   // Will not work (recursion)


1202
//synonym :       ID; // synonym_id | external_synonym;
Maxime Perrotin's avatar
Maxime Perrotin committed
1203
1204

external_synonym
1205
1206
        :       external_synonym_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1207
1208


1209
conditional_expression
Maxime Perrotin's avatar
Maxime Perrotin committed
1210
1211
1212
        :       IF ifexpr=expression
                THEN thenexpr=expression
                ELSE elseexpr=expression FI
1213
1214
        ->      ^(CONDITIONAL $ifexpr $thenexpr $elseexpr)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1215
1216


dbarbera's avatar
dbarbera committed
1217
expression_list
Maxime Perrotin's avatar
Maxime Perrotin committed
1218
        :       expression (',' expression)*
1219
1220
        ->      expression+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1221
1222
1223
1224
1225
1226
1227
1228


terminator_statement
        :       label?
                cif?
                hyperlink?
                terminator
                end
1229
1230
        ->      ^(TERMINATOR label? cif? hyperlink? end? terminator)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1231
1232
1233

label
        :       cif? connector_name ':'
1234
1235
        ->      ^(LABEL cif? connector_name)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1236
1237
1238


terminator
1239
1240
        :       nextstate | join | stop | return_stmt
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1241
1242
1243
1244


join
        :        JOIN connector_name
1245
1246
        ->       ^(JOIN connector_name)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1247
1248


1249
1250
stop    :       STOP
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1251
1252
1253
1254


return_stmt
        :       RETURN expression?
1255
1256
        ->      ^(RETURN expression?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1257
1258
1259
1260


nextstate
        :       NEXTSTATE nextstatebody
1261
1262
        ->      ^(NEXTSTATE nextstatebody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1263
1264
1265


nextstatebody
1266
        :       statename via?
1267
1268
                | dash_nextstate
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1269
1270


1271
via     :       VIA state_entry_point_name
1272
1273
        ->      ^(VIA state_entry_point_name)
        ;
1274
1275


Maxime Perrotin's avatar
Maxime Perrotin committed
1276
end
1277
        :   (cif? hyperlink? COMMENT STRING)? SEMI+
1278
1279
        -> ^(COMMENT cif? hyperlink? STRING)?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1280
1281
1282
1283
1284
1285


cif
        :       cif_decl symbolname
                L_PAREN x=INT COMMA y=INT R_PAREN
                COMMA
dbarbera's avatar
dbarbera committed
1286
                L_PAREN width=INT COMMA height=INT R_PAREN
Maxime Perrotin's avatar
Maxime Perrotin committed
1287
                cif_end
1288
1289
        ->      ^(CIF $x $y $width $height)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1290
1291
1292


hyperlink
1293
        :       cif_decl KEEP SPECIFIC GEODE HYPERLINK STRING
Maxime Perrotin's avatar
Maxime Perrotin committed
1294
                cif_end
1295
1296
        ->      ^(HYPERLINK STRING)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1297
1298
1299

/* OpenGEODE specific: SDL does not allow specifying the name
   of signal parameters, but it is needed to generate function signatures
dbarbera's avatar
dbarbera committed
1300
   when generating code (in particular in Ada, where the name in the
Maxime Perrotin's avatar
Maxime Perrotin committed
1301
1302
1303
1304
1305
1306
   body must comply with the one of the source
   Extension is using CIF comment so it is invisible to other SDL parsers
   (This is valid SDL code - see ITU-T Z106)
*/
paramnames
        :       cif_decl KEEP SPECIFIC GEODE PARAMNAMES field_name+ cif_end
1307
1308
        ->      ^(PARAMNAMES field_name+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1309
1310
1311
1312
1313
1314
1315


/* OpenGEODE specific: Allow specifying the name of an ASN.1 file
   as a CIF extension linked to a USE clause.
   CIF Extensions are valid SDL constructs (ITU-T Z106)
*/
use_asn1
1316
        :       cif_decl KEEP SPECIFIC GEODE ASNFILENAME STRING cif_end
1317
1318
        ->      ^(ASN1 STRING)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1319
1320


Maxime Perrotin's avatar
Maxime Perrotin committed
1321
1322
1323
/* OpenGEODE specific: Boolean condition that can be used in simulators
*/
stop_if
1324
        :       (STOP IF expression end)+
1325
1326
1327
        ->      ^(STOPIF expression+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
1328