0
$\begingroup$

Shift means that you need to put the status and terminal symbol on the stack. But what is the terminal symbol used for? After all, if the reduce command is executed, both the state and the terminal symbol are deleted and the terminal symbol will never be used.

Why not push into the stack only state?

(English is not my native language, so please be kind to my mistakes)

$\endgroup$
  • $\begingroup$ Can you provide some more context? It seems that you're talking about some kind of parser? $\endgroup$ – Steven Apr 15 at 14:03
  • $\begingroup$ The terminal is not shifted onto the stack; as you say, only the state is necessary. What is the source for your statement? $\endgroup$ – rici Apr 15 at 14:22
0
$\begingroup$

You are talking about the typical description of LR parsing. And you are completely right, the "state" (if you look closely, it is the state of the DFA that recognizes left hand sides of productions when processing the current stack's contents) encodes all information needed. Adding the symbol is redundant. As far as I can tell, it is usually added to clarify what is going on (just a list of state numbers would be completely opaque).

| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Thanks for you answer. $\endgroup$ – none9632 Apr 15 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.