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

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


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


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


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

Maxime Perrotin's avatar
Maxime Perrotin committed
169

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

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

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

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


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


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


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


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


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


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


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

268

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

277
278
279

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

Maxime Perrotin's avatar
Maxime Perrotin committed
283

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

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

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


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


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


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


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

Maxime Perrotin's avatar
Maxime Perrotin committed
357

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

Maxime Perrotin's avatar
Maxime Perrotin committed
365
366

syntype_name
367
368
369
        :       sort
        ;

370
371

parent_sort
372
373
374
        :       sort
        ;

375
376

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


type_name
384
385
386
        :       sort
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
387

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

393
394

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

399
400

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

405
406

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

411

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

Maxime Perrotin's avatar
Maxime Perrotin committed
419

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

Maxime Perrotin's avatar
Maxime Perrotin committed
424

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

Maxime Perrotin's avatar
Maxime Perrotin committed
431

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

Maxime Perrotin's avatar
Maxime Perrotin committed
437
438
439

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


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


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


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


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


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


state
482
        :       cif?
Maxime Perrotin's avatar
Maxime Perrotin committed
483
484
485
486
                hyperlink?
                STATE statelist e=end
                (state_part)*
                ENDSTATE statename? f=end
487
488
        ->      ^(STATE cif? hyperlink? $e? statelist state_part*)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
489
490
491
492


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


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


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


composite_state_graph
513
514
        :       STATE statename e=end
                SUBSTRUCTURE
515
                connection_points*
