From 2a65d41cd852f762433e7b12b23fe562793e97b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Fri, 16 Feb 2018 00:21:29 +0100 Subject: [PATCH] Add IfZero construct to lexer + parser --- src/Lexer.mll | 6 ++++++ src/Parser.mly | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/Lexer.mll b/src/Lexer.mll index ba016f0..19bd802 100644 --- a/src/Lexer.mll +++ b/src/Lexer.mll @@ -44,6 +44,12 @@ rule entry = parse { PRINT } | "rec" { REC } +| "ifzero" + { IFZERO } +| "then" + { THEN } +| "else" + { ELSE } | "->" { ARROW } | "=" diff --git a/src/Parser.mly b/src/Parser.mly index 4f032b2..9e1adba 100644 --- a/src/Parser.mly +++ b/src/Parser.mly @@ -1,6 +1,7 @@ %token IDENT %token INTLITERAL %token FUN IN LET PRINT REC +%token IFZERO THEN ELSE %token ARROW EQ LPAREN RPAREN %token MULOP ADDOP %token EOF @@ -67,6 +68,9 @@ any_term_: { Lam (x, t) } | LET mode = recursive x = IDENT EQ t1 = any_term IN t2 = any_term { Let (mode, x, t1, t2) } +| IFZERO expr = any_term THEN tIf = any_term ELSE tElse = any_term + { IfZero (expr, tIf, tElse) } + %inline any_term: t = placed(any_term_)