Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compiler Tools JavaCC > request for he...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 467 of 549
Post > Topic >>

request for help!

by snowody@[EMAIL PROTECTED] Jul 29, 2007 at 08:19 PM

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>
}
 




 2 Posts in Topic:
request for help!
snowody@[EMAIL PROTECTED]  2007-07-29 20:19:24 
Re: request for help!
AC <user@[EMAIL PROTEC  2007-07-31 11:36:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 14:26:44 CDT 2008.