If I want to use a predictive parser the following grammar is not suitable:
E -> T + E | T
As I understand the problem with this grammar is that the non-terminal T
is specified in multiple productions. So if a parser looks ahead the next token T
it doesn't know which production to use because T
is mentioned in several productions.
So the grammar has to be refactored to
E -> T X
X -> +E | e
Now, if I look at the EcmaScript grammar most non-terminal symbols have multiple productions with the same non-terminal. For example, PropertyDefinition
symbol is repeated in both productions:
PropertyDefinitionList[Yield, Await]:
PropertyDefinition[?Yield, ?Await]
PropertyDefinitionList[?Yield, ?Await], PropertyDefinition[?Yield, ?Await]
So is my understanding correct that the EcmaScript grammar is not left-factored and if I want to use with a predictive top-down parser it has to be refactored?