Search code examples
parsingcompiler-constructiongrammardfa

Question Regarding Non-Terminal On Bottom Up Parsing


If the DFA halts at a state where all the items say to shift; but after the dot none of the items match the next input token. Do we investigate the non-terminals after the dot or not? Or do we immediately reject it?

Example

Assume in this example the DFA terminated at this state: do I immediately reject? Or do I investigate the non-terminals after the dot? And see whether if the next symbol in their first/follow set and they can disappear?


Solution

  • If you're in a parser state where you're supposed to shift but none of the items in the state have the dot right before the current terminal, it means that the terminal can't legally appear here and you have a parsing error. There's no need to explore the nonterminals after the dots here, since in the construction of the parser state you would have already expanded out those nonterminals to see if any of them involve productions that start with the given nonterminal.

    (I'm not sure that the parser state you're describing here could actually exist if T is a nonterminal. If T is a nonterminal, then for each production of the form T → ω you would also see T → ·ω as one of the production items in the state.)