帮助理解 LR(1) 解析器、表生成?还有其他资源吗?

发布于 2024-10-20 09:08:27 字数 228 浏览 1 评论 0 原文

我目前正在学习编译器课程,并且很难理解使用操作/转到表的 LR(1) 解析算法以及如何手动生成这些表。现在我们正在使用 Cooper 和 Torczon 编写的 Engineering a Compiler 作为我们的课堂教科书,我也阅读了有关表生成的维基百科页面,但我仍然不理解这些概念。如果可能的话,有人可以推荐任何其他很好地解释解析的书或在线资源吗?我认为许多大学都会有关于该主题的良好在线资源/幻灯片,但我不知道从哪里开始寻找。谢谢!

I am currently taking a compilers class and I am having a hard time understanding LR(1) parsing algorithms using the action/goto table and also how to hand generate these tables. Right now we are using Engineering a Compiler by Cooper and Torczon as our class text book and I have also read the wikipedia pages on table generation but I still do not understand the concepts. If possible can anyone recommend any other book that explains parsing well or an online resource? I would think many universities would have good online resources/slides on the subject but I have no idea on where to start looking. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

眼趣 2024-10-27 09:08:27

由于算法细节,这些书总是很难读。希腊符号和抽象运算很难解释,除非您已经知道它们的含义。

我学习如何做到这一点的方法是编写一个小语法(简单的表达式,
赋值语句、if then 语句、语句序列),然后手动模拟算法。拿一张非常大的纸。仅使用目标符号和点 [ G = DOT RHS1 ... RHSM ] 绘制起始配置状态。然后对未处理的状态进行处理,详细遵循算法;写下每个希腊符号当时代表的含义。当你获得自信时,你会感觉更好,而且进展会更快。

本质上,您要做的是,对于处于

 [LHS RHS1 DOT RHS2 RHS3 ... RHSN] 

某个状态的每个项目,将项目中的点向右推一个位置以生成一个新项目,

 [LHS RHS1 RHS2 DOT RHS3 ... RHSN ]

在纸上绘制一个新状态,以该项目为种子,填写具有基于 FIRST(RHS3) 的前瞻集的项目核心,扩展状态,然后重复。

第一次尝试时,这将花费您几个小时。每一秒都值得。
使用铅笔!

The books are always hard to read because of the algorithm details. Greek symbols and abstract operations are hard to interpret unless you already know what they mean.

The way I learned how to do this, was to write a tiny grammar (simple expression,
assignment statement, if then statement, sequence of statements), and then hand simulate the algorithm. Get a really big piece of paper. Draw the starting configuration state with just the goal symbol and dot [ G = DOT RHS1 ... RHSM ]. Then process the unprocessed states, following the algorithm in detail; write down what each greek symbol represents at that moment. As you gain confidence, you'll get a better feeling and it will go faster.

Essentially what you are going to do is, for each item I

 [LHS RHS1 DOT RHS2 RHS3 ... RHSN] 

in a state, push the dot in item one place to right to produce a new item

 [LHS RHS1 RHS2 DOT RHS3 ... RHSN ]

draw a new state on your paper new state with that item as the seed, fill out the item core with lookahead sets based on FIRST(RHS3), expand the state, and repeat.

This will take you several hours the first time you try it. Worth every second.
Use a pencil!

娇女薄笑 2024-10-27 09:08:27

一些不错的讲义...

http://cs.oberlin.edu/~jdonalds /331/lecture14.html

理解和编写编译器有一节,LR(1) 分析的真正优势是什么?

http://www.amazon.com/Understanding-Writing-Compilers-Yourself-Macmillan/ dp/0333217322

(也可以在线免费获得)

这里有一个不错的摘要的链接,尽管缺乏解释。

http://arantxa.ii.uam.es/~modonnel/Compilers/ LR1Summary.pdf

更多讲义...

http ://www.cs.umd.edu/class/spring2011/cmsc430/lectures/lec07.pdf

和注释在这里...

http://cobweb.ecn.purdue.edu/~smidkiff/ece495S/files/handouts/w3w4bBW.pdf

(包括转到和行动表)

抱歉,我无法亲自解释,我自己也不太确定。也许你会发现周围有一个善良、知识渊博的灵魂。

some decent lecture notes...

http://cs.oberlin.edu/~jdonalds/331/lecture14.html

Understanding and Writing Compilers has a section, What are the True Advantages of LR(1) Analysis?

http://www.amazon.com/Understanding-Writing-Compilers-Yourself-Macmillan/dp/0333217322

(also available freely online)

Here is a link to a decent summary, although explanation is lacking.

http://arantxa.ii.uam.es/~modonnel/Compilers/LR1Summary.pdf

more lecture notes...

http://www.cs.umd.edu/class/spring2011/cmsc430/lectures/lec07.pdf

and notes here...

http://cobweb.ecn.purdue.edu/~smidkiff/ece495S/files/handouts/w3w4bBW.pdf

(including goto and action tables)

Sorry I can't explain personally, I'm not too sure myself. Maybe you will find a kind, more knowledgeable soul around.

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