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