change build machine, use /usr/bin/tclsh instead of /usr/bin/tcl
[fleet.git] / src / edu / berkeley / fleet / assembler / fleet.g
1 // The FLEET Assembly Language Grammar [22-Aug-2008]
2
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.
6
7 s               = ws Program ws
8 Program::       = Directives CodeBagBody /ws
9 Directives::    = Directive */ ws
10 CodeBagBody::   = (Fiber | CodeBagDef) */ ws
11 CodeBagDef::    = CodeBagName ":" "{" CodeBagBody "}" /ws
12 Fiber::         = Dock        ":" Instructions        /ws
13
14 Instructions::  = Instruction +/ ws
15 Instruction     = Instruction:: (Tags:: Tag*) InstructionX
16                 | ^"head" ";" /ws
17                 | ^"tail" ";" /ws
18 Tag             = ^"[a]"  ws |  ^"[b]" ws
19                 | ^"[!a]" ws | ^"[!b]" ws
20                 | ^"[d]" ws
21                 | ^"[*]" 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
33                 |              ^"flush"                                              ";" /ws
34                 |              ^"abort"                                              ";" /ws
35
36 Flags:: = (^"0") |  (^"1") | (^"a" |  ^"b" |  ^"c" | ^"!a" | ^"!b" | ^"!c") +/ (ws "|" ws)
37
38 Command         = "recv token"::       "recv" ws "token"
39                 |                     ^"recv"
40                 | "recv"::             "recv" ws "word"
41                 | "recv nothing"::     "recv" ws "nothing"
42                 | "recv path"::        "recv" ws "path"
43                 | "recv packet"::      "recv" ws "packet"
44                 |                     ^"collect"
45                 | "collect"::          "collect" ws "word"
46                 | "collect nothing"::  "collect" ws "nothing"
47                 | "collect path"::     "collect" ws "path"
48                 | "collect packet"::   "collect" ws "packet"
49                 |                     ^"deliver"
50                 |                     ^"send"
51                 | "send to"::          "send" "to"          Destination /ws
52                 | "send token"::       "send" "token"       Destination /ws
53                 | "send token to"::    "send" "token" "to"  Destination /ws
54
55 Literal         = int
56                 | ShipType "." DockName ^"[" Constants "]"
57                 | CodeBagName
58                 | "{" CodeBagBody "}" /ws
59
60 Dock::          = ShipName "." DockName
61 Destination::   = ShipName "." DockName ( ^"" | ^":i" | ^":0" | ^":1" )
62 Constants::     = Constant +/ ","
63 Constant::      = [a-zA-Z0-9=_\-]++
64
65 CodeBagName     = UpcaseWord
66 ShipType        = 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]++)
73
74 ws!             = wsx -> ~[\r\n ]
75 wsx!            = ()
76                 | wsx [\r\n ]
77                 | wsx Comment
78 Comment!        = "//" ~[\n\r]* [\r\n]
79                 | "/*" ~[\n\r]* "*/"
80
81 Directive      = ^"#ship" ShipName ":" ("":: [0-9A-Za-z_.]++) /ws
82                | ^"#expect" int /ws
83                | ^"#skip"