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


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

262

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

271
272
273

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

Maxime Perrotin's avatar
Maxime Perrotin committed
277

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

292
293
294
295
296
297
298
// Procedure result / optional return type
procedure_result
        :       ('->' | RETURNS)
                variable_id?
                sort
        ->      ^(RETURNS variable_id? sort)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
299
300
301
302
303

// Procedure formal parameters
fpar
        :       FPAR formal_variable_param
                (',' formal_variable_param)*
304
                end?
305
306
        ->      ^(FPAR formal_variable_param+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
307
308
309


formal_variable_param
310
        :       (INOUT | IN | OUT)?
Maxime Perrotin's avatar
Maxime Perrotin committed
311
                variable_id (',' variable_id)* sort
312
313
        ->      ^(PARAM INOUT? IN? OUT? variable_id+ sort)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
314
315
316
317
318
319
320


// text_area: TODO add operator description in content
text_area
        :       cif
                content?
                cif_end_text
321
322
        ->      ^(TEXTAREA cif content? cif_end_text)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
323
324
325
326
327
328


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


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

Maxime Perrotin's avatar
Maxime Perrotin committed
351

352
syntype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
353
354
355
        :       SYNTYPE syntype_name '=' parent_sort
                (CONSTANTS (range_condition (',' range_condition)* ))?
                ENDSYNTYPE syntype_name? end
356
357
358
        ->      ^(SYNTYPE syntype_name parent_sort range_condition*)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
359
360

syntype_name
361
362
363
        :       sort
        ;

364
365

parent_sort
366
367
368
        :       sort
        ;

369
370

newtype_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
371
372
        :       NEWTYPE type_name (array_definition|structure_definition)?
                ENDNEWTYPE type_name? end
373
374
        ->      ^(NEWTYPE type_name array_definition* structure_definition*)
        ;
375
376
377


type_name
378
379
380
        :       sort
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
381

382
array_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
383
        :       ARRAY '(' sort ',' sort ')'
384
385
386
        ->      ^(ARRAY sort sort)
        ;

387
388

structure_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
389
        :       STRUCT field_list end
390
391
392
        ->      ^(STRUCT field_list)
        ;

393
394

field_list
Maxime Perrotin's avatar
Maxime Perrotin committed
395
        :       field_definition (end field_definition)*
396
397
398
        ->      ^(FIELDS field_definition+)
        ;

399
400

field_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
401
        :       field_name (',' field_name)* sort
402
403
404
        ->      ^(FIELD field_name+ sort)
        ;

405

Maxime Perrotin's avatar
Maxime Perrotin committed
406
407
408
409
variable_definition
        :       DCL variables_of_sort
                (',' variables_of_sort)*
                end
410
411
412
        ->      ^(DCL variables_of_sort+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
413

Maxime Perrotin's avatar
Maxime Perrotin committed
414
synonym_definition
415
416
417
        :       internal_synonym_definition
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
418

419
internal_synonym_definition
Maxime Perrotin's avatar
Maxime Perrotin committed
420
421
        :       SYNONYM synonym_definition_item (',' synonym_definition_item)*
                end
422
423
424
        ->      ^(SYNONYM_LIST synonym_definition_item+)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
425

426
synonym_definition_item
Maxime Perrotin's avatar
Maxime Perrotin committed
427
        :       sort sort '=' ground_expression
428
429
430
        ->      ^(SYNONYM sort sort ground_expression)
        ;

Maxime Perrotin's avatar
Maxime Perrotin committed
431
432
433

variables_of_sort
        :       variable_id (',' variable_id)* sort (':=' ground_expression)?
434
435
        ->      ^(VARIABLES variable_id+ sort ground_expression?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
436
437
438
439


ground_expression
        :       expression
440
441
        ->      ^(GROUND expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
442
443
444
445


number_of_instances
        :       '(' initial_number=INT ',' maximum_number=INT ')'
446
447
        ->      ^(NUMBER_OF_INSTANCES $initial_number $maximum_number)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
448
449
450


processBody
451
452
        :       start? (state | floating_label)*
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
453
454
455
456
457


start
        :       cif?
                hyperlink?
458
                START name=state_entry_point_name? end
Maxime Perrotin's avatar
Maxime Perrotin committed
459
                transition?
460
461
        ->      ^(START cif? hyperlink? $name? end? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
462
463
464
465
466
467
468
469
470


floating_label
        :       cif?
                hyperlink?
                CONNECTION connector_name ':'
                transition?
                cif_end_label?
                ENDCONNECTION SEMI
471
472
        ->      ^(FLOATING_LABEL cif? hyperlink? connector_name transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
473
474
475


state
476
        :       cif?
Maxime Perrotin's avatar
Maxime Perrotin committed
477
478
479
480
                hyperlink?
                STATE statelist e=end
                (state_part)*
                ENDSTATE statename? f=end
481
482
        ->      ^(STATE cif? hyperlink? $e? statelist state_part*)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
483
484
485
486


statelist
        :       ((statename)(',' statename)*)
487
        ->      ^(STATELIST statename+)
Maxime Perrotin's avatar
Maxime Perrotin committed
488
                | ASTERISK exception_state?
489
490
        ->      ^(ASTERISK exception_state?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
491
492
493


exception_state
494
        :       '(' statename (',' statename)* ')'
495
496
        ->      statename+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
497
498


499
// 11.11 State Machine and Composite State (SDL2000)
500
composite_state
501
502
503
504
505
506
        :       composite_state_graph
                | state_aggregation
        ;


composite_state_graph
507
508
        :       STATE statename e=end
                SUBSTRUCTURE
509
                connection_points*
510
511
                body=composite_state_body
                ENDSUBSTRUCTURE statename? f=end
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
        ->      ^(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)+
538
                state*
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
566
        ;


// 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?)
        ;
567
568


569
// 11.11.1 and 11.11.2 Composite State (SDL2000)
570
connection_points
571
572
573
        :       IN state_entry_exit_points end
        ->      ^(IN state_entry_exit_points end?)
                | OUT state_entry_exit_points end
574
575
        ->      ^(OUT state_entry_exit_points end?)
        ;
576
577


578
// 11.11.1 and 11.11.2 Composite State (SDL2000)
579
580
state_entry_exit_points
        :       '(' statename (',' statename)* ')'
581
582
        ->      statename+
        ;
583
584


585
// 11.11.1 Composite State graph content (SDL2000)
586
587
composite_state_body
        :       (text_area | procedure | composite_state)*
588
589
                start* (state | floating_label)*
        ;
590
591


Maxime Perrotin's avatar
Maxime Perrotin committed
592
593
594
595
596
state_part
        :       input_part
                //| priority_input        // Not supported
                | save_part               // Not supported in openGEODE
                | spontaneous_transition
597
                | continuous_signal
598
599
                | connect_part
        ;
600
601
602
603


// connect part is used to connect nested state exit points to a transition
connect_part
Maxime Perrotin's avatar
Maxime Perrotin committed
604
605
606
607
        :       cif?
                hyperlink?
                CONNECT connect_list? end
                transition?
608
609
        ->      ^(CONNECT cif? hyperlink? connect_list? end? transition?)
        ;
610
611
612
613
614


connect_list
        :       state_exit_point_name (',' state_exit_point_name)*
                -> state_exit_point_name+
615
616
                | ASTERISK
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
617
618
619
620
621
622
623
624


spontaneous_transition
        :       cif?
                hyperlink?
                INPUT NONE end
                enabling_condition?
                transition
625
626
        ->      ^(INPUT_NONE cif? hyperlink? transition)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
627
628
629
630


enabling_condition
        :       PROVIDED expression end
631
632
        ->      ^(PROVIDED expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
633
634
635


continuous_signal
636
637
638
639
        :       cif?
                hyperlink?
                PROVIDED expression e=end
                (PRIORITY p=INT end)?
640
641
                transition?
        ->      ^(PROVIDED expression cif? hyperlink? $p? $e? transition?)
642
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
643
644
645
646
647


save_part
        :       SAVE save_list
                end
648
649
        ->      ^(SAVE save_list)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
650
651
652
653


save_list
        :       signal_list
654
655
                | asterisk_save_list
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
656
657
658
659
660
661
662
663


asterisk_save_list
        :       ASTERISK;


signal_list
        :       signal_item (',' signal_item)*
664
665
        ->      ^(SIGNAL_LIST signal_item+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
666
667
668
669
670
671
672
673
674
675
676



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


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
695
696
                INPUT inputlist end
                enabling_condition?
Maxime Perrotin's avatar
Maxime Perrotin committed
697
698
                transition?
        ->      ^(INPUT cif? hyperlink? end?
699
700
                inputlist enabling_condition? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
701
702
703
704
705
706
707


// asterisk means: all signals not excplicitely specified
// (semantic is different from asterisk state)
inputlist
        :       ASTERISK
                | (stimulus (',' stimulus)*)
708
709
        ->      ^(INPUTLIST stimulus+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
710
711
712


stimulus
713
714
        :       stimulus_id input_params?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
715
716
717
718


input_params
        :       L_PAREN variable_id (',' variable_id)* R_PAREN
719
720
        ->      ^(PARAMS variable_id+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
721
722
723
724
725
726


transition
        :       action+ label? terminator_statement?
        ->      ^(TRANSITION action+ label? terminator_statement?)
                | terminator_statement
727
728
        ->      ^(TRANSITION terminator_statement)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
729
730
731
732
733
734
735
736
737
738
739
740
741


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

Maxime Perrotin's avatar
Maxime Perrotin committed
745
746
747
748
749

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

Maxime Perrotin's avatar
Maxime Perrotin committed
753
754
755

/*
remote_procedure_call
dbarbera's avatar
dbarbera committed
756
        :       CALL remote_procedure_call_body;
Maxime Perrotin's avatar
Maxime Perrotin committed
757
758

remote_procedure_call_body
dbarbera's avatar
dbarbera committed
759
        :       remote_procedure_id actual_parameters? (TO destination)?;
Maxime Perrotin's avatar
Maxime Perrotin committed
760
761
762
763
764
*/
procedure_call
        :       cif?
                hyperlink?
                CALL procedure_call_body end
765
766
        ->      ^(PROCEDURE_CALL cif? hyperlink? end? procedure_call_body)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
767
768
769


procedure_call_body
dbarbera's avatar
dbarbera committed
770
        :       procedure_id actual_parameters?
771
772
        ->      ^(OUTPUT_BODY procedure_id actual_parameters?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
773
774
775
776
777


set_timer
        :       SET set_statement (COMMA set_statement)*
                end
778
779
        ->      set_statement+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
780
781
782
783


set_statement
        :       L_PAREN (expression COMMA)? timer_id R_PAREN
784
785
        ->      ^(SET expression? timer_id)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
786
787
788
789
790
791
        // ('('expression_list')')? ')'; (removed because of non-LL(*) problem)


reset_timer
        :       RESET reset_statement (',' reset_statement)*
                end
792
793
        ->      reset_statement+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
794
795
796
797


reset_statement
        :       timer_id ('(' expression_list ')')?
798
799
        ->      ^(RESET timer_id expression_list?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
800
801
802
803
804
805
806


transition_option
        :       ALTERNATIVE alternative_question e=end
                answer_part
                alternative_part
                ENDALTERNATIVE f=end
807
808
        ->      ^(ALTERNATIVE answer_part alternative_part)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
809
810
811
812
813
814


alternative_part
        :       (answer_part+ else_part?)
        ->      answer_part+ else_part?
                | else_part
815
816
        ->      else_part
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
817
818
819
820


alternative_question
        :       expression
821
822
                | informal_text
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
823
824
825
826
827
828
829
830
831
832


decision
        :       cif?
                hyperlink?
                DECISION question e=end
                answer_part?
                alternative_part?
                ENDDECISION f=end
        ->      ^(DECISION cif? hyperlink? $e? question
833
834
                answer_part? alternative_part?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
835
836
837
838
839
840


answer_part
        :       cif?
                hyperlink?
                L_PAREN answer R_PAREN ':' transition?
841
842
        ->      ^(ANSWER cif? hyperlink? answer transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
843
844
845
846


answer
        :       range_condition
847
848
                | informal_text
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
849
850
851
852
853
854


else_part
        :       cif?
                hyperlink?
                ELSE ':' transition?
855
856
        ->      ^(ELSE cif? hyperlink? transition?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
857
858
859


question
860
861
        :       informal_text
                | expression
Maxime Perrotin's avatar
Maxime Perrotin committed
862
863
        ->      ^(QUESTION expression)
                | ANY
864
865
        ->      ^(ANY)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
866
867
868


range_condition
869
870
        :       (closed_range | open_range)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
871
872
873
874
                //(',' (closed_range|open_range))*;


closed_range
875
        :       a=expression ':' b=expression
876
877
        ->      ^(CLOSED_RANGE $a $b)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
878
879
880
881
882
883


open_range
        :       constant
        ->      constant
                | ( (EQ|NEQ|GT|LT|LE|GE) constant)
884
885
        ->      ^(OPEN_RANGE EQ? NEQ? GT? LT? LE? GE? constant)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
886
887
888
889


constant
        :       expression
890
891
        ->      ^(CONSTANT expression)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
892
893
894


create_request
dbarbera's avatar
dbarbera committed
895
        :       CREATE
Maxime Perrotin's avatar
Maxime Perrotin committed
896
897
898
                createbody
                actual_parameters?
                end
899
900
        ->      ^(CREATE createbody actual_parameters?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
901
902
903
904


createbody
        :       process_id
905
906
                | THIS
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
907
908
909
910
911
912


output
        :       cif?
                hyperlink?
                OUTPUT outputbody end
913
914
        ->      ^(OUTPUT cif? hyperlink? end? outputbody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
915
916
917


outputbody
918
        :       outputstmt (',' outputstmt)* to_part?
919
920
        ->      ^(OUTPUT_BODY outputstmt+ to_part?)
        ;
921
922
 //               via_part?
 //     -> (signal_id actual_parameters?)+ to_part? via_part?;
Maxime Perrotin's avatar
Maxime Perrotin committed
923
924
925


outputstmt
dbarbera's avatar
dbarbera committed
926
        :       signal_id
927
928
                actual_parameters?
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
929

930
to_part
Maxime Perrotin's avatar
Maxime Perrotin committed
931
        :       (TO destination)
932
933
        ->      ^(TO destination)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
934

935
via_part
dbarbera's avatar
dbarbera committed
936
        :       VIA viabody
937
938
        ->      ^(VIA viabody)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
939
940
941
942


// ambiguous in SDL92, added OR between ALL and via_path
viabody
dbarbera's avatar
dbarbera committed
943
        :       ALL
Maxime Perrotin's avatar
Maxime Perrotin committed
944
945
        ->      ^(ALL)
                | via_path
946
947
        ->      ^(VIAPATH via_path)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
948
949
950
951
952


destination
        :       pid_expression
                | process_id
953
954
                | THIS
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
955
956
957
958


via_path
        :       via_path_element (',' via_path_element)*
959
960
        ->      via_path_element+
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
961
962
963


via_path_element
964
965
        :       ID
        ; // signal_route_id | channel_id | gate_id;
Maxime Perrotin's avatar
Maxime Perrotin committed
966
967
968
969


actual_parameters
        :      '(' expression (',' expression)* ')'
970
971
        ->     ^(PARAMS expression+)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
972
973
974
975
976


task
        :       cif?
                hyperlink?
977
                TASK task_body? end
978
979
        ->      ^(TASK cif? hyperlink? end? task_body?)
        ;
Maxime Perrotin's avatar
Maxime Perrotin committed
980
981
982
983
984
985
986
987
988
989
990


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

991

Maxime Perrotin's avatar
Maxime Perrotin committed
992
993
// SDL extension - FOR loop in TASKs
forloop
994
        :       FOR variable_id IN (range | variable) ':'
Maxime Perrotin's avatar
Maxime Perrotin committed
995
996
997
998
999
1000
                transition?
                ENDFOR
        ->      ^(FOR variable_id variable? range? transition?);

range
        :       RANGE
For faster browsing, not all history is shown. View entire blame