updates to fleet.g
[sbp.git] / tests / fleet.g
1 // The FLEET Assembly Language Grammar
2 // As specified in document 2005-ucies06
3
4 // comments are included where the grammar had to go beyond the strict
5 // "letter of the law" in ies06
6
7 // Note that this is the *entire, complete* formal specification of
8 // the grammar.  An equivalent lex+yacc grammar and support code would
9 // be several times as long.
10
11 Comment     !::= "//" ~[\n]* "\n"
12                | "/*" ~[\n]* "*/"
13
14 ws           ::= w**
15 w            ::= [\r\n ]
16                | Comment
17
18 Program      ::= Statement+                            /ws
19
20 Statement    ::= Move ";"?                             /ws
21                | "{" Statement* "}"
22                | Port "RENAMES" Port "ENDRENAME" ";"   /ws
23 //             | "#define" Port Port                   /ws
24
25 Move         ::= Source       ^"->" Destination        /ws
26                | Source       ^"=>" Destination        /ws
27                | Destination  ^":=" Source             /ws
28
29 Destination  ::= Port +/ (ws "," ws)
30 Source       ::= Port
31                | CodeBag
32
33 CodeBag      ::= CodeBagName? "{" Statement* "}" ";"?  /ws
34
35 // Note: this deviates from ies06
36 Port         ::= shipname ("." portname)*
37 shipname     ::= name     index?
38 portname     ::= name     index?
39 name         ::= [A-Za-z] [A-Za-z0-9\[\]\.]*
40 index        ::= "[" [0-9]+ "]"
41                | [0-9]+
42
43
44 //
45 // The syntax should be rather self-explanatory; here are some of the
46 // grammatical operators you may not have seen before:
47 // 
48 //   ^     marks the "key" token; this is used only after parsing
49 //   /     separated-by; all preceding elements are separated by the following element
50 //   +/    one-or-more-with-separator; for example, "a"+/"," matches "a,a,a"
51 //   */    zero-or-more-with-separator
52 //   &     intersection; a&b matches a string only if a matches it and b matches it
53 //   &~    negated intersection; a&~b matches a string only if a matches it and b DOES NOT match it
54 //