Grammar · v0.8.1
Formal grammar (EBNF)
The complete context-free grammar accepted by the reference implementation, in Extended Backus–Naur Form. Expression rules are layered by precedence, lowest to highest.
thirsty-lang.ebnf
program = { statement } ;
statement = letDecl
| capability
| intent
| action
| gate
| require
| commit
| safeHalt ;
letDecl = "let" IDENT "=" expr [ ";" ] ;
capability = "capability" IDENT "{" { field } "}" [ ";" ] ;
field = IDENT ":" expr [ "," ] ;
intent = "intent" ( IDENT | STRING ) [ ";" ] ;
action = "action" ( IDENT | STRING ) block ;
gate = "gate" ( IDENT | STRING ) block ;
block = "{" { statement } "}" ;
require = "require" expr [ "else" ( "deny" | "halt" ) [ STRING ] ] [ ";" ] ;
commit = "commit" [ ";" ] ;
safeHalt = "safe_halt" [ STRING ] [ ";" ] ;
expr = orExpr ;
orExpr = andExpr { ( "or" | "||" ) andExpr } ;
andExpr = eqExpr { ( "and" | "&&" ) eqExpr } ;
eqExpr = cmpExpr { ( "==" | "!=" ) cmpExpr } ;
cmpExpr = addExpr { ( "<" | ">" | "<=" | ">=" ) addExpr } ;
addExpr = mulExpr { ( "+" | "-" ) mulExpr } ;
mulExpr = unary { ( "*" | "/" | "%" ) unary } ;
unary = ( "not" | "!" | "-" ) unary | postfix ;
postfix = primary { "." IDENT } ;
primary = NUMBER | STRING | "true" | "false" | "null"
| IDENT | "(" expr ")" ;
(* Lexical *)
IDENT = LETTER { LETTER | DIGIT | "_" } ;
NUMBER = DIGIT { DIGIT | "_" } [ "." DIGIT { DIGIT } ] ;
STRING = '"' { CHAR } '"' ;
COMMENT = "//" { CHAR } NEWLINE ;Precedence (low → high)
- or (||)
- and (&&)
- == !=
- < > <= >=
- + -
- * / %
- unary not ! -
- member access .
Lexical notes
- Line comments start with
//. - Numeric literals may use
_as a digit separator (e.g.12_000). - Strings are double-quoted and support
\n,\tescapes. - Statement terminators (
;) are optional. and/or/notare word-aliases for&& || !.