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.


|