checkpoint
[sbp.git] / tests / fleet.g
1 // The FLEET Assembly Language Grammar
2 // As specified in document 2005-ucies06
3
4 // comments are included where the grammar had to go beyond the strict
5 // "letter of the law" in ies06
6
7 // Note that this is the *entire, complete* formal specification of
8 // the grammar.  An equivalent lex+yacc grammar and support code would
9 // be several times as long.
10
11 Comment        = "//" ~[\n]* "\n"
12                | "/*" ~[\n]* "*/"
13
14 w             = [\r\n ]*
15 ws            = (w | Comment)* -> ~[\r\n ]
16
17 s              = !ws Program !ws
18 Program        = CodeBag:: statements:(Statement +/ ws)
19
20 Statement      = Move !((ws ";")?)
21                | CodeBag
22                | ^"#define" Port Port                  /ws
23
24 Move           = Source       ^"->"  Destination        /ws
25                | Source       ^"->*" Destination        /ws
26                | Port         ^":="  Source             /ws
27
28 Destination    = Port +/ (!ws "," !ws)
29 Source         = Port
30                | CodeBag
31
32 CodeBag        = CodeBag::
33                      name:(name !ws ":" !ws)?
34                      "{"
35                            !ws statements:(Statement +/ ws) !ws
36                      "}"
37                      (!ws ";")?
38
39 Port           = Port::     shipname ("." portname)*
40 shipname       = ShipName:: name index?
41 portname       = PortName:: name index?
42 name           = [A-Za-z0-9\[\]\.]**
43 index          = "[" [0-9]+ "]"
44                | [0-9]+