remove "looping" argument from Instruction
[fleet.git] / src / edu / berkeley / fleet / assembler / fleet.g
index cb8f76d..219fb21 100644 (file)
@@ -1,58 +1,83 @@
-// 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         = Program:: Directive+/ws
-                | Program:: (Directive+/ws) ws! CodeBagBody
-
-Statement       = Fiber::                  Source  ":" (Instruction +/ ws)     /ws
-                | Literal::                int     ":" "sendto" Port       ";" /ws
-                | CodeBagDescriptor::      CodeBag ":" "sendto" Port       ";" /ws
-                | NamedCodeBag::           name    ":" "{" CodeBagBody "}"     /ws
-
-Instruction     = Instruction::
-                        (Brack:: "[" (int|(Star::"*"))? ("r")? "]" ws!)?
-                        (Command +/ (ws! "," ws!) ws! ";"!)
-Command         = Nop::     "nop"
-                | Kill::    "kill"
-                | Wait::    "wait"
-                | Discard:: "discard"
-                | Take::    "take"
-                | SendTo::  "sendto" ws! Port
-                | Deliver:: "deliver"
-                | Ack::     "ack"    ws! Port
-
-Source         = Port
-               | ShipSpecific
-
-Port           = Port::     shipname "." portname
-               |           ^"()"
-
-CodeBagBody    = Statement +/ ws
-CodeBag        = CodeBagRef:: CodeBagName
-               | AnonymousCodeBag:: "{" CodeBagBody "}" /ws
-
-CodeBagName    = name
-shipname       = name
-portname       = name
-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
+s               = ws Program ws
+Program::       = Directives CodeBagBody /ws
+Directives::    = Directive */ ws
+CodeBagBody::   = (Fiber | CodeBagDef) */ ws
+CodeBagDef::    = CodeBagName ":" "{" CodeBagBody "}" /ws
+Fiber::         = Dock        ":" Instructions        /ws
 
+Instructions::  = Instruction +/ ws
+Instruction     = Instruction:: (Tags:: Tag*) InstructionX
+                | ^"head" ";" /ws
+                | ^"tail" ";" /ws
+Tag             = ^"[a]"  ws |  ^"[b]" ws
+                | ^"[!a]" ws | ^"[!b]" ws
+                | ^"[d]" ws
+                | ^"[*]" 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
+
+Flags:: = (^"0") |  (^"1") | (^"a" |  ^"b" |  ^"c" | ^"!a" | ^"!b" | ^"!c") +/ (ws "|" ws)
+
+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
+
+Literal         = int
+                | ShipType "." DockName ^"[" Constants "]"
+                | CodeBagName
+                | "{" CodeBagBody "}" /ws
+
+Dock::          = ShipName "." DockName
+Destination::   = ShipName "." DockName ( ^"" | ^":i" | ^":0" | ^":1" )
+Constants::     = Constant +/ ","
+Constant::      = [a-zA-Z0-9=_\-]++
+
+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]++)
+
+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"