1 // The FLEET Assembly Language Grammar [22-Aug-2008]
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:: = Dock ":" Instructions /ws
14 Instructions:: = Instruction +/ ws
15 Instruction = Instruction:: (Tags:: Tag*) InstructionX
18 Tag = ^"[a]" ws | ^"[b]" ws
19 | ^"[!a]" ws | ^"[!b]" ws
22 InstructionX = (() | ^"[T]" ws) ^"nop" ";" /ws
23 | (() | ^"[T]" ws) (Commands:: Command +/ (ws "," ws)) ^";" /ws
24 | "olc=word":: "set" "olc" "=" "word" ";" /ws
25 | "ilc=word":: "set" "ilc" "=" "word" ";" /ws
26 | "olc=int":: "set" "olc" "=" int ";" /ws
27 | "ilc=int":: "set" "ilc" "=" int ";" /ws
28 | "set" "ilc" "=" ^"*" ";" /ws
29 | "set" "olc" ^"--" ";" /ws
30 | "set" ^"flags" "a" "=" Flags "," "b" "=" Flags ";" /ws
31 | "set" ^"word" "=" Literal ";" /ws
32 | ^"shift" Literal ";" /ws
36 Flags:: = (^"0") | (^"1") | (^"a" | ^"b" | ^"c" | ^"!a" | ^"!b" | ^"!c") +/ (ws "|" ws)
38 Command = "recv token":: "recv" ws "token"
40 | "recv":: "recv" ws "word"
41 | "recv nothing":: "recv" ws "nothing"
42 | "recv path":: "recv" ws "path"
43 | "recv packet":: "recv" ws "packet"
45 | "collect":: "collect" ws "word"
46 | "collect nothing":: "collect" ws "nothing"
47 | "collect path":: "collect" ws "path"
48 | "collect packet":: "collect" ws "packet"
51 | "send to":: "send" "to" Destination /ws
52 | "send token":: "send" "token" Destination /ws
53 | "send token to":: "send" "token" "to" Destination /ws
56 | ShipType "." DockName ^"[" Constants "]"
58 | "{" CodeBagBody "}" /ws
60 Dock:: = ShipName "." DockName
61 Destination:: = ShipName "." DockName ( ^"" | ^":i" | ^":0" | ^":1" )
62 Constants:: = Constant +/ ","
63 Constant:: = [a-zA-Z0-9=_\-]++
65 CodeBagName = UpcaseWord
67 ShipName = DowncaseWord
68 DockName = DowncaseWord
69 Word = UpcaseWord | DowncaseWord
70 UpcaseWord = Name:: [A-Z] ("":: [A-Za-z0-9_]**)
71 DowncaseWord = Name:: [a-z] ("":: [A-Za-z0-9_]**)
72 int:: = (^"-"|^"") (^"0x"|^"0b"|^"") (digits:: [0-9A-Fa-f]++)
78 Comment! = "//" ~[\n\r]* [\r\n]
81 Directive = ^"#ship" ShipName ":" ("":: [0-9A-Za-z_.]++) /ws