Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
--   http://anggtwu.net/LUA/ELpeg-lambda1.lua.html
--   http://anggtwu.net/LUA/ELpeg-lambda1.lua
--          (find-angg "LUA/ELpeg-lambda1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun el () (interactive) (find-angg "LUA/ELpeg-lambda1.lua"))
-- (defun a5 () (interactive) (find-angg "LUA/Ast5.lua"))

-- (defun e1 () (interactive) (find-angg "LUA/ELpeg1.lua"))
-- (defun ec () (interactive) (find-angg "LUA/ELpeg-cme1.lua"))
-- (defun el () (interactive) (find-angg "LUA/ELpeg-lambda1.lua"))
-- (defun so () (interactive) (find-fline "~/LUA/Show2-outer.tex"))
-- (defun si () (interactive) (find-fline "~/LUA/Show2-inner.tex"))

require "ELpeg1"  -- (find-angg "LUA/ELpeg1.lua")
gr,V,VA,VE,PE = Gram.new()
_ = S(" ")^0

AST.alttags = {
  eq="=", plus="+", minus="-", Mul="*",
  div="/", Div="//", pow="^",
  paren="()", plic="'"
}

gr,V,VA,VE,PE = Gram.new()
grcm = function (...) print(gr:cm(...)) end
_ = S(" ")^0

bin = function (a, op, b) return AST {[0]=op, a, b} end
foldlambda = function (A)
    local f = function (var, o) return bin(var, "L", o) end
    return foldr1(f, A)
  end

VA.num       = Cs(R"09"^1)
VA.var       = anyof "a b c x y f g"

VA.paren     = "("*_* V.expr *_*")"

V.oplambda   = P"L"*_* V.var *_*P"."*_

V.exprbasic  = V.var + V.num + V.paren
V.exprap     = assocl(V.exprbasic, Cc"ap")
V.exprmul    = assocl(V.exprap,    Cs"*" )
V.exprplus   = assocl(V.exprmul,   Cs"+" )
V.exprlambda = (V.oplambda^0 * V.exprplus):Ct() / foldlambda
V.expr       = V.exprlambda

defs = [[
  \def\und#1#2{\underbrace{#1}_{#2}}
  \def\u    #1{\underbrace{#1}_{}}
]]

fmts = {
  ["()"] = "(<1>)",
  ["//"] = "\\frac{<1>}{<2>}",
  ["*"]  = "<1> \\cdot <2>",
  ["*"]  = "\\u{<1> \\cdot <2>}",
  ["*"]  = "\\und{<1> \\cdot <2>}{\\cdot}",
  ["+"]  = "<1> + <2>",
  ["+"]  = "\\u{<1> + <2>}",
  ["+"]  = "\\und{<1> + <2>}{+}",
  ["="]  = "<1> = <2>",
  ap  = "<1>\\,<2>",
  ap  = "\\u{<1>\\,<2>}",
  ap  = "\\und{<1>\\,<2>}{ap}",
  mul = "<1> <2>",
  Mul = "<1> \\cdot <2>",
  L = "\\lambda <1>.\\,<2>",
  L = "\\u{\\lambda\\u{<1>}.\\,<2>}",
  L = "\\u{\\lambda <1>.\\,<2>}",
  L = "\\und{\\lambda <1>.\\,<2>}{\\lambda}",
  num = "\\u{<1>}",
  num = "<1>",
  var = "<1>",
}


--[[
* (code-etv2 "SHOW2DIR" "/tmp/" "Show2")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "ELpeg-lambda1.lua"

-- La2018p6, exercicio (c)
=   grcm  ("expr",  "(L a. 10*a) ((L b. b+4)(3))")
o = gr:cm0("expr",  "(L a. 10*a) ((L b. b+4)(3))")
= o
= o:totex()
= o:totex00()
  o:show("2")
* (etv)

-- La2018p6, exercicio (d)
o = gr:cm0("expr",  "((L f.(L a. f(f(a))))(L x. 10*x))(7)")
= o
= o:totex()
= o:totex0()
  o:show("1.2")
* (etv)


--]]


-- Local Variables:
-- coding:  utf-8-unix
-- End: