sdl92.g 36.2 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
148
149
150
151
152
153
154
155
156
157
158
159
160
}


/*
    Top level: any .pr file
*/

pr_file
        :       (use_clause
                | system_definition
                | process_definition)+;


system_definition
        :       SYSTEM system_name end
                entity_in_system*
                ENDSYSTEM system_name? end
        ->      ^(SYSTEM system_name entity_in_system*);


use_clause
        :       use_asn1?
161
162
163
164
                USE package_name
                ('/' def_selection_list )?
                end
        ->      ^(USE use_asn1? end? package_name def_selection_list?);
Maxime Perrotin's avatar
Maxime Perrotin committed
165

166
167
168
169
170
/*
    In USE clause: USE package/X, Y, Z;
*/
def_selection_list
        :       ID (','! ID)*;
Maxime Perrotin's avatar
Maxime Perrotin committed
171
172
173
174
175
176

/* Entity in system:
   Declare signals, external procedures, connections and blocks
*/
entity_in_system
        :       signal_declaration
177
                | text_area
Maxime Perrotin's avatar
Maxime Perrotin committed
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
                | procedure
                | channel
                | block_definition;

/* signal_declaration:
   e.g. SIGNAL open_door(typeA, typeB);
*/
signal_declaration
        :       paramnames?
                SIGNAL signal_id input_params? end
        ->      ^(SIGNAL paramnames? signal_id input_params?);


channel
        :       CHANNEL channel_id
                route+
                ENDCHANNEL end
        ->      ^(CHANNEL channel_id route+);


route
        :       FROM source_id TO dest_id WITH signal_id (',' signal_id)* end
        ->      ^(ROUTE source_id dest_id signal_id+);


block_definition
        :       BLOCK block_id end
dbarbera's avatar
dbarbera committed
205
                entity_in_block*
Maxime Perrotin's avatar
Maxime Perrotin committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
                ENDBLOCK end
        ->      ^(BLOCK block_id entity_in_block*);


