From 1b4184ccbb01634792897d3412c489b989674567 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 1 Nov 2003 19:10:41 +0000 Subject: [PATCH] * Let syntax. --- src/fix-ng/eval.cc | 5 +++++ src/fix-ng/fix.sdf | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/fix-ng/eval.cc b/src/fix-ng/eval.cc index 785467741..46bb1f941 100644 --- a/src/fix-ng/eval.cc +++ b/src/fix-ng/eval.cc @@ -160,6 +160,11 @@ Expr evalExpr2(EvalState & state, Expr e) if (ATmatch(e, "Rec([])", &bnds)) return expandRec(e, (ATermList) bnds); + /* Let expressions `let {..., body = ...}' are just desugared + into `(rec {..., body = ...}).body'. */ + if (ATmatch(e, "LetRec()", &e1)) + return evalExpr(state, ATmake("Select(Rec(), \"body\")", e1)); + /* Barf. */ throw badTerm("invalid expression", e); } diff --git a/src/fix-ng/fix.sdf b/src/fix-ng/fix.sdf index cae5d2748..251a63f0c 100644 --- a/src/fix-ng/fix.sdf +++ b/src/fix-ng/fix.sdf @@ -47,6 +47,9 @@ exports "rec" "{" {Bind ","}* "}" -> Expr {cons("Rec")} + "let" "{" {Bind ","}* "}" + -> Expr {cons("LetRec")} + "{" {Bind ","}* "}" -> Expr {cons("Attrs")} @@ -59,6 +62,12 @@ exports Expr "." Id -> Expr {cons("Select")} + "if" Expr "then" Expr "else" Expr + -> Expr {cons("If")} + + Expr "==" Expr + -> Expr {cons("OpEq")} + context-free priorities Expr "." Id -> Expr