pratt_mixfix.ebnf (883B)
1 // Mixfix Pratt forms: ternary `?:`, circumfix call/index, and `.` member 2 // chains layered on the prefix/infix/postfix frame machine. 3 // 4 // Precedence is declaration order, loosest first: ternary, then +/-, then */, 5 // then call `(...)`, then index `[...]`, then `.` member (tightest). Member 6 // binds tightest so `a.b(c)` is `(a.b)(c)` and `f(x).y` is `(f(x)).y`; call and 7 // index chain left-to-right at constant depth. The conditional is 8 // right-associative. 9 %pratt expr { 10 primary primary; 11 ternary "?" ":"; 12 infixl "+" "-"; 13 infixl "*" "/"; 14 circumfix "(" args ")"; 15 circumfix "[" expr "]"; 16 infixl "."; 17 } 18 19 primary = NUMBER | NAME | "(" expr ")"; 20 21 // `(` is both a grouping primary-start (nud) and a call open (led); position 22 // disambiguates. The argument list is comma-separated and may be empty. 23 args = %empty | expr arg_more*; 24 arg_more = "," expr;