cleanups, reorg, and commenting
[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        = Program::
19                     (Directive ws!)*
20                     CodeBagBody
21
22 Directive      = Memory::  "#memory" "{" (int +/ (ws! "," ws!)) "}" /ws
23                | Import::  "#import" [A-Za-z_.]++ /ws
24                | Ship::    "#ship" shipname ":" [A-Za-z_\.]++ /ws
25
26
27 Statement      = Move ((ws ";")?)!
28                | CodeBag
29 //             | ^"#define" Port Port                  /ws
30
31 Move           = Source       ^"->"  Destination        /ws
32                | Source       ^"->*" Destination        /ws
33                | Port         ^":="  Source             /ws
34
35 Destination    = Port +/ (ws! "," ws!)
36 Source         = Port
37                | CodeBag
38 CodeBagBody    = CodeBag:: (Statement +/ ws)
39 CodeBag        = NamedCodeBag::
40                      name:(name ws! ":" ws!)?
41                      "{"
42                            ws! statements:(Statement +/ ws) ws!
43                      "}"
44                      (ws! ";")?!
45
46 //Port           = Port::     shipname ("." portname)*
47 Port           = Port::     shipname "." portname
48                | Port::     shipname
49 shipname       = ShipName:: name (index?)
50 portname       = PortName:: name (index?)
51 name           = [A-Za-z0-9\[\]]**
52 index          = "[" [0-9]+ "]"
53                | [0-9]+
54 int            = [0-9]++
55