/* 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
                | process_definition;


signalroute
        :       SIGNALROUTE route_id
                route+
        ->      ^(SIGNALROUTE route_id route+);


connection
        :       CONNECT channel_id AND route_id end
        ->      ^(CONNECTION channel_id route_id);


process_definition
        :       PROCESS process_id number_of_instances? REFERENCED end
        ->      ^(PROCESS process_id number_of_instances? REFERENCED)
236
                | cif? PROCESS process_id number_of_instances? end
237
                pfpar?
238
                (text_area | procedure | composite_state)*
Maxime Perrotin's avatar
Maxime Perrotin committed
239
240
                processBody? ENDPROCESS process_id?
                end
241
242
243
244
245
246
        ->      ^(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
247

248
249
250
251
252
253
254
255
256
257
258
// Process formal parameters
pfpar
        :       FPAR parameters_of_sort
                (',' parameters_of_sort)*
                end
        ->      ^(PFPAR parameters_of_sort+);

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

Maxime Perrotin's avatar
Maxime Perrotin committed
259

260
261
// procedure: missing the RETURNS statement
// (TODO - but check new SDL2000 syntax that has no RETURNS token)
Maxime Perrotin's avatar
Maxime Perrotin committed
262
263
procedure
        :       cif?
264
                PROCEDURE procedure_id e1=end
Maxime Perrotin's avatar
Maxime Perrotin committed
265
266
267
                fpar?
                (text_area | procedure)*
                ((processBody? ENDPROCEDURE procedure_id?) | EXTERNAL)
268
269
                e2=end
        ->      ^(PROCEDURE cif? procedure_id $e1? $e2? fpar?
Maxime Perrotin's avatar
Maxime Perrotin committed
270
271
272
273
274
275
276
277
278
279
280
281
                text_area* procedure* processBody? EXTERNAL?);


// Procedure formal parameters
fpar
        :       FPAR formal_variable_param
                (',' formal_variable_param)*
                end
        ->      ^(FPAR formal_variable_param+);


formal_variable_param
282
        :       (INOUT | IN | OUT)?
Maxime Perrotin's avatar
Maxime Perrotin committed
283
                variable_id (',' variable_id)* sort
284
        ->      ^(PARAM INOUT? IN? OUT? variable_id+ sort);
Maxime Perrotin's avatar
Maxime Perrotin committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298


// text_area: TODO add operator description in content
text_area
        :       cif
                content?
                cif_end_text
        ->      ^(TEXTAREA cif content? cif_end_text);


// Text areas can contain textual procedures, FPAR declarations,
// and variable or timer declarations
content
        :        (procedure
299
300
                 | use_clause
                 | signal_declaration
Maxime Perrotin's avatar
Maxime Perrotin committed
301
302
                 | fpar
                 | timer_declaration
303
304
                 | syntype_definition
                 | newtype_definition
305
306
                 | variable_definition
                 | synonym_definition)*
Maxime Perrotin's avatar
Maxime Perrotin committed
307
308
        ->       ^(TEXTAREA_CONTENT fpar* procedure* variable_definition*
                   syntype_definition* newtype_definition* timer_declaration*
309
                   signal_declaration* use_clause* synonym_definition*);
Maxime Perrotin's avatar
Maxime Perrotin committed
310
311
312
313
314
315
316
317


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

318
syntype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
319
320
321
322
323
324
325
        :       SYNTYPE syntype_name '=' parent_sort
                (CONSTANTS (range_condition (',' range_condition)* ))?
                ENDSYNTYPE syntype_name? end
        ->      ^(SYNTYPE syntype_name parent_sort range_condition*);

syntype_name
        :       sort;
326
327

parent_sort
Maxime Perrotin's avatar
Maxime Perrotin committed
328
        :       sort;
329
330

newtype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
331
332
333
        :       NEWTYPE type_name (array_definition|structure_definition)?
                ENDNEWTYPE type_name? end
        ->      ^(NEWTYPE type_name array_definition* structure_definition*);
334
335
336


type_name
Maxime Perrotin's avatar
Maxime Perrotin committed
337
338
        :       sort;

339
array_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
340
341
        :       ARRAY '(' sort ',' sort ')'
        ->      ^(ARRAY sort sort);
342
343

structure_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
344
345
        :       STRUCT field_list end
        ->      ^(STRUCT field_list);
346
347

field_list
Maxime Perrotin's avatar
Maxime Perrotin committed
348
349
        :       field_definition (end field_definition)*
        ->      ^(FIELDS field_definition+);
350
351

field_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
352
353
        :       field_name (',' field_name)* sort
        ->      ^(FIELD field_name+ sort);
354

Maxime Perrotin's avatar
Maxime Perrotin committed
355
356
357
358
359
360
variable_definition
        :       DCL variables_of_sort
                (',' variables_of_sort)*
                end
        ->      ^(DCL variables_of_sort+);

Maxime Perrotin's avatar
Maxime Perrotin committed
361
362
363
synonym_definition
        :       internal_synonym_definition;

364
internal_synonym_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
365
366
367
368
        :       SYNONYM synonym_definition_item (',' synonym_definition_item)*
                end
        ->      ^(SYNONYM_LIST synonym_definition_item+);

369
synonym_definition_item
Maxime Perrotin's avatar
Maxime Perrotin committed
370
371
        :       sort sort '=' ground_expression
        ->      ^(SYNONYM sort sort ground_expression);
Maxime Perrotin's avatar
Maxime Perrotin committed
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

variables_of_sort
        :       variable_id (',' variable_id)* sort (':=' ground_expression)?
        ->      ^(VARIABLES variable_id+ sort ground_expression?);


ground_expression
        :       expression
        ->      ^(GROUND expression);


number_of_instances
        :       '(' initial_number=INT ',' maximum_number=INT ')'
        ->      ^(NUMBER_OF_INSTANCES $initial_number $maximum_number);


processBody
        :       start? (state | floating_label)*;


start
        :       cif?
                hyperlink?
395
                START name=state_entry_point_name? end
Maxime Perrotin's avatar
Maxime Perrotin committed
396
                transition?
397
        ->      ^(START cif? hyperlink? $name? end? transition?);
Maxime Perrotin's avatar
Maxime Perrotin committed
398
399
400
401
402
403
404
405
406
407
408
409
410


floating_label
        :       cif?
                hyperlink?
                CONNECTION connector_name ':'
                transition?
                cif_end_label?
                ENDCONNECTION SEMI
        ->      ^(FLOATING_LABEL cif? hyperlink? connector_name transition?);


state
411
        :       cif?
Maxime Perrotin's avatar
Maxime Perrotin committed
412
413
414
415
416
417
418
419
420
                hyperlink?
                STATE statelist e=end
                (state_part)*
                ENDSTATE statename? f=end
        ->      ^(STATE cif? hyperlink? $e? statelist state_part*);


statelist
        :       ((statename)(',' statename)*)
421
        ->      ^(STATELIST statename+)
Maxime Perrotin's avatar
Maxime Perrotin committed
422
                | ASTERISK exception_state?
423
424
        ->      ^(ASTERISK exception_state?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
425
426
427


exception_state
428
        :       '(' statename (',' statename)* ')'
429
430
        ->      statename+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
431
432


433
composite_state
434
435
436
437
438
439
        :       composite_state_graph
                | state_aggregation
        ;


composite_state_graph
440
441
        :       STATE statename e=end
                SUBSTRUCTURE
442
                connection_points*
443
444
                body=composite_state_body
                ENDSUBSTRUCTURE statename? f=end
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
        ->      ^(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?)
        ;
499
500
501


connection_points
502
503
504
        :       IN state_entry_exit_points end
        ->      ^(IN state_entry_exit_points end?)
                | OUT state_entry_exit_points end
505
506
        ->      ^(OUT state_entry_exit_points end?)
        ;
507
508
509
510


state_entry_exit_points
        :       '(' statename (',' statename)* ')'
511
512
        ->      statename+
        ;
513
514
515
516


composite_state_body
        :       (text_area | procedure | composite_state)*
517
518
                start* (state | floating_label)*
        ;
519
520


Maxime Perrotin's avatar
Maxime Perrotin committed
521
522
523
524
525
state_part
        :       input_part
                //| priority_input        // Not supported
                | save_part               // Not supported in openGEODE
                | spontaneous_transition
526
                | continuous_signal       // Not supoorted in openGEODE
527
528
                | connect_part
        ;
529
530
531
532


// connect part is used to connect nested state exit points to a transition
connect_part
Maxime Perrotin's avatar
Maxime Perrotin committed
533
534
535
536
        :       cif?
                hyperlink?
                CONNECT connect_list? end
                transition?
537
538
        ->      ^(CONNECT cif? hyperlink? connect_list? end? transition?)
        ;
539
540
541
542
543


connect_list
        :       state_exit_point_name (',' state_exit_point_name)*
                -> state_exit_point_name+
544
545
                | ASTERISK
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
546
547
548
549
550
551
552
553


spontaneous_transition
        :       cif?
                hyperlink?
                INPUT NONE end
                enabling_condition?
                transition
554
555
        ->      ^(INPUT_NONE cif? hyperlink? transition)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
556
557
558
559


enabling_condition
        :       PROVIDED expression end
560
561
        ->      ^(PROVIDED expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
562
563
564


continuous_signal
dbarbera's avatar
dbarbera committed
565
        :       PROVIDED expression end
566
                (PRIORITY integer_literal_name=INT end)?
Maxime Perrotin's avatar
Maxime Perrotin committed
567
                transition
568
569
        ->      ^(PROVIDED expression $integer_literal_name? transition)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
570
571
572
573
574


save_part
        :       SAVE save_list
                end
575
576
        ->      ^(SAVE save_list)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
577
578
579
580


save_list
        :       signal_list
581
582
                | asterisk_save_list
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
583
584
585
586
587
588
589
590


asterisk_save_list
        :       ASTERISK;


signal_list
        :       signal_item (',' signal_item)*
591
592
        ->      ^(SIGNAL_LIST signal_item+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
593
594
595
596
597
598
599
600
601
602
603



// 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
604
/*   Not considered for the moment
Maxime Perrotin's avatar
Maxime Perrotin committed
605
606
     (irrelevant in the scope of the generation of code for a single process)
priority_input
dbarbera's avatar
dbarbera committed
607
        :       PRIORITY INPUT priority_input_list end transition;
Maxime Perrotin's avatar
Maxime Perrotin committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621


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
622
623
                INPUT inputlist end
                enabling_condition?
Maxime Perrotin's avatar
Maxime Perrotin committed
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
                transition?
        ->      ^(INPUT cif? hyperlink? end?
                inputlist enabling_condition? transition?);


// asterisk means: all signals not excplicitely specified
// (semantic is different from asterisk state)
inputlist
        :       ASTERISK
                | (stimulus (',' stimulus)*)
        ->      ^(INPUTLIST stimulus+);


stimulus
        :       stimulus_id input_params?;


input_params
        :       L_PAREN variable_id (',' variable_id)* R_PAREN
        ->      ^(PARAMS variable_id+);


transition
        :       action+ label? terminator_statement?
        ->      ^(TRANSITION action+ label? terminator_statement?)
                | terminator_statement
        ->      ^(TRANSITION terminator_statement);


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

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

/*
remote_procedure_call
dbarbera's avatar
dbarbera committed
674
        :       CALL remote_procedure_call_body;
Maxime Perrotin's avatar
Maxime Perrotin committed
675
676

remote_procedure_call_body
dbarbera's avatar
dbarbera committed
677
        :       remote_procedure_id actual_parameters? (TO destination)?;
Maxime Perrotin's avatar
Maxime Perrotin committed
678
679
680
681
682
683
684
685
686
687
688
*/


