1 // The FLEET Assembly Language Grammar [26-Aug-2007]
3 // Note that this is the *entire, complete* formal specification of
4 // the grammar. An equivalent lex+yacc grammar and support code would
5 // be several times as long.
8 Program:: = Directives CodeBagBody /ws
9 Directives:: = Directive */ ws
10 CodeBagBody:: = (Fiber | CodeBagDef) */ ws
11 CodeBagDef:: = CodeBagName ":" "{" CodeBagBody "}" /ws
12 Fiber:: = Pump ":" Instructions /ws
14 Instructions:: = Instruction +/ ws
15 Instruction = ^"unclog" ";" /ws
19 | "take" ^"loop" "counter" ";" /ws
20 | ^"load" (^"loop"|^"repeat") ws "counter" ";" /ws
21 | "load" (^"loop"|^"repeat") ws "counter" ^"with" int ";" /ws
22 | ^"decrement" "loop" "counter" ";" /ws
23 | ^"setflags" ws "a=" Flag ws "b=" Flag ws ";"
25 | ^"literal" Literal RequeueCount ";" /ws
26 | RepeatCount Commands RequeueCount ^";" /ws
27 RepeatCount = "" | ^"[*]" | "[" int "]"
29 | "," "requeue" (^"forever" | int ws "times") /ws
42 Commands:: = Command +/ (ws "," ws)
50 | ^"sendto" Destination /ws
51 | ^"notify" Destination /ws
52 | ^"notifyLast" Destination /ws
55 | ShipType "." PortName ^"[" Constants "]"
57 | "{" CodeBagBody "}" /ws
59 Pump:: = ShipName "." PortName
60 Destination:: = ShipName "." PortName
61 Constants:: = Constant +/ ","
62 Constant:: = [a-zA-Z0-9=_\-]++
64 CodeBagName = UpcaseWord
66 ShipName = DowncaseWord
67 PortName = DowncaseWord
68 Word = UpcaseWord | DowncaseWord
69 UpcaseWord = Name:: [A-Z] ("":: [A-Za-z0-9_]**)
70 DowncaseWord = Name:: [a-z] ("":: [A-Za-z0-9_]**)
71 int:: = (^"-"|^"") (^"0x"|^"0b"|^"") (digits:: [0-9]++)
77 Comment! = "//" ~[\n\r]* [\r\n]
80 // the following extensions are not part of the official FLEET syntax
82 Directive = ^"#memory" "{" (Memory:: int +/ (ws! "," ws!)) "}" /ws
83 | ^"#import" [A-Za-z_.]++ /ws
84 | ^"#include" ws! "\"" ~[\"]+ "\""
85 | ^"#ship" ShipName ":" ("":: [0-9A-Za-z_.]++) /ws