Add IfZero construct to lexer + parser
This commit is contained in:
parent
7bc7921fc3
commit
2a65d41cd8
|
@ -44,6 +44,12 @@ rule entry = parse
|
||||||
{ PRINT }
|
{ PRINT }
|
||||||
| "rec"
|
| "rec"
|
||||||
{ REC }
|
{ REC }
|
||||||
|
| "ifzero"
|
||||||
|
{ IFZERO }
|
||||||
|
| "then"
|
||||||
|
{ THEN }
|
||||||
|
| "else"
|
||||||
|
{ ELSE }
|
||||||
| "->"
|
| "->"
|
||||||
{ ARROW }
|
{ ARROW }
|
||||||
| "="
|
| "="
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
%token<string> IDENT
|
%token<string> IDENT
|
||||||
%token<int> INTLITERAL
|
%token<int> INTLITERAL
|
||||||
%token FUN IN LET PRINT REC
|
%token FUN IN LET PRINT REC
|
||||||
|
%token IFZERO THEN ELSE
|
||||||
%token ARROW EQ LPAREN RPAREN
|
%token ARROW EQ LPAREN RPAREN
|
||||||
%token<RawLambda.binop> MULOP ADDOP
|
%token<RawLambda.binop> MULOP ADDOP
|
||||||
%token EOF
|
%token EOF
|
||||||
|
@ -67,6 +68,9 @@ any_term_:
|
||||||
{ Lam (x, t) }
|
{ Lam (x, t) }
|
||||||
| LET mode = recursive x = IDENT EQ t1 = any_term IN t2 = any_term
|
| LET mode = recursive x = IDENT EQ t1 = any_term IN t2 = any_term
|
||||||
{ Let (mode, x, t1, t2) }
|
{ Let (mode, x, t1, t2) }
|
||||||
|
| IFZERO expr = any_term THEN tIf = any_term ELSE tElse = any_term
|
||||||
|
{ IfZero (expr, tIf, tElse) }
|
||||||
|
|
||||||
|
|
||||||
%inline any_term:
|
%inline any_term:
|
||||||
t = placed(any_term_)
|
t = placed(any_term_)
|
||||||
|
|
Loading…
Reference in a new issue