Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
--   http://anggtwu.net/LUA/Ast6.lua.html
--   http://anggtwu.net/LUA/Ast6.lua
--          (find-angg "LUA/Ast6.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/Ast6.lua"))
-- (defun a2 () (interactive) (find-angg "LUA/Ast2.lua"))
-- (defun a3 () (interactive) (find-angg "LUA/Ast3.lua"))
-- (defun a4 () (interactive) (find-angg "LUA/Ast4.lua"))
-- (defun a5 () (interactive) (find-angg "LUA/Ast5.lua"))
-- (defun a6 () (interactive) (find-angg "LUA/Ast6.lua"))
-- (defun tt () (interactive) (find-angg "LUA/TikzTrees1.lua"))

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

tnode_tex["*"] = "\\cdot"
tnode_tex["^"] = "pow"
tnode_tex["'"] = "\\prime"

VA.num   = Cs(R"09"^1)
VA.var   = anyof "x"
VA.fun   = anyof "f' f g' g ln sin cos"
VA.ap    = V.fun *_* V.exprbasic

VA.paren = "("*_* V.expr *_*")"
V.exprbasic = V.paren + V.ap + V.num + V.var -- + V.fun
V.exprplic  = assocpost(V.exprbasic, Cs"'"     )
V.exprpow   = assocr(V.exprplic,     Cs"^"     )
V.exprmul   = assocl(V.exprpow,      Cc"mul"   )
V.exprMul   = assocl(V.exprmul,      Cs"*"     )
V.exprplus  = assocl(V.exprMul,      Cs"+"     )
V.exprDiv   = assocl(V.exprplus,     Cs"//"    )
V.expreq    = assocl(V.exprDiv,      Cs"="     )
V.expr      = V.expreq

unary    = function (op, a) return AST {[0]=op, a} end
plic     = function (a) return unary("'", a) end
foldplic = function (A)
    local o = A[1]
    for i=2,#A do o = plic(o) end
    return o
  end

V.exprplic  = Ct(V.exprbasic * (_*Cs"'")^0) / foldplic

clean = function (o)
    if type(o) == "string" then return o end
    if type(o) == "number" then return o end
    if o[0] == "paren" then return clean(o[1]) end
    if o[0] == "var" then return o[1] end
    if o[0] == "fun" then return o[1] end
    if o[0] == "num" then return o[1] end
    if o[0] == "mul" then return mkast("*", clean(o[1]), clean(o[2])) end
    if o[0] == "ap"  then return mkast(o[1][1], clean(o[2])) end
    o = copy(o)
    for i=1,#o do o[i] = clean(o[i]) end
    return o
  end



--[[
** (find-code-show2 "~/LATEX/Show2.tex")
*       (code-show2 "~/LATEX/Show2.tex")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Ast6.lua"

=   gr:cm("expr", "x")
o = gr:cm0("expr", "(ln x)^3 // 5 + sin x")
o = gr:cm0("expr", "(f(x)g(x))' = f'(x)g(x) + f(x)g'(x)")
o = gr:cm0("expr", "(f(x)g(x))' = f(x)'g(x) + f(x)g(x)'")
= o
oc = clean(o)
= oc
on = to_tnode(oc)
= on

  on.preopts = "[every node/.style={ellipse,draw,fill=orange}]"
  on.preopts = "[every node/.style={ellipse,draw,fill=orange},sibling distance=5cm]"
  on[2][2].preopts = "[sibling distance=1cm]"


= on:tp():totex()
= on:tp():show(0.7)   -- or: on:tikzshow()
= Show.bigstr
= Show.log
* (etv)



  on.opts = "[fill=red]"

  on.opts = "[sibling distance=5cm]"

  on.chopts = "[sibling distance=5cm]"

  on.preopts = "[sibling distance=5cm]"

-- (tiks)

E[    "x"                ] = var"x"
E[ "ln x"                ] = ap(fun"ln", E"x")
E["(ln x)"               ] = paren(E"ln x")
E[       "3"             ] = num("3")
E["(ln x)^3"             ] = pow(E"(ln x)", E"3")
E["(ln x)^3"             ] = pow(E"(ln x)", E"3")
E[           "5"         ] = num("5")
E[                "sin x"] = ap(fun"sin", E"x")
E[            "5 + sin x"] = plus(E"5", E"sin x")
E["(ln x)^3 // 5 + sin x"] = Div(E"(ln x)^3", E"5 + sin x")

E[ "f"                                 ] = fun"f"
E[  "(x)"                              ] = paren(E"x")
E[ "f(x)"                              ] = ap(E"f", E"(x)")
E[     "g"                             ] = fun"g"
E[     "g(x)"                          ] = ap(E"g", E"(x)")
E[ "f(x)g(x)"                          ] = mul(E"f(x)", E"g(x)")
E["(f(x)g(x))"                         ] = paren(E"f(x)g(x)")
E["(f(x)g(x))'"                        ] = plic(E"(f(x)g(x))")
E[              "f'"                   ] = fun"f'"
E[              "f'(x)"                ] = ap(E"f'", E"(x)")
E[              "f'(x)g(x)"            ] = mul(E"f'(x)", E"g(x)")
E[                              "g'"   ] = fun"g'"
E[                              "g'(x)"] = ap(E"g'", E"(x)")
E[                          "f(x)g'(x)"] = mul(E"f(x)", E"g'(x)")
E[              "f'(x)g(x) + f(x)g'(x)"] = plus(E"f'(x)g(x)", E"f(x)g'(x)")
E["(f(x)g(x))' = f'(x)g(x) + f(x)g'(x)"] = eq(E"(f(x)g(x))'", E"f'(x)g(x) + f(x)g'(x)")


--]]



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