// The FLEET Assembly Language Grammar // Updated 05-Nov-2006 // 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]* "\n" | "/*" ~[\n]* "*/" ws = ([\r\n ] | Comment)* -> ~[\r\n ] s = ws! Program ws! Program = Program:: Directive+/ws | Program:: (Directive+/ws) ws! CodeBagBody Statement = Instruction:: (Opcode ws!)? Source ws! Arrow ws! Port | NamedCodeBag:: name ":" "{" CodeBagBody "}" /ws Opcode = Triggered:: "triggered" OpcodeBody /ws | UnTriggered:: OpcodeBody OpcodeBody = ^"nop" | ^"wait" | ^"discard" | ^"nop+ack" | ^"wait+ack" | ^"discard+ack" | ^"copy" | ^"move" | ^"accept" | ^"copy+ack" | ^"move+ack" | ^"accept+ack" | ^"synthesize" | ^"synthesize+ack" Arrow = ^"->" | ^"-[*]->" | ^"-[" int "]->" Source = Port | CodeBag | int | ShipSpecific Port = Port:: shipname "." portname | ^"()" CodeBagBody = Statement +/ (ws (";" ws)?!) CodeBag = CodeBagRef:: CodeBagName | AnonymousCodeBag:: "{" CodeBagBody "}" /ws CodeBagName = name &~ Opcode shipname = name &~ Opcode portname = name &~ Opcode 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 ":" [A-Za-z_.]++ /ws