cup dilemma  
Author Message
Manuel





PostPosted: 2006-8-3 18:39:00 Top

java-programmer, cup dilemma Hi all,
I'm making a parser with java_cup and jlex, it must recognize a language
like this:

// Definition of the apparel heads:
dress = [quality->10, woven->8];
shirt = [quality->10, woven->8];
?
// Description of the apparel heads:
BOSSdress = quality *, woven -: dress;
dressofValentino = quality *, woven +: dress;
shirtofArmani = quality +, woven +: shirt;

The definition of the apparel heads is made with this cup code:

non terminal frasi, frase;
frasi ::= frasi frase | frase;

frase ::= LETTER:var EQ QO LETTER:attr ARROW NUMBER:n QC SEMI
{:
System.out.print("Ist: " + var);
System.out.print(" attrib: " + attr);
System.out.println(" value: " + n);
:};

Now I need recognize the second part of language, but how I can
distinguish by the '?' ?

JLex code:
%%
%cup

%%
";" { return new Symbol(sym.SEMI); }
"=" { return new Symbol(sym.EQ); }
"->" { return new Symbol(sym.ARROW); }
"[" { return new Symbol(sym.QO); }
"]" { return new Symbol(sym.QC); }
"?" { return new Symbol(sym.ASKP); }
[0-9]+ { return new Symbol(sym.NUMBER, new Integer(yytext())); }
[a-zA-Z]+ { return new Symbol(sym.LETTER, new String(yytext())); }
[ \t\r\n\f] { /* ignore white space. */ }
. { System.err.println("Illegal character: "+yytext()); }

Thanks in advance