736d4ae31834c22923bc87aef9d52b75ac63d39b
[fleet.git] / src / edu / berkeley / fleet / assembler / 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\r]* [\r\n]!
9                | "/*" ~[\n\r]* "*/"
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  ":" (Instruction +/ ws)     /ws
17                 | Literal::                int     ":" "sendto" Port       ";" /ws
18                 | CodeBagDescriptor::      CodeBag ":" "sendto" Port       ";" /ws
19                 | NamedCodeBag::           name    ":" "{" CodeBagBody "}"     /ws
20
21 CountField      = Brack::     "[" int "]"
22                 | Paren::     "(" int ")"
23                 | BrackStar:: "[*]"
24                 | ParenStar:: "(*)"
25 Instruction     = Instruction::
26                         (CountField ws!)?
27                         (Command +/ (ws! "," ws!) ws! ";"!)
28 Command         = Nop::      "nop"
29                 | Kill::     "kill"
30                 | KillStar:: "kill*"
31                 | Wait::     "wait"
32                 | Discard::  "dismiss"
33                 | Take::     ("take"|"receive")
34                 | SendTo::   "sendto" ws! Port
35                 | Deliver::  "deliver"
36                 | Ack::      "notify" ws! Port
37
38 Source         = Port
39                | ShipSpecific
40
41 Port           = Port::     shipname "." portname
42                |           ^"()"
43
44 CodeBagBody    = Statement +/ ws
45 CodeBag        = CodeBagRef:: CodeBagName
46                | AnonymousCodeBag:: "{" CodeBagBody "}" /ws
47
48 CodeBagName    = name
49 shipname       = name
50 portname       = name
51 name           = Name:: [A-Za-z] [A-Za-z0-9\[\]_]**
52 index          = "[" [0-9]+ "]" | [0-9]+
53 int            = [\-0-9]++
54 ShipSpecific   = ShipSpecific:: "\"" ~[\"]++ "\""
55
56 // the following are not part of the official FLEET syntax and are
57 // specific to Adam's interpreter.
58
59 Directive      = Memory::  "#memory" "{" (int +/ (ws! "," ws!)) "}" /ws
60                | Import::  "#import" [A-Za-z_.]++ /ws
61                | Include:: "#include" ("\"" (~[\"])+ "\"") /ws
62                | Ship::    "#ship" shipname ":" [0-9A-Za-z_.]++ /ws
63                | Expect::  "#expect" int /ws
64