implement support (fpga+interp+test) for massacre instruction
[fleet.git] / src / edu / berkeley / fleet / assembler / fleet.g
index f73a0fe..463a1ba 100644 (file)
@@ -1,71 +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::       = Directives CodeBagBody /ws
+Directives::    = Directive */ ws
+CodeBagBody::   = (Fiber | CodeBagDef) */ ws
+CodeBagDef::    = CodeBagName ":" "{" CodeBagBody "}" /ws
+Fiber::         = Pump        ":" Instructions        /ws
 
-s               = ws! Program ws!
-Program         = Program:: Directive+/ws
-                | Program:: ("":: Directive+/ws) ws! CodeBagBody
+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
 
-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
+Commands::      = Command +/ (ws "," ws)
+Command         = ^"wait"
+                | ^"nop"
+                | ^"discard"
+                | ^"recieve"
+                | ^"take"
+                | ^"deliver"
+                | ^"send"
+                | ^"sendto"     Destination /ws
+                | ^"notify"     Destination /ws
+                | ^"notifyLast" Destination /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
-                | DataOutDest::   "send"
-                | Deliver::  "deliver"
-                | Ack::      "notify" ws! Port
+Literal         = int
+                | ShipType "." PortName ^"[" Constants "]"
+                | CodeBagName
+                | "{" CodeBagBody "}" /ws
 
-Source         = Port
-               | ShipSpecific
+Pump::          = ShipName "." PortName
+Destination::   = ShipName "." PortName
+Constants::     = Constant +/ ","
+Constant::      = [a-zA-Z0-9=_\-]++
 
-SSL            = ShipSpecificLiteral:: shiptype "." ShipSpecificLiteral
-Port           = Port::     shipname "." portname
-               | SubPort::  shipname "." portname "." portname
-               |           ^"()"
+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]++)
 
-CodeBagBody::  = Statement +/ ws
-CodeBag        = CodeBagRef:: CodeBagName
-               | AnonymousCodeBag:: "{" CodeBagBody "}" /ws
+ws!             = wsx -> ~[\r\n ]
+wsx!            = ()
+                | wsx [\r\n ]
+                | wsx Comment
+Comment!        = "//" ~[\n\r]* [\r\n]
+                | "/*" ~[\n\r]* "*/"
 
-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
-               | Skip::    "#skip"
+// 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"