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 > How to create p...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 451 of 549
Post > Topic >>

How to create postfix operators?

by tactics40@[EMAIL PROTECTED] Mar 24, 2007 at 05:10 PM

I'm new to Javacc. I have a working parser for regular expressions
implemented in PLY (a Lex&Yacc for Python). The grammar looks like
this:

expression := expression OR_TOKEN term
expression := term
term := term factor
term := factor
factor := factor STAR_TOKEN
factor := LP_TOKEN expression RP_TOKEN
factor := digit | empty | null

My problem comes from the fact JavaCC doesn't sup****t left-recursion.
I have reworked expression and term to use the rules:

expression := term (OR_TOKEN term)*
term := factor (factor)*

and they are giving me the correct output. However, I don't know how
to fix the STAR_TOKEN operator. An example would be ab*a (meaning the
set of stirngs starting and ending with 'a' with any number of 'b's in
between). I have it working as a prefix-operator (ex: a*ba), but I
want to keep the standard postfix-operator convention.

Clearly, since C is implementable in JavaCC, there must be a way to
allow postfix operators. From what I've seen, it has something to do
with lookaheads. However, my knowledge of JavaCC is pretty limited,
and I don't know how to use lookaheads to solve my problem.

If anyway can offer any insight, I would much appreciate it.
 




 3 Posts in Topic:
How to create postfix operators?
tactics40@[EMAIL PROTECTE  2007-03-24 17:10:25 
Re: How to create postfix operators?
AC <user@[EMAIL PROTEC  2007-03-25 17:06:41 
Re: How to create postfix operators?
tactics40@[EMAIL PROTECTE  2007-03-25 15:00:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Fri Jul 25 20:07:47 CDT 2008.