516
517
                body=composite_state_body
                ENDSUBSTRUCTURE statename? f=end
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
        ->      ^(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
543
        :       (state_partitioning | state_partition_connection)*
544
                state*
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
        ;


// 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?)
        ;
573
574


575
// 11.11.1 and 11.11.2 Composite State (SDL2000)
576
connection_points
577
578
579
        :       IN state_entry_exit_points end
        ->      ^(IN state_entry_exit_points end?)
                | OUT state_entry_exit_points end
580
581
        ->      ^(OUT state_entry_exit_points end?)
        ;
582
583


584
// 11.11.1 and 11.11.2 Composite State (SDL2000)
585
586
state_entry_exit_points
        :       '(' statename (',' statename)* ')'
587
588
        ->      statename+
        ;
589
590


591
// 11.11.1 Composite State graph content (SDL2000)
592
593
composite_state_body
        :       (text_area | procedure | composite_state)*
594
595
                start* (state | floating_label)*
        ;
596
597


Maxime Perrotin's avatar
Maxime Perrotin committed
598
599
600
601
602
state_part
        :       input_part
                //| priority_input        // Not supported
                | save_part               // Not supported in openGEODE
                | spontaneous_transition
603
                | continuous_signal
604
605
                | connect_part
        ;
606
607
608
609


// connect part is used to connect nested state exit points to a transition
connect_part
Maxime Perrotin's avatar
Maxime Perrotin committed
610
611
612
613
        :       cif?
                hyperlink?
                CONNECT connect_list? end
                transition?
614
615
        ->      ^(CONNECT cif? hyperlink? connect_list? end? transition?)
        ;
616
617
618
619
620


connect_list
        :       state_exit_point_name (',' state_exit_point_name)*
                -> state_exit_point_name+
621
622
                | ASTERISK
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
623
624
625
626
627
628
629
630


spontaneous_transition
        :       cif?
                hyperlink?
                INPUT NONE end
                enabling_condition?
                transition
631
632
        ->      ^(INPUT_NONE cif? hyperlink? transition)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
633
634
635
636


enabling_condition
        :       PROVIDED expression end
637
638
        ->      ^(PROVIDED expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
639
640
641


continuous_signal
642
643
644
645
        :       cif?
                hyperlink?
                PROVIDED expression e=end
                (PRIORITY p=INT end)?
646
647
                transition?
        ->      ^(PROVIDED expression cif? hyperlink? $p? $e? transition?)
648
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
649
650
651
652
653


save_part
        :       SAVE save_list
                end
654
655
        ->      ^(SAVE save_list)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
656
657
658
659


save_list
        :       signal_list
660
661
                | asterisk_save_list
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
662
663
664
665
666
667
668
669


asterisk_save_list
        :       ASTERISK;


signal_list
        :       signal_item (',' signal_item)*
670
671
        ->      ^(SIGNAL_LIST signal_item+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
672
673
674
675
676
677
678
679
680
681
682



// 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
683
/*   Not considered for the moment
Maxime Perrotin's avatar
Maxime Perrotin committed
684
685
     (irrelevant in the scope of the generation of code for a single process)
priority_input
dbarbera's avatar
dbarbera committed
686
        :       PRIORITY INPUT priority_input_list end transition;
Maxime Perrotin's avatar
Maxime Perrotin committed
687
688
689
690
691
692
693
694
695
696
697
698
699
700


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
701
702
                INPUT inputlist end
                enabling_condition?
Maxime Perrotin's avatar
Maxime Perrotin committed
703
704
                transition?
        ->      ^(INPUT cif? hyperlink? end?
705
706
                inputlist enabling_condition? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
707
708
709
710
711
712
713


// asterisk means: all signals not excplicitely specified
// (semantic is different from asterisk state)
inputlist
        :       ASTERISK
                | (stimulus (',' stimulus)*)
714
715
        ->      ^(INPUTLIST stimulus+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
716
717
718


stimulus
719
720
        :       stimulus_id input_params?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
721
722
723
724


input_params
        :       L_PAREN variable_id (',' variable_id)* R_PAREN
725
726
        ->      ^(PARAMS variable_id+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
727
728
729
730
731
732


transition
        :       action+ label? terminator_statement?
        ->      ^(TRANSITION action+ label? terminator_statement?)
                | terminator_statement
733
734
        ->      ^(TRANSITION terminator_statement)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
735
736
737
738
739
740
741
742
743
744
745
746
747


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

Maxime Perrotin's avatar
Maxime Perrotin committed
751
752
753
754
755

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

Maxime Perrotin's avatar
Maxime Perrotin committed
759
760
761

/*
remote_procedure_call
dbarbera's avatar
dbarbera committed
762
        :       CALL remote_procedure_call_body;
Maxime Perrotin's avatar
Maxime Perrotin committed
763
764

remote_procedure_call_body
dbarbera's avatar
dbarbera committed
765
        :       remote_procedure_id actual_parameters? (TO destination)?;
Maxime Perrotin's avatar
Maxime Perrotin committed
766
767
768
769
770
*/
procedure_call
        :       cif?
                hyperlink?
                CALL procedure_call_body end
771
772
        ->      ^(PROCEDURE_CALL cif? hyperlink? end? procedure_call_body)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
773
774
775


procedure_call_body
dbarbera's avatar
dbarbera committed
776
        :       procedure_id actual_parameters?
777
778
        ->      ^(OUTPUT_BODY procedure_id actual_parameters?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
779
780
781
782
783


set_timer
        :       SET set_statement (COMMA set_statement)*
                end
784
785
        ->      set_statement+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
786
787
788
789


set_statement
        :       L_PAREN (expression COMMA)? timer_id R_PAREN
790
791
        ->      ^(SET expression? timer_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
792
793
794
795
796
797
        // ('('expression_list')')? ')'; (removed because of non-LL(*) problem)


reset_timer
        :       RESET reset_statement (',' reset_statement)*
                end
798
799
        ->      reset_statement+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
800
801
802
803


reset_statement
        :       timer_id ('(' expression_list ')')?
804
805
        ->      ^(RESET timer_id expression_list?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
806
807
808
809
810
811
812


transition_option
        :       ALTERNATIVE alternative_question e=end
                answer_part
                alternative_part
                ENDALTERNATIVE f=end
813
814
        ->      ^(ALTERNATIVE answer_part alternative_part)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
815
816
817
818
819
820


alternative_part
        :       (answer_part+ else_part?)
        ->      answer_part+ else_part?
                | else_part
821
822
        ->      else_part
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
823
824
825
826


alternative_question
        :       expression
827
828
                | informal_text
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
829
830
831
832
833
834
835
836
837
838


decision
        :       cif?
                hyperlink?
                DECISION question e=end
                answer_part?
                alternative_part?
                ENDDECISION f=end
        ->      ^(DECISION cif? hyperlink? $e? question
839
840
                answer_part? alternative_part?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
841
842
843
844
845
846


answer_part
        :       cif?
                hyperlink?
                L_PAREN answer R_PAREN ':' transition?
847
848
        ->      ^(ANSWER cif? hyperlink? answer transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
849
850
851
852


answer
        :       range_condition
853
854
                | informal_text
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
855
856
857
858
859
860


else_part
        :       cif?
                hyperlink?
                ELSE ':' transition?
861
862
        ->      ^(ELSE cif? hyperlink? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
863
864
865


question
866
867
        :       informal_text
                | expression
Maxime Perrotin's avatar
Maxime Perrotin committed
868
869
        ->      ^(QUESTION expression)
                | ANY
870
871
        ->      ^(ANY)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
872
873
874


range_condition
875
876
        :       (closed_range | open_range)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
877
878
879
880
                //(',' (closed_range|open_range))*;


closed_range
881
        :       a=expression ':' b=expression
882
883
        ->      ^(CLOSED_RANGE $a $b)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
884
885
886
887
888
889


open_range
        :       constant
        ->      constant
                | ( (EQ|NEQ|GT|LT|LE|GE) constant)
890
891
        ->      ^(OPEN_RANGE EQ? NEQ? GT? LT? LE? GE? constant)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
892
893
894
895


constant
        :       expression
896
897
        ->      ^(CONSTANT expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
898
899
900


create_request
dbarbera's avatar
dbarbera committed
901
        :       CREATE
Maxime Perrotin's avatar
Maxime Perrotin committed
902
903
904
                createbody
                actual_parameters?
                end
905
906
        ->      ^(CREATE createbody actual_parameters?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
907
908
909
910


createbody
        :       process_id
911
912
                | THIS
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
913
914
915
916
917
918


output
        :       cif?
                hyperlink?
                OUTPUT outputbody end
919
920
        ->      ^(OUTPUT cif? hyperlink? end? outputbody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
921
922
923


outputbody
924
        :       outputstmt (',' outputstmt)* to_part?
925
926
        ->      ^(OUTPUT_BODY outputstmt+ to_part?)
        ;
927
928
 //               via_part?
 //     -> (signal_id actual_parameters?)+ to_part? via_part?;
Maxime Perrotin's avatar
Maxime Perrotin committed
929
930
931


outputstmt
dbarbera's avatar
dbarbera committed
932
        :       signal_id
933
934
                actual_parameters?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
935

936
to_part
Maxime Perrotin's avatar
Maxime Perrotin committed
937
        :       (TO destination)
938
939
        ->      ^(TO destination)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
940

941
via_part
dbarbera's avatar
dbarbera committed
942
        :       VIA viabody
943
944
        ->      ^(VIA viabody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
945
946
947
948


// ambiguous in SDL92, added OR between ALL and via_path
viabody
dbarbera's avatar
dbarbera committed
949
        :       ALL
Maxime Perrotin's avatar
Maxime Perrotin committed
950
951
        ->      ^(ALL)
                | via_path
952
953
        ->      ^(VIAPATH via_path)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
954
955
956
957
958


destination
        :       pid_expression
                | process_id
959
960
                | THIS
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
961
962
963
964


via_path
        :       via_path_element (',' via_path_element)*
965
966
        ->      via_path_element+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
967
968
969


via_path_element
970
971
        :       ID
        ; // signal_route_id | channel_id | gate_id;
Maxime Perrotin's avatar
Maxime Perrotin committed
972
973
974
975


actual_parameters
        :      '(' expression (',' expression)* ')'
976
977
        ->     ^(PARAMS expression+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
978
979
980
981
982


task
        :       cif?
                hyperlink?
983
                TASK task_body? end
984
985
        ->      ^(TASK cif? hyperlink? end? task_body?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
986
987
988
989
990
991
992
993
994
995
996


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

997

Maxime Perrotin's avatar
Maxime Perrotin committed
998
999
// SDL extension - FOR loop in TASKs
forloop
1000
        :       FOR variable_id IN (range | variable) ':'
Maxime Perrotin's avatar
Maxime Perrotin committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
                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
1019
        :       postfix_expression
dbarbera's avatar
dbarbera committed
1020
1021
        |       ID                     ->  ^(VARIABLE ID);

Maxime Perrotin's avatar
Maxime Perrotin committed
1022
1023
1024
1025

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

1026

dbarbera's avatar
dbarbera committed
1027
expression
1028
1029
        :       binary_expression;

1030

1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
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)*;

1044

1045
unary_expression
1046
1047
        :       postfix_expression
        |       primary_expression
1048
        |       NOT^ unary_expression
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
        |       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)
                )+
        ;

1060
1061
1062

primary_expression
        :       primary                       -> ^(PRIMARY primary)
1063
        |       '(' expression ')'            -> ^(PAREN expression)
1064
        |       conditional_expression
1065
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1066

1067

1068
primary
1069
        :       TRUE^
Maxime Perrotin's avatar
Maxime Perrotin committed
1070
        |       FALSE^
1071
        |       STRING
Maxime Perrotin's avatar
Maxime Perrotin committed
1072
1073
1074
        |       NULL^
        |       PLUS_INFINITY^
        |       MINUS_INFINITY^
1075
1076
        |       INT^
        |       FLOAT^
1077
        |       ID ':' expression           -> ^(CHOICE ID expression)
dbarbera's avatar
dbarbera committed
1078
        |       ID                          -> ^(VARIABLE ID)
1079
1080
        |       '{' '}'                     -> ^(EMPTYSTR)
        |       '{'
Maxime Perrotin's avatar
Maxime Perrotin committed
1081
1082
                MANTISSA mant=INT COMMA
                BASE bas=INT COMMA
dbarbera's avatar
dbarbera committed
1083
                EXPONENT exp=INT
1084
1085
                '}'                         -> ^(FLOAT2 $mant $bas $exp)
        |       '{'
1086
1087
                named_value (COMMA named_value)*
                '}'                         -> ^(SEQUENCE named_value+)
1088
        |       '{'
1089
1090
                primary (COMMA primary)*
                '}'                         -> ^(SEQOF primary+)
1091
        |       STATE^
Maxime Perrotin's avatar
Maxime Perrotin committed
1092
1093
        ;

1094

Maxime Perrotin's avatar
Maxime Perrotin committed
1095
informal_text
1096
        :        STRING
1097
1098
        ->       ^(INFORMAL_TEXT STRING)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1099
1100
1101


// { a 5 } (SEQUENCE field value)
1102
named_value
1103
1104
        :       ID expression
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1105
1106
1107
1108
1109
1110


primary_params
        :      '(' expression_list ')'
        ->     ^(PARAMS expression_list)
               | '!' literal_id
1111
1112
        ->     ^(FIELD_NAME literal_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1113
1114


dbarbera's avatar
dbarbera committed
1115
/* All cases are covered by the ground primary
Maxime Perrotin's avatar
Maxime Perrotin committed
1116
1117
1118
1119
1120
   above (Except structure primary, but we favour ASN.1 notation)
extended_primary
        :       synonym         |
                indexed_primary |
                field_primary   |
1121
1122
                structure_primary
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1123
1124
1125
1126
*/


indexed_primary
1127
1128
        :       primary '(' expression_list ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1129
1130
1131


field_primary
1132
1133
        :       primary field_selection
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1134
1135
1136


structure_primary
1137
1138
        :       '(.' expression_list '.)'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1139
1140
1141
1142
1143
// Removed "qualifier" from the standard
// (to be put later, but never used in practice)


active_expression
1144
1145
        :       active_primary
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1146
1147
1148
1149
1150
1151
1152
1153


active_primary
        :       variable_access
                | operator_application
                | conditional_expression
                | imperative_operator
                | '(' active_expression ')'
1154
1155
                | 'ERROR'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1156
1157
1158
1159
1160
1161
1162
1163
1164
   // active_extended_primary removed because not defined in the standard


imperative_operator
        :       now_expression
                | import_expression
                | pid_expression
                | view_expression
                | timer_active_expression
1165
1166
                | anyvalue_expression
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1167
1168
1169


timer_active_expression
1170
1171
        :       ACTIVE '(' timer_id ('(' expression_list ')')? ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1172
1173
1174


anyvalue_expression
1175
1176
        :       ANY '(' sort ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1177
1178
1179


sort    :       sort_id
1180
1181
1182
        ->      ^(SORT sort_id)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
1183

1184
1185
type_inst
        :       type_id
1186
1187
        ->      ^(TYPE_INSTANCE type_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1188

1189
1190
1191

syntype :       syntype_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1192
1193
1194


import_expression
1195
1196
        :       IMPORT '(' remote_variable_id (',' destination)? ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1197
1198
1199


view_expression
1200
1201
        :       VIEW '(' view_id (',' pid_expression)? ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1202
1203
1204


variable_access
1205
1206
        :       variable_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1207
1208
1209


operator_application
1210
1211
        :       operator_id '('active_expression_list ')'
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1212
1213


dbarbera's avatar
dbarbera committed
1214
active_expression_list
1215
1216
1217
        :       active_expression (',' expression_list)?
        ;
/* |
Maxime Perrotin's avatar
Maxime Perrotin committed
1218
1219
1220
                ground_expression ',' active_expression_list;*/   // Will not work (recursion)


1221
//synonym :       ID; // synonym_id | external_synonym;
Maxime Perrotin's avatar
Maxime Perrotin committed
1222
1223

external_synonym
1224
1225
        :       external_synonym_id
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1226
1227


1228
conditional_expression
Maxime Perrotin's avatar
Maxime Perrotin committed
1229
1230
1231
        :       IF ifexpr=expression
                THEN thenexpr=expression
                ELSE elseexpr=expression FI
1232
1233
        ->      ^(CONDITIONAL $ifexpr $thenexpr $elseexpr)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1234
1235


dbarbera's avatar
dbarbera committed
1236
expression_list
Maxime Perrotin's avatar
Maxime Perrotin committed
1237
        :       expression (',' expression)*
1238
1239
        ->      expression+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1240
1241
1242
1243
1244
1245
1246
1247


terminator_statement
        :       label?
                cif?
                hyperlink?
                terminator
                end
1248
1249
        ->      ^(TERMINATOR label? cif? hyperlink? end? terminator)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1250
1251
1252

label
        :       cif? connector_name ':'
1253
1254
        ->      ^(LABEL cif? connector_name)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1255
1256
1257


terminator
1258
1259
        :       nextstate | join | stop | return_stmt
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1260
1261
1262
1263


join
        :        JOIN connector_name
1264
1265
        ->       ^(JOIN connector_name)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1266
1267


1268
1269
stop    :       STOP
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1270
1271
1272
1273


return_stmt
        :       RETURN expression?
1274
1275
        ->      ^(RETURN expression?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1276
1277
1278
1279


nextstate
        :       NEXTSTATE nextstatebody
1280
1281
        ->      ^(NEXTSTATE nextstatebody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1282
1283
1284


nextstatebody
1285
        :       statename via?
1286
1287
                | dash_nextstate
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1288
1289


1290
via     :       VIA state_entry_point_name
1291
1292
        ->      ^(VIA state_entry_point_name)
        ;
1293
1294


Maxime Perrotin's avatar
Maxime Perrotin committed
1295
end
1296
        :   (cif? hyperlink? COMMENT STRING)? SEMI+
1297
1298
        -> ^(COMMENT cif? hyperlink? STRING)?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1299
1300
1301
1302
1303
1304


cif
        :       cif_decl symbolname
                L_PAREN x=INT COMMA y=INT R_PAREN
                COMMA
dbarbera's avatar
dbarbera committed
1305
                L_PAREN width=INT COMMA height=INT R_PAREN
Maxime Perrotin's avatar
Maxime Perrotin committed
1306
                cif_end
1307
1308
        ->      ^(CIF $x $y $width $height)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
1309
1310
1311


hyperlink
1312
        :       cif_decl KEEP SPECIFIC GEODE HYPERLINK STRING
Maxime Perrotin's avatar
Maxime Perrotin committed
1313
                cif_end