added fleet api classes
[fleet.git] / src / edu / berkeley / fleet / parser / 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:: (Brack:: "[" (int|(Star::"*"))? ("r")? "]" ws!)? (Command +/ (ws! "," ws!) ws! ";"!)
21 Command         = Kill::    "kill"
22                 | Wait::    "wait"
23                 | Discard:: "discard"
24                 | Take::    "take"
25                 | SendTo::  "sendto" ws! Port
26                 | Deliver:: "deliver"
27                 | Ack::     "ack" ws! Port
28
29 Source         = Port
30                | CodeBag
31                | ShipSpecific
32
33 Port           = Port::     shipname "." portname
34                |           ^"()"
35
36 CodeBagBody    = Statement +/ (ws (";" ws)?!)
37 CodeBag        = CodeBagRef:: CodeBagName
38                | AnonymousCodeBag:: "{" CodeBagBody "}" /ws
39
40 CodeBagName    = name
41 shipname       = name
42 portname       = name
43 name           = Name:: [A-Za-z] [A-Za-z0-9\[\]_]**
44 index          = "[" [0-9]+ "]" | [0-9]+
45 int            = [\-0-9]++
46 ShipSpecific   = ShipSpecific:: "\"" ~[\"]++ "\""
47
48 // the following are not part of the official FLEET syntax and are
49 // specific to Adam's interpreter.
50
51 Directive      = Memory::  "#memory" "{" (int +/ (ws! "," ws!)) "}" /ws
52                | Import::  "#import" [A-Za-z_.]++ /ws
53                | Include:: "#include" ("\"" (~[\"])+ "\"") /ws
54                | Ship::    "#ship" shipname ":" [0-9A-Za-z_.]++ /ws
55