update to 03-Jan-2009 am33: head, abort, and d-flag
[fleet.git] / src / edu / berkeley / fleet / assembler / fleet.g
index 1d0041b..90f601d 100644 (file)
@@ -1,69 +1,84 @@
-// The FLEET Assembly Language Grammar
-// Updated 05-Nov-2006
+// The FLEET Assembly Language Grammar [22-Aug-2008]
 
 // Note that this is the *entire, complete* formal specification of
 // the grammar.  An equivalent lex+yacc grammar and support code would
 // be several times as long.
 
-Comment        = "//" (~[\n\r])* [\r\n]!
-               | "/*" (~[\n\r])* "*/"
-ws             = ([\r\n ] | Comment)* -> ~[\r\n ]
+s               = ws Program ws
+Program::       = Directives CodeBagBody /ws
+Directives::    = Directive */ ws
+CodeBagBody::   = (Fiber | CodeBagDef) */ ws
+CodeBagDef::    = CodeBagName ":" "{" CodeBagBody "}" /ws
+Fiber::         = Dock        ":" Instructions        /ws
 
-s               = ws! Program ws!
-Program         = Program:: Directive+/ws
-                | Program:: (Directive+/ws) ws! CodeBagBody
+Instructions::  = Instruction +/ ws
+Instruction     = Instruction:: (Tags:: Tag*) InstructionX
+                | ^"head" ";" /ws
+                | ^"tail" ";" /ws
+Tag             = ^"[a]"  ws |  ^"[b]" ws
+                | ^"[!a]" ws | ^"[!b]" ws
+                | ^"[d]" ws
+                | ^"[*]" ws
+                | ^"[Rq]" ws
+InstructionX    = (() | ^"[T]" ws) ^"nop"                                            ";" /ws
+                | (() | ^"[T]" ws)  (Commands:: Command +/ (ws "," ws))             ^";" /ws
+                | "olc=word"::      "set"  "olc" "=" "word"                          ";" /ws
+                | "ilc=word"::      "set"  "ilc" "=" "word"                          ";" /ws
+                | "olc=int"::       "set"  "olc" "=" int                             ";" /ws
+                | "ilc=int"::       "set"  "ilc" "=" int                             ";" /ws
+                |                   "set"  "ilc" "=" ^"*"                            ";" /ws
+                |                   "set"  "olc" ^"--"                               ";" /ws
+                |                   "set" ^"flags" "a" "=" Flags "," "b" "=" Flags   ";" /ws
+                |                   "set" ^"word"      "=" Literal                   ";" /ws
+                |              ^"shift" Literal                                      ";" /ws
+                |              ^"flush"                                              ";" /ws
+                |              ^"abort"                                              ";" /ws
 
-Statement       = Fiber::                  Source  ":" (Instruction +/ ws)     /ws
-                | Literal::                int     ":" "sendto" Port       ";" /ws
-                | ShipSpecificLiteral::    SSL     ":" "sendto" Port       ";" /ws
-                | CodeBagDescriptor::      CodeBag ":" "sendto" Port       ";" /ws
-                | NamedCodeBag::           name    ":" "{" CodeBagBody "}"     /ws
+Flags:: = (^"0") |  (^"1") | (^"a" |  ^"b" |  ^"c" | ^"!a" | ^"!b" | ^"!c") +/ (ws "|" ws)
 
-CountField      = Brack::     "[" int "]"
-                | Paren::     "(" int ")"
-                | BrackStar:: "[*]"
-                | ParenStar:: "(*)"
-Instruction     = Instruction::
-                        (CountField ws!)?
-                        (Command +/ (ws! "," ws!) ws! ";"!)
-Command         = Nop::      "nop"
-                | Kill::     "kill"
-                | KillStar:: "kill*"
-                | Wait::     "wait"
-                | Discard::  "dismiss"
-                | Take::     ("take"|"receive")
-                | SendTo::   "sendto" ws! Port
-                | Deliver::  "deliver"
-                | Ack::      "notify" ws! Port
+Command         = "recv token"::       "recv" ws "token"
+                |                     ^"recv"
+                | "recv"::             "recv" ws "word"
+                | "recv nothing"::     "recv" ws "nothing"
+                | "recv path"::        "recv" ws "path"
+                | "recv packet"::      "recv" ws "packet"
+                |                     ^"collect"
+                | "collect"::          "collect" ws "word"
+                | "collect nothing"::  "collect" ws "nothing"
+                | "collect path"::     "collect" ws "path"
+                | "collect packet"::   "collect" ws "packet"
+                |                     ^"deliver"
+                |                     ^"send"
+                | "send to"::          "send" "to"          Destination /ws
+                | "send token"::       "send" "token"       Destination /ws
+                | "send token to"::    "send" "token" "to"  Destination /ws
 
-Source         = Port
-               | ShipSpecific
+Literal         = int
+                | ShipType "." DockName ^"[" Constants "]"
+                | CodeBagName
+                | "{" CodeBagBody "}" /ws
 
-SSL            = ShipSpecificLiteral:: shiptype "." ShipSpecificLiteral
-Port           = Port::     shipname "." portname
-               | SubPort::  shipname "." portname "." portname
-               |           ^"()"
+Dock::          = ShipName "." DockName
+Destination::   = ShipName "." DockName ( ^"" | ^":i" | ^":0" | ^":1" )
+Constants::     = Constant +/ ","
+Constant::      = [a-zA-Z0-9=_\-]++
 
-CodeBagBody    = Statement +/ ws
-CodeBag        = CodeBagRef:: CodeBagName
-               | AnonymousCodeBag:: "{" CodeBagBody "}" /ws
+CodeBagName     = UpcaseWord
+ShipType        = UpcaseWord
+ShipName        = DowncaseWord
+DockName        = DowncaseWord
+Word            = UpcaseWord | DowncaseWord
+UpcaseWord      = Name:: [A-Z]    ("":: [A-Za-z0-9_]**)
+DowncaseWord    = Name:: [a-z]    ("":: [A-Za-z0-9_]**)
+int::           = (^"-"|^"") (^"0x"|^"0b"|^"") (digits:: [0-9A-Fa-f]++)
 
-CodeBagName         = name
-shipname            = name
-shiptype            = Name:: [A-Z] [A-Za-z0-9\[\]_]**
-ShipSpecificLiteral = Name:: [A-Z] [A-Z0-9\[\]_]**
-portname            = Name:: [a-z] [A-Za-z0-9\[\]_]**
-name                = Name:: [A-Za-z] [A-Za-z0-9\[\]_]**
-index               = "[" [0-9]+ "]" | [0-9]+
-int                 = [\-0-9]++
-ShipSpecific        = ShipSpecific:: "\"" (~[\"])++ "\""
-
-// the following are not part of the official FLEET syntax and are
-// specific to Adam's interpreter.
-
-Directive      = Memory::  "#memory" "{" (int +/ (ws! "," ws!)) "}" /ws
-               | Import::  "#import" [A-Za-z_.]++ /ws
-               | Include:: "#include" ("\"" (~[\"])+ "\"") /ws
-               | Ship::    "#ship" shipname ":" [0-9A-Za-z_.]++ /ws
-               | Expect::  "#expect" int /ws
+ws!             = wsx -> ~[\r\n ]
+wsx!            = ()
+                | wsx [\r\n ]
+                | wsx Comment
+Comment!        = "//" ~[\n\r]* [\r\n]
+                | "/*" ~[\n\r]* "*/"
 
+Directive      = ^"#ship" ShipName ":" ("":: [0-9A-Za-z_.]++) /ws
+               | ^"#expect" int /ws
+               | ^"#skip"