procedure_call
        :       cif?
                hyperlink?
                CALL procedure_call_body end
        ->      ^(PROCEDURE_CALL cif? hyperlink? end? procedure_call_body);


procedure_call_body
dbarbera's avatar
dbarbera committed
689
        :       procedure_id actual_parameters?
Maxime Perrotin's avatar
Maxime Perrotin committed
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
        ->      ^(OUTPUT_BODY procedure_id actual_parameters?);


set_timer
        :       SET set_statement (COMMA set_statement)*
                end
        ->      set_statement+;


set_statement
        :       L_PAREN (expression COMMA)? timer_id R_PAREN
        ->      ^(SET expression? timer_id);
        // ('('expression_list')')? ')'; (removed because of non-LL(*) problem)


reset_timer
        :       RESET reset_statement (',' reset_statement)*
                end
        ->      reset_statement+;


reset_statement
        :       timer_id ('(' expression_list ')')?
        ->      ^(RESET timer_id expression_list?);


transition_option
        :       ALTERNATIVE alternative_question e=end
                answer_part
                alternative_part
                ENDALTERNATIVE f=end
        ->      ^(ALTERNATIVE answer_part alternative_part);


alternative_part
        :       (answer_part+ else_part?)
        ->      answer_part+ else_part?
                | else_part
        ->      else_part;


