[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
if/else if
Hi,
Thanks for the help. Now I changed my grammer like
the sample java grammer as follows:
if_statement={if_else} if
l_par general_expression r_par [true]:statement_no_if else [false]:statement
|
{if} if l_par
general_expression r_par statement;
if_statement_no_if =
{if_else} if l_par general_expression r_par [true]:statement_no_if else
[false]:statement_no_if;
It solves reduce/shift problem. Now I can build the
parser. Everything works fine for my code except
that I can not put "else if" together. For example,
all the followings are fine:
1) "if (a>5) {b=5;}"
2) "if (a>5) {b=5;} else {c=5;}"
3) "if (a>5) {b=5;} else {if(a>4)
{;}}"
But if I put "else if" together, like
"if (a>5) {b=5;} else if (a>4) {b=3;}", then
I got the following error message:
"parser.ParserException: [1,17] expecting: EOF",
the position is pointing to the beginning of
the "else". Please let me what is your
thought.
Thanks a lot.
Yuntao Cui