EBNF like this
Goal = Stmt
Stmt = "if" "expr" "then" Stmt ("else" Stmt)?
Stmt = "S"
Should I Convert this to
Goal = Stmt
X = "else" Stmt
Stmt = "if" "expr" "then" Stmt | "if" "expr" "then" Stmt X
Stmt = "S"
Or
Goal = Stmt
Stmt = "if" "expr" "then" Stmt | "if" "expr" "then" Stmt "else" Stmt
Stmt = "S"
Are these two BNF mean the same to GLR parser?
------------------------ APPEND CONTENT ------------------------------
If the lexes are
"if" "expr" "then" "if" "expr" "then" "S" "else" "S"
GLR parser should get two trees
Goal
Stmt
"if"
"expr"
"then"
Stmt
"if"
"expr"
"then"
Stmt
"S"
"else"
Stmt
"S"
And
Goal
Stmt
"if"
"expr"
"then"
Stmt
"if"
"expr"
"then"
Stmt
"S"
"else"
Stmt
"S"
But the first converted BNF can only get the first tree, because when it meet "else"
, there is no conflict in reduce/shift, the conflict is at meeting X.
The second BNF will has a reduce/shift conflict when it meet "else"
, so the parser will split to two threads to parse in different conditions.
Am I right? Is there any ACTION, GOTO TABLE generator that will treat the first BNF just like the second one?