[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: if/else if



Sorry, please ignore the last message. I actually had an unused token "elseif" defined.
Even though grammer does not use it, I guess it causes trouble to the parser.
 
Thanks for the help.
 
Yuntao Cui
 
----- Original Message -----
From: yuntao
To: Etienne M. Gagnon ; sablecc-list@sable.mcgill.ca ; Roger Keays
Cc: yuntao@eventmonitor.com
Sent: Tuesday, October 02, 2001 2:39 PM
Subject: 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