请向我解释 "Compilers. Dragon book" 练习 2.2.1 的解决方案
Please, explain me a solution to exercise 2.2.1 of "Compilers. Dragon book"
练习和适当的解决方案写在这里:https://github.com/fool2fish/dragon-book-exercise-answers/blob/34db00b33f727571d4f0f338147f1eeaf18712b3/ch02/2.2/2.2.md#221
练习指出:
Consider the context-free grammar:
S -> S S + | S S * | a
1. Show how the string aa+a* can be generated by this grammar.
2. Construct a parse tree for this string.
3. What language does this grammar generate? Justify your answer.
我无法理解作者在“这个语法如何生成字符串...”下的意思。我重新阅读了这篇文章,但仍然不知道它是什么。我很难理解构建解析树的所有步骤以及为什么可以有 3 个子节点
语法的意思是你可以把任何一个S变成3个选项之一。因此,要创建 aa+a*,您假设从单个 S 开始。
对这个 S 你应用第二条规则,你得到 SS*
现在在这个 SS* 最左边的 S 应用第一条规则,剩下 SS+S*
现在,您将第三条规则应用于每个 S,从而为您留下所需的单词 aa+a*
练习和适当的解决方案写在这里:https://github.com/fool2fish/dragon-book-exercise-answers/blob/34db00b33f727571d4f0f338147f1eeaf18712b3/ch02/2.2/2.2.md#221
练习指出:
Consider the context-free grammar:
S -> S S + | S S * | a
1. Show how the string aa+a* can be generated by this grammar.
2. Construct a parse tree for this string.
3. What language does this grammar generate? Justify your answer.
我无法理解作者在“这个语法如何生成字符串...”下的意思。我重新阅读了这篇文章,但仍然不知道它是什么。我很难理解构建解析树的所有步骤以及为什么可以有 3 个子节点
语法的意思是你可以把任何一个S变成3个选项之一。因此,要创建 aa+a*,您假设从单个 S 开始。
对这个 S 你应用第二条规则,你得到 SS*
现在在这个 SS* 最左边的 S 应用第一条规则,剩下 SS+S*
现在,您将第三条规则应用于每个 S,从而为您留下所需的单词 aa+a*