dfee55005c97ac1c6a908e53b1e532b9075a884f
[fleet.git] / src / edu / berkeley / fleet / assembler / fleet.g
1 // The FLEET Assembly Language Grammar [26-Aug-2007]
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::         = Pump        ":" Instructions        /ws
13
14 Instructions::  = Instruction +/ ws
15 Instruction     = ^"unclog"                          ";" /ws
16                 | ^"clog"                            ";" /ws
17                 | ^"kill"                            ";" /ws
18                 | ^"kill"     int                    ";" /ws
19                 | ^"literal"  Literal  RequeueCount  ";" /ws
20                 | RepeatCount Commands RequeueCount ^";" /ws
21 RepeatCount     = "" | ^"[*]" | "[" int "]"
22 RequeueCount    = ""
23                 | "," "requeue" (^"forever" | int ws "times") /ws
24
25 Commands::      = Command +/ (ws "," ws)
26 Command         = ^"wait"
27                 | ^"nop"
28                 | ^"discard"
29                 | ^"recieve"
30                 | ^"take"
31                 | ^"deliver"
32                 | ^"send"
33                 | ^"sendto"     Destination /ws
34                 | ^"notify"     Destination /ws
35                 | ^"notifyLast" Destination /ws
36
37 Literal         = int
38                 | ShipType "." PortName ^"[" Constants "]"
39                 | CodeBagName
40                 | "{" CodeBagBody "}" /ws
41
42 Pump::          = ShipName "." PortName
43 Destination::   = ShipName "." PortName
44 Constants::     = Constant +/ ","
45 Constant::      = [a-zA-Z0-9=_\-]++
46
47 CodeBagName     = UpcaseWord
48 ShipType        = UpcaseWord
49 ShipName        = DowncaseWord
50 PortName        = DowncaseWord
51 Word            = UpcaseWord | DowncaseWord
52 UpcaseWord      = Name:: [A-Z]    ("":: [A-Za-z0-9_]**)
53 DowncaseWord    = Name:: [a-z]    ("":: [A-Za-z0-9_]**)
54 int::           = (^"-"|^"") (^"0x"|^"0b"|^"") (digits:: [0-9]++)
55
56 ws!             = wsx -> ~[\r\n ]
57 wsx!            = ()
58                 | wsx [\r\n ]
59                 | wsx Comment
60 Comment!        = "//" ~[\n\r]* [\r\n]
61                 | "/*" ~[\n\r]* "*/"
62
63 // the following extensions are not part of the official FLEET syntax
64
65 Directive      = ^"#memory" "{" (Memory:: int +/ (ws! "," ws!)) "}" /ws
66                | ^"#import" [A-Za-z_.]++ /ws
67                | ^"#include" ws! "\"" ~[\"]+ "\""
68                | ^"#ship" ShipName ":" ("":: [0-9A-Za-z_.]++) /ws
69                | ^"#expect" int /ws
70                | ^"#skip"