Sup expert programmers. My task is to write a .lex file for jflex in order to generate a lexical scanner. I have everything ready, except for the declarations of IDENT and NUMBER:
ALPHA=[A-Za-z]
DIGIT=[0-9]
({ALPHA}({DIGIT}|{ALPHA})*) { value = /* ? */ return TokenType.IDENT; }
({DIGIT}+) { value = /* ? */ return TokenType.NUMBER; }
As you can see, I don't know how I should assign a value to ident and number. The task is: Ident should have its name as a String as the value and Number should have its own int value as a value. How would I go about doing this?
>>6
Still, it's better than Nothing. It's better to try and fail than never to try at all.
Name:
Anonymous2009-05-13 10:47
>>4
You should have a Symbol class (or equivalent) lying somewhere, either your own or one provided by a lexical analyzer (like javacup). Instead of an integer representing the token, return an instance of this class with the type of the token and its value :
({ALPHA}({DIGIT}|{ALPHA})*) { return new Symbol(TokenType.IDENT, new String(yytext()));}
>>13
Sup expert programmers. My task is to write a .lex file for jflex in order to generate a lexical scanner. I have everything ready, except for the declarations of IDENT and NUMBER: