sdl92.g 33.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
6
    Includes the following features from SDL2000+:
    - FOR loops in TASKs
    - Composite states
Maxime Perrotin's avatar
Maxime Perrotin committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

    author: Maxime Perrotin
*/

grammar sdl92;

options {
    language=Python;
    output=AST;
    ASTLabelType=CommonTree;
    backtrack=true;
}

tokens {
        ACTION;
dbarbera's avatar
dbarbera committed
22
        ALL;
Maxime Perrotin's avatar
Maxime Perrotin committed
23
24
        ALTERNATIVE;
        ANSWER;
dbarbera's avatar
dbarbera committed
25
26
27
28
29
30
31
32
        ARRAY;
        ASN1;
        ASSIGN;
        BITSTR;
        BLOCK;
        CHANNEL;
        CHOICE;
        CIF;
Maxime Perrotin's avatar
Maxime Perrotin committed
33
        CLOSED_RANGE;
dbarbera's avatar
dbarbera committed
34
35
36
37
        COMMENT;
        COMPOSITE_STATE;
        CONNECT;
        CONNECTION;
Maxime Perrotin's avatar
Maxime Perrotin committed
38
        CONSTANT;
dbarbera's avatar
dbarbera committed
39
40
41
42
        CONSTANTS;
        DCL;
        DECISION;
        DIGITS;
Maxime Perrotin's avatar
Maxime Perrotin committed
43
        ELSE;
dbarbera's avatar
dbarbera committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
        EMPTYSTR;
        ENDNEWTYPE;
        ENDSYNTYPE;
        ENDTEXT;
        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;
72
        LITERAL;
dbarbera's avatar
dbarbera committed
73
74
75
76
77
78
        NEG;
        NEWTYPE;
        NEXTSTATE;
        NUMBER_OF_INSTANCES;
        OCTSTR;
        OPEN_RANGE;
Maxime Perrotin's avatar
Maxime Perrotin committed
79
80
        OUTPUT;
        OUTPUT_BODY;
dbarbera's avatar
dbarbera committed
81
82
        PARAM;
        PARAMNAMES;
Maxime Perrotin's avatar
Maxime Perrotin committed
83
        PARAMS;
84
        PAREN;
Maxime Perrotin's avatar
Maxime Perrotin committed
85
        PRIMARY;
dbarbera's avatar
dbarbera committed
86
87
88
89
90
        PROCEDURE;
        PROCEDURE_CALL;
        PROCEDURE_NAME;
        PROCESS;
        PROVIDED;
Maxime Perrotin's avatar
Maxime Perrotin committed
91
        QUESTION;
dbarbera's avatar
dbarbera committed
92
93
94
        RANGE;
        RESET;
        RETURN;
Maxime Perrotin's avatar
Maxime Perrotin committed
95
        ROUTE;
dbarbera's avatar
dbarbera committed
96
        SAVE;
97
        SELECTOR;
dbarbera's avatar
dbarbera committed
98
99
100
101
102
103
104
105
106
107
108
        SEQOF;
        SEQUENCE;
        SET;
        SIGNAL;
        SIGNAL_LIST;
        SORT;
        STATE;
        STATELIST;
        STIMULUS;
        STOP;
        STRING;
109
        STRUCT;
110
111
        SYNONYM;
        SYNONYM_LIST;
dbarbera's avatar
dbarbera committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
        SYNTYPE;
        SYSTEM;
        TASK;
        TASK_BODY;
        TERMINATOR;
        TEXT;
        TEXTAREA;
        TEXTAREA_CONTENT;
        THEN;
        TIMER;
        TO;
        TRANSITION;
        USE;
        VALUE;
        VARIABLE;
        VARIABLES;
        VIA;
        VIAPATH;
Maxime Perrotin's avatar
Maxime Perrotin committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
}


/*
    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?
                USE package_name end
        ->      ^(USE use_asn1? package_name);


/* Entity in system:
   Declare signals, external procedures, connections and blocks
*/
entity_in_system
        :       signal_declaration
                | 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
188
                entity_in_block*
Maxime Perrotin's avatar
Maxime Perrotin committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
                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)
219
                | cif? PROCESS process_id number_of_instances? end
220
                (text_area | procedure | composite_state)*
Maxime Perrotin's avatar
Maxime Perrotin committed
221
222
                processBody? ENDPROCESS process_id?
                end
223
        ->      ^(PROCESS cif? process_id number_of_instances?
224
                text_area* procedure* composite_state* processBody?);
Maxime Perrotin's avatar
Maxime Perrotin committed
225
226


227
228
// procedure: missing the RETURNS statement
// (TODO - but check new SDL2000 syntax that has no RETURNS token)
Maxime Perrotin's avatar
Maxime Perrotin committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
procedure
        :       cif?
                PROCEDURE procedure_id end
                fpar?
                (text_area | procedure)*
                ((processBody? ENDPROCEDURE procedure_id?) | EXTERNAL)
                end
        ->      ^(PROCEDURE cif? procedure_id end? fpar?
                text_area* procedure* processBody? EXTERNAL?);


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


formal_variable_param
        :       (INOUT | IN)?
                variable_id (',' variable_id)* sort
        ->      ^(PARAM INOUT? IN? variable_id+ sort);


// 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
                 | fpar
                 | timer_declaration
268
269
                 | syntype_definition
                 | newtype_definition
270
271
                 | variable_definition
                 | synonym_definition)*
Maxime Perrotin's avatar
Maxime Perrotin committed
272
273
274
        ->       ^(TEXTAREA_CONTENT fpar* procedure* variable_definition*
                   syntype_definition* newtype_definition* timer_declaration*
                   synonym_definition*);
Maxime Perrotin's avatar
Maxime Perrotin committed
275
276
277
278
279
280
281
282


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

283
syntype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
284
285
286
287
288
289
290
        :       SYNTYPE syntype_name '=' parent_sort
                (CONSTANTS (range_condition (',' range_condition)* ))?
                ENDSYNTYPE syntype_name? end
        ->      ^(SYNTYPE syntype_name parent_sort range_condition*);

syntype_name
        :       sort;
291
292

parent_sort
Maxime Perrotin's avatar
Maxime Perrotin committed
293
        :       sort;
294
295

newtype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
296
297
298
        :       NEWTYPE type_name (array_definition|structure_definition)?
                ENDNEWTYPE type_name? end
        ->      ^(NEWTYPE type_name array_definition* structure_definition*);
299
300
301


type_name
Maxime Perrotin's avatar
Maxime Perrotin committed
302
303
        :       sort;

304
array_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
305
306
        :       ARRAY '(' sort ',' sort ')'
        ->      ^(ARRAY sort sort);
307
308

structure_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
309
310
        :       STRUCT field_list end
        ->      ^(STRUCT field_list);
311
312

field_list
Maxime Perrotin's avatar
Maxime Perrotin committed
313
314
        :       field_definition (end field_definition)*
        ->      ^(FIELDS field_definition+);
315
316

field_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
317
318
        :       field_name (',' field_name)* sort
        ->      ^(FIELD field_name+ sort);
319

Maxime Perrotin's avatar
Maxime Perrotin committed
320
321
322
323
324
325
variable_definition
        :       DCL variables_of_sort
                (',' variables_of_sort)*
                end
        ->      ^(DCL variables_of_sort+);

Maxime Perrotin's avatar
Maxime Perrotin committed
326
327
328
synonym_definition
        :       internal_synonym_definition;

329
internal_synonym_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
330
331
332
333
        :       SYNONYM synonym_definition_item (',' synonym_definition_item)*
                end
        ->      ^(SYNONYM_LIST synonym_definition_item+);

334
synonym_definition_item
Maxime Perrotin's avatar
Maxime Perrotin committed
335
336
        :       sort sort '=' ground_expression
        ->      ^(SYNONYM sort sort ground_expression);
Maxime Perrotin's avatar
Maxime Perrotin committed
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

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?
360
                START name=state_entry_point_name? end
Maxime Perrotin's avatar
Maxime Perrotin committed
361
                transition?
362
        ->      ^(START cif? hyperlink? $name? end? transition?);
Maxime Perrotin's avatar
Maxime Perrotin committed
363
364
365
366
367
368
369
370
371
372
373
374
375


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


state
376
        :       cif?
Maxime Perrotin's avatar
Maxime Perrotin committed
377
378
379
380
381
382
383
384
385
                hyperlink?
                STATE statelist e=end
                (state_part)*
                ENDSTATE statename? f=end
        ->      ^(STATE cif? hyperlink? $e? statelist state_part*);


statelist
        :       ((statename)(',' statename)*)
386
        ->      ^(STATELIST statename+)
Maxime Perrotin's avatar
Maxime Perrotin committed
387
388
389
390
391
                | ASTERISK exception_state?
        ->      ^(ASTERISK exception_state?);


exception_state
392
        :       '(' statename (',' statename)* ')'
Maxime Perrotin's avatar
Maxime Perrotin committed
393
394
395
        ->      statename+;


396
397
398
composite_state
        :       STATE statename e=end
                SUBSTRUCTURE
399
                connection_points*
400
401
                body=composite_state_body
                ENDSUBSTRUCTURE statename? f=end
402
        ->      ^(COMPOSITE_STATE statename connection_points* $body $e?);
403
404
405


connection_points
406
407
408
409
        :       IN state_entry_exit_points end
        ->      ^(IN state_entry_exit_points end?)
                | OUT state_entry_exit_points end
        ->      ^(OUT state_entry_exit_points end?);
410
411
412
413
414
415
416
417
418


state_entry_exit_points
        :       '(' statename (',' statename)* ')'
        ->      statename+;


composite_state_body
        :       (text_area | procedure | composite_state)*
Maxime Perrotin's avatar
Maxime Perrotin committed
419
                start* (state | floating_label)*;
420
421


Maxime Perrotin's avatar
Maxime Perrotin committed
422
423
424
425
426
state_part
        :       input_part
                //| priority_input        // Not supported
                | save_part               // Not supported in openGEODE
                | spontaneous_transition
427
428
429
430
431
432
                | continuous_signal       // Not supoorted in openGEODE
                | connect_part;


// connect part is used to connect nested state exit points to a transition
connect_part
Maxime Perrotin's avatar
Maxime Perrotin committed
433
434
435
436
437
        :       cif?
                hyperlink?
                CONNECT connect_list? end
                transition?
        ->      ^(CONNECT cif? hyperlink? connect_list? end? transition?);
438
439
440
441
442
443


connect_list
        :       state_exit_point_name (',' state_exit_point_name)*
                -> state_exit_point_name+
                | ASTERISK;
Maxime Perrotin's avatar
Maxime Perrotin committed
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460


spontaneous_transition
        :       cif?
                hyperlink?
                INPUT NONE end
                enabling_condition?
                transition
        ->      ^(INPUT_NONE cif? hyperlink? transition);


enabling_condition
        :       PROVIDED expression end
        ->      ^(PROVIDED expression);


continuous_signal
dbarbera's avatar
dbarbera committed
461
        :       PROVIDED expression end
462
                (PRIORITY integer_literal_name=INT end)?
Maxime Perrotin's avatar
Maxime Perrotin committed
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
                transition
        ->      ^(PROVIDED expression $integer_literal_name? transition);


save_part
        :       SAVE save_list
                end
        ->      ^(SAVE save_list);


save_list
        :       signal_list
                | asterisk_save_list;


asterisk_save_list
        :       ASTERISK;


signal_list
        :       signal_item (',' signal_item)*
        ->      ^(SIGNAL_LIST signal_item+);



// 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
496
/*   Not considered for the moment
Maxime Perrotin's avatar
Maxime Perrotin committed
497
498
     (irrelevant in the scope of the generation of code for a single process)
priority_input
dbarbera's avatar
dbarbera committed
499
        :       PRIORITY INPUT priority_input_list end transition;
Maxime Perrotin's avatar
Maxime Perrotin committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513


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
514
515
                INPUT inputlist end
                enabling_condition?
Maxime Perrotin's avatar
Maxime Perrotin committed
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
                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
566
        :       CALL remote_procedure_call_body;
Maxime Perrotin's avatar
Maxime Perrotin committed
567
568

remote_procedure_call_body
dbarbera's avatar
dbarbera committed
569
        :       remote_procedure_id actual_parameters? (TO destination)?;
Maxime Perrotin's avatar
Maxime Perrotin committed
570
571
572
573
574
575
576
577
578
579
580
*/


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
581
        :       procedure_id actual_parameters?
