final pass to update instruction encoding; should now match the spec
[fleet.git] / contrib / f0 / f0.g
diff --git a/contrib/f0/f0.g b/contrib/f0/f0.g
new file mode 100644 (file)
index 0000000..f5c1912
--- /dev/null
@@ -0,0 +1,41 @@
+s               = ws! (Def+/ws) ws!
+
+Def = Id "(" (Id+/comma) "->" (Id+/comma) ")" "=" Exprs /ws
+
+Exprs =
+  Exprs:: Decl */ ws
+          ws!
+          ((Expr +/ ws) +/ semicolons)
+
+Decl = Id   ^"::" ShipName  /ws
+
+Expr = "{" Exprs "}"        /ws
+     | (Literal|Port)     ^"-->"              Ports /ws
+     | (Literal|Port)     ^"+->"              Ports /ws
+     | (Literal|Port) ws! ^"-[" Int "]->" ws! Ports
+     | (Literal|Port)     ^"-[*]->"           Ports /ws
+     | ^"while" Cond Expr /ws
+//   | "if" "then" "else"
+
+CondOp = ^"==" | ^"!=" | ^">" | ^">=" | ^"<" | ^"<="
+Cond   = Cond:: Port CondOp Int /ws
+
+Ports    = ";":: Port +/ semicolon
+         > ",":: Port +/ comma
+Port     = "Port":: Id
+         | "Port":: Id "." Id
+
+Literal  = Int | ^"{" Int +/ comma "}" /ws
+Int      = [\-0-9]++
+ShipName = "":: [A-Z] [a-zA-Z0-9_]*
+Id       = "":: [a-z] [a-zA-Z0-9_]*
+
+Comment    = "//" (~eol)* eol!
+           | "/*" (any* &~ (any*! "*/" any*!)) "*/"
+ws         = (wsc | Comment)* -> ~wsc
+eol        = [\r\n]
+wsc        = [\r\n ] | \{ | \}
+comma      = ws! "," ws!
+semicolon  = ws! ";" ws!
+semicolons = ws! ";;" ws!
+any        = ~[]