Algorithm for computing FIRST and FOLLOW sets for context-free grammars [closed]

主宰稳场 提交于 2020-05-11 06:40:30

问题


I need an algorithm to computing FIRST and FOLLOW sets for a grammar.

Is there a simple algorithm or simple code for computing these?


回答1:


The standard algorithm for computing FIRST and FOLLOW sets is discussed in most compiler textbooks and books on parsing algorithms. I would be surprised if you were taking a course where this was covered and had no assigned reading or materials provided on this topic.

I taught a class on compiler construction and have some lecture slides that might be useful here. You might want to check out slides 303-304 of these slides on LL parsing for an algorithm that computes FIRST sets and slide 32 of these slides on LL parsing for an algorithm that computes FOLLOW sets.

Hope this helps!




回答2:


This can be solved with Graphical calculation of first and follow sets of a grammar by ASR Murty.

A graphical method has been given to calculate the First and Follow sets of a grammar which is easier to apply for a learner or a student...

This graphical method is applied to the Expression Grammar to find the First and Follow sets and we also check its correctness with the help of derivations.



来源:https://stackoverflow.com/questions/19869163/algorithm-for-computing-first-and-follow-sets-for-context-free-grammars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!