alternative_question
        :       expression
                | informal_text;


decision
        :       cif?
                hyperlink?
                DECISION question e=end
                answer_part?
                alternative_part?
                ENDDECISION f=end
        ->      ^(DECISION cif? hyperlink? $e? question
                answer_part? alternative_part?);


answer_part
        :       cif?
                hyperlink?
                L_PAREN answer R_PAREN ':' transition?
        ->      ^(ANSWER cif? hyperlink? answer transition?);


answer
        :       range_condition
                | informal_text;


else_part
        :       cif?
                hyperlink?
                ELSE ':' transition?
        ->      ^(ELSE cif? hyperlink? transition?);


question
767
768
        :       informal_text
                | expression
Maxime Perrotin's avatar
Maxime Perrotin committed
769
770
771
772
773
774
775
776
777
778
779
        ->      ^(QUESTION expression)
                | ANY
        ->      ^(ANY);


range_condition
        :       (closed_range | open_range);
                //(',' (closed_range|open_range))*;


closed_range
780
        :       a=expression ':' b=expression
Maxime Perrotin's avatar
Maxime Perrotin committed
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
        ->      ^(CLOSED_RANGE $a $b);


open_range
        :       constant
        ->      constant
                | ( (EQ|NEQ|GT|LT|LE|GE) constant)
        ->      ^(OPEN_RANGE EQ? NEQ? GT? LT? LE? GE? constant);


constant
        :       expression
        ->      ^(CONSTANT expression);


create_request
dbarbera's avatar
dbarbera committed
797
        :       CREATE
Maxime Perrotin's avatar
Maxime Perrotin committed
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
                createbody
                actual_parameters?
                end
        ->      ^(CREATE createbody actual_parameters?);


createbody
        :       process_id
                | THIS;


output
        :       cif?
                hyperlink?
                OUTPUT outputbody end
        ->      ^(OUTPUT cif? hyperlink? end? outputbody);


outputbody
817
818
819
820
        :       outputstmt (',' outputstmt)* to_part?
        ->      ^(OUTPUT_BODY outputstmt+ to_part?);
 //               via_part?
 //     -> (signal_id actual_parameters?)+ to_part? via_part?;
Maxime Perrotin's avatar
Maxime Perrotin committed
821
822
823


outputstmt
dbarbera's avatar
dbarbera committed
824
        :       signal_id
Maxime Perrotin's avatar
Maxime Perrotin committed
825
826
                actual_parameters?;

827
to_part
Maxime Perrotin's avatar
Maxime Perrotin committed
828
829
        :       (TO destination)
        ->      ^(TO destination);
Maxime Perrotin's avatar
Maxime Perrotin committed
830

