Re: how to handle lookahead in JLex?

Gerwin Klein <kleing@informatik.tu-muenchen.de>
1 Nov 1998 11:42:08 -0500

          From comp.compilers

Related articles
how to handle lookahead in JLex? jwilleke@ix.netcom.com (1998-10-24)
Re: how to handle lookahead in JLex? jwilleke@ix.netcom.com (1998-10-30)
Re: how to handle lookahead in JLex? cfc@world.std.com (Chris F Clark) (1998-10-30)
Re: how to handle lookahead in JLex? kleing@informatik.tu-muenchen.de (Gerwin Klein) (1998-11-01)
| List of all articles for this month |
From: Gerwin Klein <kleing@informatik.tu-muenchen.de>
Newsgroups: comp.compilers
Date: 1 Nov 1998 11:42:08 -0500
Organization: Technische Universitaet Muenchen, Germany
References: 98-10-155
Keywords: Java, lex

Jon Willeke wrote:
> I'm using JLex to write a lexer for M. I have a case that calls for
> lookahead, which JLex doesn't support. [..]
This may not be exactly what you asked for, but it could help anyway:


The scanner generator JFlex (http://www.in.tum.de/~kleing/jflex/)
has a pushback method (similair to unput(c)) that should be able
to handle your problem.


Something like:


WSP = [ \t\r\n] | \r\n


Ident = [a-zA-Z] [a-zA-Z0-9]*
FCall = {Ident} {WSP}* "("


%%


{Ident} { return new Token(IDENT); }
{FCall} { yy_pushback(1); /* push back the last character */
                          return new Token(F_CALL); }


should do what you want.


BTW: JFlex also reads JLex specifications, so you wouldn't need
to change them


shamelessly promoting JFlex :-)
Gerwin


Post a followup to this message

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