hi all,
i am a beginner on javacc. this question has confused me so long
time,i can't check the mistakes,so here request for help.
Here is the source code,listed as follows.it is about boolean
expression evaluation program.for example: if (89>9 and 'a'>'b') is
false ,then print false.
my question is that the second expression ('a'>'b')after 'and',can't
be parsed every time.i can't find the reason.please help me .
Thanks for any reply!
PARSER_BEGIN(Exper)
public class Exper{
}
PARSER_END(Exper)
/*number */
TOKEN:{
<NUMBER: (["0"-"9"])+ >
}
/*operator*/
TOKEN:{
<LPAREN: "(">
|<RPAREN: ")">
|<LT: "<">
|<GT: ">">
|<LE: "<=">
|<GE: ">=">
|<EQ: "==">
|<NE: "!=">
|<AND: "and">
|<OR: "or">
|<NOT: "not">
}
/*white space*/
SKIP:
{" "|"\n"|"\r"|"\t"
}
/*quoted String */
TOKEN:{<STRING:
"\'" (~["\n","\r","\'"])* "\'">
}
Boolean exp():
{Boolean l,r;}
{ l=lex(){return l;} (<AND> r=lex()
{
if(l.booleanValue()&& r.booleanValue())
return Boolean.TRUE;
else
return Boolean.FALSE;}
|<OR> r=lex() {if (l.booleanValue()||r.booleanValue())
return Boolean.TRUE;
else
return Boolean.FALSE;
})*
}
Boolean lex():
{ Boolean t;}
{ <NOT> t=rex(){ if(t.booleanValue())
return Boolean.FALSE;
else
return Boolean.TRUE;}
|t=rex(){return t;}
}
Boolean rex():
{ Boolean t;
Object l,r; }
{ l=atom()
(<GT> r=atom(){return Util.gt(l,r);}|<LT>r=atom(){return
Util.lt(l,r);}|
<GE>r=atom(){return Util.ge(l,r);}|<LE>r=atom(){return
Util.le(l,r);}|<EQ>r=atom(){return Util.eq(l,r);}
| <NE>r=atom(){return Util.ne(l,r);})*
}
Object atom():
{
Token t,str;
Boolean s;}
{ t=<NUMBER>{return new Double(t.image);}|str=<STRING>{return
(str.image.substring(1,str.image.length()-1));}|
<LPAREN>s=exp(){ return s; }<RPAREN>
}


|