在 http://hackingoff.com/compilers/ll-1-parser-generator 解释解析 Table
Explain Parsing Table at http://hackingoff.com/compilers/ll-1-parser-generator
我在 http://hackingoff.com/compilers/ll-1-parser-generator 中使用以下语法:
E -> T E'
E' -> + T E'
E' -> EPSILON
T -> F T'
T' -> * F T'
T' -> EPSILON
F -> ( E )
F -> id
输出解析 Table 是
[
[0, "+", "*", "(", ")", "id", "$"],
[0, 0, 0, 0, 0, 0, 0],
[0, 10, 10, 1, 9, 1, 9],
[0, 2, 10, 10, 3, 10, 3],
[0, 9, 10, 4, 9, 4, 9],
[0, 6, 5, 10, 6, 10, 6],
[0, 9, 9, 7, 9, 8, 9]
]
有人可以解释一下解析 table 吗?特别是,鉴于生产规则中只有 8 行
,9
和 10
的含义是什么
它在页面本身中进行了解释,就在 table:
的上方
If a terminal is absent from a non-terminal's predict set, an error code is placed in the table. If that terminal is in follow(that non-terminal), the error is a POP error. Else, it's a SCAN error.
POP error code = # of predict table productions + 1
SCAN error code = # of predict table productions + 2
所以对于具有八个产生式规则的文法,值 9 和 10 分别是 POP error
和 SCAN error
。
我在 http://hackingoff.com/compilers/ll-1-parser-generator 中使用以下语法:
E -> T E'
E' -> + T E'
E' -> EPSILON
T -> F T'
T' -> * F T'
T' -> EPSILON
F -> ( E )
F -> id
输出解析 Table 是
[
[0, "+", "*", "(", ")", "id", "$"],
[0, 0, 0, 0, 0, 0, 0],
[0, 10, 10, 1, 9, 1, 9],
[0, 2, 10, 10, 3, 10, 3],
[0, 9, 10, 4, 9, 4, 9],
[0, 6, 5, 10, 6, 10, 6],
[0, 9, 9, 7, 9, 8, 9]
]
有人可以解释一下解析 table 吗?特别是,鉴于生产规则中只有 8 行
,9
和 10
的含义是什么
它在页面本身中进行了解释,就在 table:
的上方If a terminal is absent from a non-terminal's predict set, an error code is placed in the table. If that terminal is in follow(that non-terminal), the error is a POP error. Else, it's a SCAN error.
POP error code = # of predict table productions + 1
SCAN error code = # of predict table productions + 2
所以对于具有八个产生式规则的文法,值 9 和 10 分别是 POP error
和 SCAN error
。