为 LR(1) 解析构造状态时处理无限循环

发布于 2024-08-31 06:32:21 字数 814 浏览 2 评论 0原文

我目前正在根据以下语法构造 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流星番茄 2024-09-07 06:32:21

我很确定我找到了答案。显然,状态可以相互指向,因此如果内容已经存在,则无需创建新的状态。不过,如果有人能证实这一点,我仍然希望它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文