This is the skeleton of my bottom-up parser:
while (!stack.empty())
{
if (!reduce())
{
shift();
}
}
And I have these rules:
Program -> Expr
Expr -> Expr '+' Expr
Expr -> Number
Number -> FLOAT | INTEGER // These 2 are terminal symbols
If I have the following input:
2 + 3
2 gets pushed onto the stack, then gets reduced to a Number, then an Expression and then a Program. So it doesn't have any chance to parse the whole addition. How can I force the parser to parse the rest too? Should I do something like:
Program -> Expr EOF
?
Bottom-up parsing is pretty new for me so any help is appreciated.