Related articles |
---|
LALR(1) lookahead confuse pt1855@yahoo.com.tw (pinglengcy) (2005-03-24) |
From: | "pinglengcy" <pt1855@yahoo.com.tw> |
Newsgroups: | comp.compilers |
Date: | 24 Mar 2005 21:13:24 -0500 |
Organization: | http://groups.google.com |
Keywords: | LALR, question |
Posted-Date: | 24 Mar 2005 21:13:23 EST |
Hello,
I use "compilers principles Techniques and Tools" book
,but not calculate correct propagate lookahead
THINKS BY TOM
as follow:
(I)
My Grammar:
G->.L #
L->.V(args) #=
L->.L=Var() #=
V->.Var+V #=(
V->.id #=(
Var->.id #=(+
(II)
--------------------------------
(0)G->.L (1)G->L. deal1
(2)L->V.(args)
(1)L->L.=Var()
(3)V->Var.+V
(4)V->id.
(4)Var->id.
--------------------------------
(2)L->V.(args) (6)L->V(.args) deal2
-----------------------------
(1)L->L.=Var() (5)L->L=.Var() deal3
---------------------------------
(3)V->Var.+V (7)V->Var+.V deal4
---------------------------------
(6)L->V(.args) (10)L->V(args.) deal5
----------------------------------
(5)L->L=.Var() (8)L->L=Var.() deal6
(9)Var->id.
----------------------------------
(7)V->Var+.V (11)V->Var+V. deal7
(3)V->Var.+V
(4)V->id.
(4)Var->id.
----------------------------------
(10)L->V(args.) (13)L->V(args). deal8
------------------------------------
(8)L->L=Var.() (12)L->L=Var(.) deal9
------------------------------------
(12)L->L=Var(.) (14)L->L=Var(). deal10
-----------------------------------
(III)
LR(0) init 1 2 3 4 5 6 7 8 9 10
(0)G->.L # # # # # # # # # # #
(1)G->L. # # # # # # # # # #
(2)L->V.(args) = =# =# =# =# =# =# =# =# =# =#
(3)V->Var.+V ( (# (# (# (# (# (# (# (# (# (#
(4)V->id. ( (# (# (# (# (# (# (# (# (# (# (error)
(4)Var->id. + +# +# +# +# +# +# +#( +#( +#( +#(
(5)L->L=.Var() = = = =# =# =# =# =# =# =# =#
(6)L->V(.args) =# =# =# =# =# =# =# =# =#
(7)V->Var+.V (# (# (# (# (# (# (#
(8)L->L=Var.() =# =# =# =# =#
(9)Var->id. =# =# =# =# =# (error)
(10)L->V(args.) =# =# =# =# =# =#
(11)V->Var+V. (# (# (# (#(error)
(12)L->L=Var(.) =# =#
(13)L->V(args). =# =# =# (ok)
(14)L->L=Var(). =# (ok)
and correct table:
http://smlweb.cpsc.ucalgary.ca/lalr1.php?grammar=L+-%3E+V+%28+args+%29%0A+++%7C+L+equals+Var+%28+%29.%0AV+-%3E+Var+%2B+V%0A+++%7C+id.%0AVar+-%3E+id.%0A&substs=
Return to the
comp.compilers page.
Search the
comp.compilers archives again.