Re: JLex and CUP Help!! (skidmarks)
9 Mar 2002 03:09:49 -0500

          From comp.compilers

Related articles
JLex and CUP Help!! (2002-02-28)
Re: JLex and CUP Help!! (2002-03-09)
| List of all articles for this month |

From: (skidmarks)
Newsgroups: comp.compilers
Date: 9 Mar 2002 03:09:49 -0500
References: 02-02-071
Keywords: Java, parse
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
> it.
> 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:

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.