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

require "Ast3"   -- (find-angg "LUA/Ast3.lua")
                 -- (find-angg "LUA/Show1.lua")

totex00 = ToText0 {fmts={}}    -- Override this!
totex0  = function (o) return totex00:with(o)          end
totex   = function (o) return totex00:with(o):totext() end
AST.__index.totex0 = function (o) return totex0(o) end
AST.__index.totex  = function (o) return totex(o)  end

-- (find-angg "LUA/Show1.lua" "string.show-tests")
AST.__index.show   = function (o, ops) return totex(o):show(ops) end

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

Show.preamble = [[
  \def\und#1#2{\underbrace{#1}_{#2}}
  \def\u    #1{\underbrace{#1}_{}}
]]

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


--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Ast5.lua"
=   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:totex0()
= o:show("dd 1")
* (etv)

--]]





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