implement support (fpga+interp+test) for massacre instruction
[fleet.git] / src / edu / berkeley / fleet / assembler / fleet.g
index 6d6fed0..463a1ba 100644 (file)
@@ -1,60 +1,71 @@
-// The FLEET Assembly Language Grammar
-// Updated 05-Nov-2006
+// The FLEET Assembly Language Grammar [26-Aug-2007]
 
 // 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"
-                | KillStar:: "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
-               | Expect::  "#expect" int /ws
+s               = ws Program ws
+Program::       = Directives CodeBagBody /ws
+Directives::    = Directive */ ws
+CodeBagBody::   = (Fiber | CodeBagDef) */ ws
+CodeBagDef::    = CodeBagName ":" "{" CodeBagBody "}" /ws
+Fiber::         = Pump        ":" Instructions        /ws
 
+Instructions::  = Instruction +/ ws
+Instruction     = ^"unclog"                          ";" /ws
+                | ^"clog"                            ";" /ws
+                | ^"massacre"                        ";" /ws
+                | ^"kill"                            ";" /ws
+                | ^"kill"     int                    ";" /ws
+                | ^"literal"  Literal  RequeueCount  ";" /ws
+                | RepeatCount Commands RequeueCount ^";" /ws
+RepeatCount     = "" | ^"[*]" | "[" int "]"
+RequeueCount    = ""
+                | "," "requeue" (^"forever" | int ws "times") /ws
+
+Commands::      = Command +/ (ws "," ws)
+Command         = ^"wait"
+                | ^"nop"
+                | ^"discard"
+                | ^"recieve"
+                | ^"take"
+                | ^"deliver"
+                | ^"send"
+                | ^"sendto"     Destination /ws
+                | ^"notify"     Destination /ws
+                | ^"notifyLast" Destination /ws
+
+Literal         = int
+                | ShipType "." PortName ^"[" Constants "]"
+                | CodeBagName
+                | "{" CodeBagBody "}" /ws
+
+Pump::          = ShipName "." PortName
+Destination::   = ShipName "." PortName
+Constants::     = Constant +/ ","
+Constant::      = [a-zA-Z0-9=_\-]++
+
+CodeBagName     = UpcaseWord
+ShipType        = UpcaseWord
+ShipName        = DowncaseWord
+PortName        = 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-9]++)
+
+ws!             = wsx -> ~[\r\n ]
+wsx!            = ()
+                | wsx [\r\n ]
+                | wsx Comment
+Comment!        = "//" ~[\n\r]* [\r\n]
+                | "/*" ~[\n\r]* "*/"
+
+// the following extensions are not part of the official FLEET syntax
+
+Directive      = ^"#memory" "{" (Memory:: int +/ (ws! "," ws!)) "}" /ws
+               | ^"#import" [A-Za-z_.]++ /ws
+               | ^"#include" ws! "\"" ~[\"]+ "\""
+               | ^"#ship" ShipName ":" ("":: [0-9A-Za-z_.]++) /ws
+               | ^"#expect" int /ws
+               | ^"#skip"