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