First: What is a viable prefix?
A viable prefix is any prefix of a right sentential form that does not go beyond the handle.
In simpler shift-reduce parser terms:
👉 At any valid moment, the contents of the stack form a viable prefix.
That is the key theorem used in LR parsing.
Statement 1:
“Viable prefixes appear only at the bottom of the stack and not inside”
❌ Incorrect
Why?
If the whole stack is a viable prefix, then many prefixes of the stack are also viable prefixes.
Example stack:
id + id
Then:
can all be viable prefixes (depending on grammar).
So viable prefixes are not only bottom portion.
They can occur as prefixes inside stack growth.
Hence false.
Statement 2:
“Viable prefixes appear only at the top of the stack and not inside”
❌ Incorrect
Same reason.
Viable prefixes are not only topmost suffixes.
They are related to prefixes from bottom of stack.
Top symbols alone may not form viable prefix.
Example:
Stack =
E + T
Top = T
But viable prefix usually refers to stack content from bottom, not isolated top portion.
Hence false.
Statement 3:
“The stack contains only a set of viable prefixes”
✅ Correct
This is the standard LR parsing property.
At every valid shift-reduce step:
- stack content itself is a viable prefix
- every prefix of stack is also viable prefix
Thus stack consists of symbols whose cumulative prefixes are viable prefixes.
This is exactly why LR automata recognize viable prefixes.
Hence TRUE.
Statement 4:
“The stack never contains viable prefixes”
❌ Incorrect
Completely opposite of LR theory.
In fact:
👉 LR parser stack always represents a viable prefix at any valid state.
So false.