像这样的EBNF
Goal = Stmt
Stmt = "if" "expr" "then" Stmt ("else" Stmt)?
Stmt = "S"
我应该将其转换为
Goal = Stmt
X = "else" Stmt
Stmt = "if" "expr" "then" Stmt | "if" "expr" "then" Stmt X
Stmt = "S"
或者
Goal = Stmt
Stmt = "if" "expr" "then" Stmt | "if" "expr" "then" Stmt "else" Stmt
Stmt = "S"
这两个 BNF 对 GLR 解析器的含义相同吗?
------------------------ 附加内容 ------------------------ ------
如果词法是
"if" "expr" "then" "if" "expr" "then" "S" "else" "S"
GLR 解析器应该得到两棵树
Goal
Stmt
"if"
"expr"
"then"
Stmt
"if"
"expr"
"then"
Stmt
"S"
"else"
Stmt
"S"
和
Goal
Stmt
"if"
"expr"
"then"
Stmt
"if"
"expr"
"then"
Stmt
"S"
"else"
Stmt
"S"
但是第一个转换的 BNF 只能得到第一棵树,因为当它遇到时"else"
,reduce/shift 没有冲突,冲突在遇到 X。
第二个 BNF 在遇到时会发生 reduce/shift 冲突"else"
,因此解析器将拆分为两个线程在不同的条件下进行解析。
我对吗?是否有任何 ACTION、GOTO TABLE 生成器可以像对待第二个 BNF 一样对待第一个 BNF?