update to AM15
[fleet.git] / fleet.g
1 // The FLEET Assembly Language Grammar
2 // Updated 05-Nov-2006
3
4 // Note that this is the *entire, complete* formal specification of
5 // the grammar.  An equivalent lex+yacc grammar and support code would
6 // be several times as long.
7
8 Comment        = "//" ~[\n]* "\n"
9                | "/*" ~[\n]* "*/"
10 ws             = ([\r\n ] | Comment)* -> ~[\r\n ]
11
12 s               = ws! Program ws!
13 Program         = Program:: Directive+/ws
14                 | Program:: (Directive+/ws) ws! CodeBagBody
15
16 Statement       = Fiber:: Source ws! ":" ws! (Instruction +/ ws)
17                 | Literal:: int ":" "sendto" Port /ws
18                 | NamedCodeBag:: name ":" "{" CodeBagBody "}" /ws
19
20 Instruction     = Instruction:: ("[" (int|(Star::"*")) "]" ws!)? (Command +/ (ws! "," ws!))
21 Command         = Wait::    "wait"
22                 | Discard:: "discard"
23                 | Take::    "take"
24                 | SendTo::  "sendto" ws! Port
25                 | Accept::  "accept"
26                 | Ack::     "ack" ws! Port
27
28 Source         = Port
29                | CodeBag
30                | ShipSpecific
31
32 Port           = Port::     shipname "." portname
33                |           ^"()"
34
35 CodeBagBody    = Statement +/ (ws (";" ws)?!)
36 CodeBag        = CodeBagRef:: CodeBagName
37                | AnonymousCodeBag:: "{" CodeBagBody "}" /ws
38
39 CodeBagName    = name
40 shipname       = name
41 portname       = name
42 name           = Name:: [A-Za-z] [A-Za-z0-9\[\]_]**
43 index          = "[" [0-9]+ "]" | [0-9]+
44 int            = [\-0-9]++
45 ShipSpecific   = ShipSpecific:: "\"" ~[\"]++ "\""
46
47 // the following are not part of the official FLEET syntax and are
48 // specific to Adam's interpreter.
49
50 Directive      = Memory::  "#memory" "{" (int +/ (ws! "," ws!)) "}" /ws
51                | Import::  "#import" [A-Za-z_.]++ /ws
52                | Include:: "#include" ("\"" (~[\"])+ "\"") /ws
53                | Ship::    "#ship" shipname ":" [0-9A-Za-z_.]++ /ws
54