|JLex and CUP Help!! firstname.lastname@example.org (2002-02-28)|
|Re: JLex and CUP Help!! email@example.com (2002-03-09)|
|Date:||9 Mar 2002 03:09:49 -0500|
|Posted-Date:||09 Mar 2002 03:09:49 EST|
This may not be helpful, sorry. CUP uses a slightly different syntax
than YACC (BISON and etc.). Other than that, the expressions are
identical. From memory, one possible syntax (in YACC) for the
conditional expression is:
condExpression : IF '(' boolean_expression ')' THEN '(' expression
| IF '(' boolean_expression ')' THEN '(' expression
ELSE '(' expression ')'
Where: IF, THEN, and ELSE are keywords returned by the lexer,
'(' is (also) returned by the lexer, and
boolean_expression and expression are other syntactic elements
in your language.
; is a symbol in the CUP/YACC meta-language
This is all from memory and since I haven't input it to YACC it might
have a problem. However, the idea is there.
If the parenthesis are not required then you might have a LALR(1)
conflict (or two). If you do, you might consider adding an expression
terminator (';') or separator.
> I am trying to learn JLex and CUP again after a long time of not using
> I want to model a simple IF-ELSE statement in CUP. I think I can
> figure out the JLex, but the CUP is giving me trouble.
> Problem I want to represent:
> IF (BOOLEAN EXPRESSION) THEN (EXPRESSION) ELSE (EXPRESSION)
Return to the
Search the comp.compilers archives again.