Maxime Perrotin's avatar
Maxime Perrotin committed
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
        ->      ^(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
        :       expression
        ->      ^(QUESTION expression)
                | informal_text
        ->      informal_text
                | ANY
        ->      ^(ANY);


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


closed_range
        :       a=INT ':' b=INT
        ->      ^(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
690
        :       CREATE
Maxime Perrotin's avatar
Maxime Perrotin committed
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
                createbody
                actual_parameters?
                end
        ->      ^(CREATE createbody actual_parameters?);


createbody
        :       process_id
                | THIS;


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


outputbody
710
711
712
713
        :       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
714
715
716


outputstmt
dbarbera's avatar
dbarbera committed
717
        :       signal_id
Maxime Perrotin's avatar
Maxime Perrotin committed
718
719
                actual_parameters?;

720
to_part
Maxime Perrotin's avatar
Maxime Perrotin committed
721
722
        :       (TO destination)
        ->      ^(TO destination);
Maxime Perrotin's avatar
Maxime Perrotin committed
723

724
via_part
dbarbera's avatar
dbarbera committed
725
726
        :       VIA viabody
        ->      ^(VIA viabody);
Maxime Perrotin's avatar
Maxime Perrotin committed
727
728
729
730


// ambiguous in SDL92, added OR between ALL and via_path
viabody
dbarbera's avatar
dbarbera committed
731
        :       ALL
Maxime Perrotin's avatar
Maxime Perrotin committed
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
        ->      ^(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?
760
761
                TASK task_body? end
        ->      ^(TASK cif? hyperlink? end? task_body?);
Maxime Perrotin's avatar
Maxime Perrotin committed
762
763
764
765
766
767
768
769
770
771
772
773
774


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
775
        :       FOR variable_id IN (range | variable) ':'
Maxime Perrotin's avatar
Maxime Perrotin committed
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
                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
794
        :       postfix_expression
dbarbera's avatar
dbarbera committed
795
796
        |       ID                     ->  ^(VARIABLE ID);

Maxime Perrotin's avatar
Maxime Perrotin committed
797
798
799
800

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

801

dbarbera's avatar
dbarbera committed
802
expression
803
804
        :       binary_expression;

805

806
807
808
809
810
811
812
813
814
815
816
817
818
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)*;

819

820
unary_expression
821
822
        :       postfix_expression
        |       primary_expression
823
        |       NOT^ unary_expression
824
825
826
827
828
829
830
831
832
833
834
        |       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)
                )+
        ;

835
836
837

primary_expression
        :       primary                       -> ^(PRIMARY primary)
838
        |       '(' expression ')'            -> ^(PAREN expression)
839
840
        |       conditional_ground_expression
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
841

842

843
primary
844
845
        :       BITSTR^
        |       OCTSTR^
Maxime Perrotin's avatar
Maxime Perrotin committed
846
847
        |       TRUE^
        |       FALSE^
848
        |       STRING
Maxime Perrotin's avatar
Maxime Perrotin committed
849
850
851
        |       NULL^
        |       PLUS_INFINITY^
        |       MINUS_INFINITY^
852
853
        |       INT^
        |       FLOAT^
854
        |       ID ':' expression           -> ^(CHOICE ID expression)
dbarbera's avatar
dbarbera committed
855
        |       ID                          -> ^(VARIABLE ID)
856
857
        |       '{' '}'                     -> ^(EMPTYSTR)
        |       '{'
Maxime Perrotin's avatar
Maxime Perrotin committed
858
859
                MANTISSA mant=INT COMMA
                BASE bas=INT COMMA
dbarbera's avatar
dbarbera committed
860
                EXPONENT exp=INT
861
862
                '}'                         -> ^(FLOAT2 $mant $bas $exp)
        |       '{'
863
864
                named_value (COMMA named_value)*
                '}'                         -> ^(SEQUENCE named_value+)
865
        |       '{'
866
867
                primary (COMMA primary)*
                '}'                         -> ^(SEQOF primary+)
Maxime Perrotin's avatar
Maxime Perrotin committed
868
869
        ;

870

Maxime Perrotin's avatar
Maxime Perrotin committed
871
informal_text
872
873
        :        STRING
        ->       ^(INFORMAL_TEXT STRING);
Maxime Perrotin's avatar
Maxime Perrotin committed
874
875
876


// { a 5 } (SEQUENCE field value)
877
named_value
Maxime Perrotin's avatar
Maxime Perrotin committed
878
879
880
881
882
883
884
885
886
887
        :       ID expression;


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


dbarbera's avatar
dbarbera committed
888
/* All cases are covered by the ground primary
Maxime Perrotin's avatar
Maxime Perrotin committed
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
   above (Except structure primary, but we favour ASN.1 notation)
extended_primary
        :       synonym         |
                indexed_primary |
                field_primary   |
                structure_primary;
*/


indexed_primary
        :       primary '(' expression_list ')';


field_primary
        :       primary field_selection;


structure_primary
        :       '(.' expression_list '.)';
// Removed "qualifier" from the standard
// (to be put later, but never used in practice)


active_expression
        :       active_primary;


active_primary
        :       variable_access
                | operator_application
                | conditional_expression
                | imperative_operator
                | '(' active_expression ')'
                | 'ERROR';
   // active_extended_primary removed because not defined in the standard


imperative_operator
        :       now_expression
                | import_expression
                | pid_expression
                | view_expression
                | timer_active_expression
                | anyvalue_expression;


timer_active_expression
dbarbera's avatar
dbarbera committed
936
        :       ACTIVE '(' timer_id ('(' expression_list ')')? ')';
Maxime Perrotin's avatar
Maxime Perrotin committed
937
938
939


anyvalue_expression
dbarbera's avatar
dbarbera committed
940
        :       ANY '(' sort ')';
Maxime Perrotin's avatar
Maxime Perrotin committed
941
942
943
944
945
946
947
948
949
950


sort    :       sort_id
        ->      ^(SORT sort_id);


syntype :       syntype_id;


import_expression
dbarbera's avatar
dbarbera committed
951
        :       IMPORT '(' remote_variable_id (',' destination)? ')';
Maxime Perrotin's avatar
Maxime Perrotin committed
952
953
954


view_expression
dbarbera's avatar
dbarbera committed
955
        :       VIEW '(' view_id (',' pid_expression)? ')';
Maxime Perrotin's avatar
Maxime Perrotin committed
956
957
958
959
960
961
962
963
964
965


variable_access
        :       variable_id;


operator_application
        :       operator_id '('active_expression_list ')';


dbarbera's avatar
dbarbera committed
966
active_expression_list
Maxime Perrotin's avatar
Maxime Perrotin committed
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
        :       active_expression (',' expression_list)?;/* |
                ground_expression ',' active_expression_list;*/   // Will not work (recursion)
/*
conditional_expression
        :       IF boolean_active_expression THEN consequence_expression ELSE alternative_expression FI |
                IF boolean_expression THEN active_consequence_expression ELSE alternative_expression FI |
                IF boolean_expression THEN consequence_expression ELSE active_alternative_expression FI;
*/


// Simpler version, the rest will is checked by semantic analysis
conditional_expression
        :       IF expression THEN expression ELSE expression FI;


982
//synonym :       ID; // synonym_id | external_synonym;
Maxime Perrotin's avatar
Maxime Perrotin committed
983
984
985
986
987
988
989
990
991
992
993
994
995


external_synonym
        :       external_synonym_id;


conditional_ground_expression
        :       IF ifexpr=expression
                THEN thenexpr=expression
                ELSE elseexpr=expression FI
        ->      ^(IFTHENELSE $ifexpr $thenexpr $elseexpr);


dbarbera's avatar
dbarbera committed
996
expression_list
Maxime Perrotin's avatar
Maxime Perrotin committed
997
998
999
1000
        :       expression (',' expression)*
        ->      expression+;