831
via_part
dbarbera's avatar
dbarbera committed
832
833
        :       VIA viabody
        ->      ^(VIA viabody);
Maxime Perrotin's avatar
Maxime Perrotin committed
834
835
836
837


// ambiguous in SDL92, added OR between ALL and via_path
viabody
dbarbera's avatar
dbarbera committed
838
        :       ALL
Maxime Perrotin's avatar
Maxime Perrotin committed
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
        ->      ^(ALL)
                | via_path
        ->      ^(VIAPATH via_path);


destination
        :       pid_expression
                | process_id
                | THIS;


via_path
        :       via_path_element (',' via_path_element)*
        ->      via_path_element+;


via_path_element
        :       ID; // signal_route_id | channel_id | gate_id;


actual_parameters
        :      '(' expression (',' expression)* ')'
        ->     ^(PARAMS expression+);


task
        :       cif?
                hyperlink?
867
868
                TASK task_body? end
        ->      ^(TASK cif? hyperlink? end? task_body?);
Maxime Perrotin's avatar
Maxime Perrotin committed
869
870
871
872
873
874
875
876
877
878
879
880
881


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

// SDL extension - FOR loop in TASKs
forloop
882
        :       FOR variable_id IN (range | variable) ':'
Maxime Perrotin's avatar
Maxime Perrotin committed
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
                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
901
        :       postfix_expression
dbarbera's avatar
dbarbera committed
902
903
        |       ID                     ->  ^(VARIABLE ID);

Maxime Perrotin's avatar
Maxime Perrotin committed
904
905
906
907

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

908

dbarbera's avatar
dbarbera committed
909
expression
910
911
        :       binary_expression;

912

913
914
915
916
917
918
919
920
921
922
923
924
925
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)*;

926

927
unary_expression
928
929
        :       postfix_expression
        |       primary_expression
930
        |       NOT^ unary_expression
931
932
933
934
935
936
937
938
939
940
941
        |       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)
                )+
        ;

942
943
944

primary_expression
        :       primary                       -> ^(PRIMARY primary)
945
        |       '(' expression ')'            -> ^(PAREN expression)
946
        |       conditional_expression
947
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
948

949

950
primary
951
        :       TRUE^
Maxime Perrotin's avatar
Maxime Perrotin committed
952
        |       FALSE^
953
        |       STRING
Maxime Perrotin's avatar
Maxime Perrotin committed
954
955
956
        |       NULL^
        |       PLUS_INFINITY^
        |       MINUS_INFINITY^
957
958
        |       INT^
        |       FLOAT^
959
        |       ID ':' expression           -> ^(CHOICE ID expression)
dbarbera's avatar
dbarbera committed
960
        |       ID                          -> ^(VARIABLE ID)
961
962
        |       '{' '}'                     -> ^(EMPTYSTR)
        |       '{'
Maxime Perrotin's avatar
Maxime Perrotin committed
963
964
                MANTISSA mant=INT COMMA
                BASE bas=INT COMMA
dbarbera's avatar
dbarbera committed
965
                EXPONENT exp=INT
966
967
                '}'                         -> ^(FLOAT2 $mant $bas $exp)
        |       '{'
968
969
                named_value (COMMA named_value)*
                '}'                         -> ^(SEQUENCE named_value+)
970
        |       '{'
971
972
                primary (COMMA primary)*
                '}'                         -> ^(SEQOF primary+)
973
        |       STATE^
Maxime Perrotin's avatar
Maxime Perrotin committed
974
975
        ;

976

Maxime Perrotin's avatar
Maxime Perrotin committed
977
informal_text
978
979
        :        STRING
        ->       ^(INFORMAL_TEXT STRING);
Maxime Perrotin's avatar
Maxime Perrotin committed
980
981
982


// { a 5 } (SEQUENCE field value)
983
named_value
Maxime Perrotin's avatar
Maxime Perrotin committed
984
985
986
987
988
989
990
991
992
993
        :       ID expression;


primary_params
        :      '(' expression_list ')'
        ->     ^(PARAMS expression_list)
               | '!' literal_id
        ->     ^(FIELD_NAME literal_id);


dbarbera's avatar
dbarbera committed
994
/* All cases are covered by the ground primary
Maxime Perrotin's avatar
Maxime Perrotin committed
995
996
997
998
999
1000
   above (Except structure primary, but we favour ASN.1 notation)
extended_primary
        :       synonym         |
                indexed_primary |
                field_primary   |
                structure_primary;
For faster browsing, not all history is shown. View entire blame