-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCtrl.grammar
73 lines (55 loc) · 2.71 KB
/
Ctrl.grammar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
72
73
/* Main program. */
program : package_decl? import_decl* (function | recipe | stat)*
/* Package declaration. */
package_decl : 'package' qual_name ';'
/* Import statement. */
import_decl : 'import' qual_name ';'
/* Dot-separated sequence of identifiers. */
qual_name : ID ('.' ID)*
/* Recipe declaration, with optional priority. Behaves like a rule; its body is executed atomically. */
recipe : 'recipe' ID par_list ('priority' INT_LIT)? block
/* Function declaration. */
function : 'function' ID par_list block
/* Procedure formal parameter declaration list. */
par_list : '(' (par (',' par)*)? ')'
/* Procedure formal parameter declaration. */
par : 'out'? type ID
/* Statement block. */
block : '{' stat* '}'
/* Atomic statement. */
stat : block
| 'alap' stat // repeat stat as long as possible
| '<' stat+ '>' // do stat sequence atomically (as transaction)
| 'while' '(' cond ')' stat // try cond, on success do stat and repeat
| 'until' '(' cond ')' stat // try cond, on failure do stat and repeat
| 'do' stat 'while' '(' cond ')' // do stat then try cond; repeat on success
| 'do' stat 'until' '(' cond ')' // do stat then try cond; repeat on failure
| 'if' '(' cond ')' stat1 ('else' stat2)? // try cond, on success do stat1 else optional stat2
| 'try' stat1 ('else' stat2)? // try stat1, on failure do optional stat2
| 'choice' stat ('or' stat)+ // nondeterministically choose between stats
| expr ';' // do expr
| decl ';' // control variable declatation
/* Condition: limited form of expression. */
cond : cond1 '|' cond2
| 'true'
| call
/* Expression. */
expr : expr1 '|' expr2 // nondeterministic choice between exprs (see 'choice')
| expr '+' // nondeterministically repeat expr at least once
| expr '*' // nondeterministically repeat expr zero or more times
| '#' expr // repeat expr as long as possible (see 'alap')
| '(' expr ')'
| call
/* Rule, procedure or group call, with optional argument list. */
call : unit arg_list?
unit : (package '.')? name // optionally qualified rule or procedure
| (package '.')? ('*' '.')? ('any' | 'other') // optionally qualified group call
/* Argument list. */
arg_list : '(' (arg (',' arg)*)? ')'
/* Argument. */
arg : 'out'? ID | '_' | literal
literal : 'true' | 'false' | STRING_LIT | INT_LIT | REAL_LIT
/* Control variable declaration. */
decl : type ID (',' ID)*
/* Variable or argument type. */
type : 'node' | 'bool' | 'string' | 'int' | 'real'