Dealing with infinite loops when constructing states for LR(1) parsing -
i'm constructing lr(1) states following grammar.
s->as s->c a->aa a->b a,s nonterminals , a,b,c terminals.
this construction of i0
i0: s' -> .s, epsilon --------------- s -> .as, epsilon s -> .c, epsilon --------------- s -> .as, s -> .c, c -> .aa, -> .b, b
and i1.
from s, i1: s' -> s., epsilon //done
and on. when constructing i4...
from a, i4: -> a.a, ----------- -> .aa, -> .b, b
the problem -> .aa
when attempt construct next state a, i'm going once again exact same content of i4, , continues infinitely. similar loop occurs with
s -> .as
so, doing wrong? there has detail i'm missing, i've browsed notes , book , either can't find or don't understand what's wrong here. help?
i'm pretty sure figured out answer. obviously, states can point each other, eliminates need create new ones if it's content exists. i'd still if can confirm this, though.
Comments
Post a Comment