Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Lexical Scanner

Name: Anonymous 2009-05-13 5:26

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?

Name: Anonymous 2009-05-13 5:33

Read the documentation

Name: Anonymous 2009-05-13 5:38

Read SICP, the universal documentation

Name: Anonymous 2009-05-13 5:56

I found out that there's a yytext() function that returns the matched text, so would it work if I (for the IDENT) do something like:

{ String value = yytext();   return TokenType.IDENT; }

?

Name: Anonymous 2009-05-13 6:23

>>4
Maybe, but maybe not.

Name: MAYBE MEME FAN 2009-05-13 9:56

>>5
1/10, that's Just so uncreative.

Name: Anonymous 2009-05-13 10:43

>>6
Still, it's better than Nothing. It's better to try and fail than never to try at all.

Name: Anonymous 2009-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()));}


And RTFM goddamnit :http://jflex.de/manual.html#SECTION00040000000000000000

Name: Anonymous 2009-05-13 10:50

>>7
Either that, or just train hard and then get it Right the first time.

Name: Anonymous 2009-05-13 10:55

Fuck CFGs and their archaic yacks.

Packrat parsing is the language definition of the future.

Name: Anonymous 2009-05-13 11:58

>>9
It's True, there's Just no Alternative to good hard work. There are SomeExceptions to be aware of, naturally, but they're quite rare.

Name: Anonymous 2009-05-13 12:08

Could you please take your haskell jokes outside me thread?

Name: Anonymous 2009-05-13 20:08

>>12
Maybe.

Name: Anonymous 2009-05-13 20:33

>>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:

Name: Anonymous 2010-12-06 9:17

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2011-02-03 3:07


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List