c8917378d8e70cdcbdfcaf753241804648b39e18
[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                 | NamedCodeBag::           name    ":" "{" CodeBagBody "}"     /ws
18
19 CountField      = Brack::     "[" int "]"
20                 | Paren::     "(" int ")"
21                 | BrackStar:: "[*]"
22                 | ParenStar:: "(*)"
23 Instruction     = Instruction::
24                         ("":: (CountField ws!)?)
25                         ("":: Command +/ (ws! "," ws!) ws! ";"!)
26 Command         = Nop::      "nop"
27                 | Kill::     "kill"
28                 | KillStar:: "kill*"
29                 | Wait::     "wait"
30                 | Discard::           "dismiss"
31                 | Take::              ("take"|"receive")
32                 | SendTo::            "sendto" ws! Port
33                 | DataOutDest::       "send"
34                 | Deliver::           "deliver"
35                 | LocalLiteral::      "literal" ws! int
36                 | LocalLiteralConst:: "literal" ws! SSL
37                 | LocalLiteralCodeBag:: "literal" ws! CodeBag
38                 | Ack::               "notify" ws! Port
39
40 Source         = Port
41                | ShipSpecific
42
43 SSL            = ShipSpecificLiteral:: shiptype "." portname "[" SSLSpec "]"
44 Port           = Port::     shipname "." portname
45                | SubPort::  shipname "." portname "." portname
46                |           ^"()"
47
48 SSLSpec::      = SSLElement +/ ","
49 SSLElement     = "":: [a-zA-Z0-9=_\-]++
50
51 CodeBagBody::  = Statement +/ ws
52 CodeBag        = CodeBagRef:: CodeBagName
53                | AnonymousCodeBag:: "{" CodeBagBody "}" /ws
54
55 CodeBagName         = name
56 shipname            = name
57 shiptype            = Name:: [A-Z]    ("":: [A-Za-z0-9_]**)
58 ShipSpecificLiteral = Name:: [A-Z]    ("":: [A-Z0-9_]**)
59 portname            = Name:: [a-z]    ("":: [A-Za-z0-9_]**)
60 name                = Name:: [A-Za-z] ("":: [A-Za-z0-9_]**)
61 index               = "[" ("":: [0-9]+) "]" | ("":: [0-9]+)
62 int                 = "":: [\-0-9]++
63 ShipSpecific        = ShipSpecific:: "\"" (~[\"])++ "\""
64
65 // the following are not part of the official FLEET syntax and are
66 // specific to Adam's interpreter.
67
68 Directive      =           "#memory" "{" (Memory:: int +/ (ws! "," ws!)) "}" /ws
69                | Import::  "#import" [A-Za-z_.]++ /ws
70                | Include:: "#include" ws! "\"" ~[\"]+ "\""
71                | Ship::    "#ship" shipname ":" ("":: [0-9A-Za-z_.]++) /ws
72                | Expect::  "#expect" int /ws
73                | Skip::    "#skip"
74