1 // The FLEET Assembly Language Grammar
4 // Note that this is the *entire, complete* formal specification of
5 // the grammar. An equivalent lex+yacc grammar and support code would
6 // be several times as long.
8 Comment = "//" ~[\n\r]* [\r\n]!
10 ws = ([\r\n ] | Comment)* -> ~[\r\n ]
13 Program = Program:: Directive+/ws
14 | Program:: (Directive+/ws) ws! CodeBagBody
16 Statement = Fiber:: Source ":" (Instruction +/ ws) /ws
17 | Literal:: int ":" "sendto" Port ";" /ws
18 | ShipSpecificLiteral:: SSL ":" "sendto" Port ";" /ws
19 | CodeBagDescriptor:: CodeBag ":" "sendto" Port ";" /ws
20 | NamedCodeBag:: name ":" "{" CodeBagBody "}" /ws
22 CountField = Brack:: "[" int "]"
26 Instruction = Instruction::
28 (Command +/ (ws! "," ws!) ws! ";"!)
34 | Take:: ("take"|"receive")
35 | SendTo:: "sendto" ws! Port
37 | Ack:: "notify" ws! Port
42 SSL = ShipSpecificLiteral:: shiptype "." ShipSpecificLiteral
43 Port = Port:: shipname "." portname
46 CodeBagBody = Statement +/ ws
47 CodeBag = CodeBagRef:: CodeBagName
48 | AnonymousCodeBag:: "{" CodeBagBody "}" /ws
52 shiptype = Name:: [A-Z] [A-Za-z0-9\[\]_]**
53 ShipSpecificLiteral = Name:: [A-Z] [A-Z0-9\[\]_]**
54 portname = Name:: [a-z] [A-Za-z0-9\[\]_]**
55 name = Name:: [A-Za-z] [A-Za-z0-9\[\]_]**
56 index = "[" [0-9]+ "]" | [0-9]+
58 ShipSpecific = ShipSpecific:: "\"" ~[\"]++ "\""
60 // the following are not part of the official FLEET syntax and are
61 // specific to Adam's interpreter.
63 Directive = Memory:: "#memory" "{" (int +/ (ws! "," ws!)) "}" /ws
64 | Import:: "#import" [A-Za-z_.]++ /ws
65 | Include:: "#include" ("\"" (~[\"])+ "\"") /ws
66 | Ship:: "#ship" shipname ":" [0-9A-Za-z_.]++ /ws
67 | Expect:: "#expect" int /ws