为 LR(1) 解析构造状态时处理无限循环
我目前正在根据以下语法构造 LR(1) 状态。
S->AS
S->c
A->aA
A->b
where A,S are nonterminals and a,b,c are terminals.
这就是I0和I1的构造
I0: S' -> .S, epsilon
---------------
S -> .AS, epsilon
S -> .c, epsilon
---------------
S -> .AS, a
S -> .c, c
A -> .aA, a
A -> .b, b
。
From S, I1: S' -> S., epsilon //DONE
等等。但当我开始建造 I4 时......
From a, I4: A -> a.A, a
-----------
A -> .aA, a
A -> .b, b
问题是 A-> .aA
当我尝试从 a 构造下一个状态时,我将再次获得 I4 的完全相同的内容,并且这种情况会无限地继续。类似的循环发生在
S -> .AS
So, What am I do bad?我一定遗漏了一些细节,但我浏览了我的笔记和书,要么找不到,要么只是不明白这里出了什么问题。有什么帮助吗?
I'm currently constructing LR(1) states from the following grammar.
S->AS
S->c
A->aA
A->b
where A,S are nonterminals and a,b,c are terminals.
This is the construction of I0
I0: S' -> .S, epsilon
---------------
S -> .AS, epsilon
S -> .c, epsilon
---------------
S -> .AS, a
S -> .c, c
A -> .aA, a
A -> .b, b
And I1.
From S, I1: S' -> S., epsilon //DONE
And so on. But when I get to constructing I4...
From a, I4: A -> a.A, a
-----------
A -> .aA, a
A -> .b, b
The problem is
A -> .aA
When I attempt to construct the next state from a, I'm going to once again get the exact same content of I4, and this continues infinitely. A similar loop occurs with
S -> .AS
So, what am I doing wrong? There has to be some detail that I'm missing, but I've browsed my notes and my book and either can't find or just don't understand what's wrong here. Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定我找到了答案。显然,状态可以相互指向,因此如果内容已经存在,则无需创建新的状态。不过,如果有人能证实这一点,我仍然希望它。
I'm pretty sure I figured out the answer. Obviously, states can point to each other, so that eliminates the need to create new ones if it's content already exists. I'd still like it if someone can confirm this, though.