P‑AIProject‑AI
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)
  1. or (||)
  2. and (&&)
  3. == !=
  4. < > <= >=
  5. + -
  6. * / %
  7. unary not ! -
  8. 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, \t escapes.
  • Statement terminators (;) are optional.
  • and/or/not are word-aliases for && || !.