Flex and Lex interpreting regex differently

mjmjenks@gmail.com
Mon, 13 Oct 2008 00:01:45 -0700 (PDT)

          From comp.compilers

Related articles
Flex and Lex interpreting regex differently mjmjenks@gmail.com (2008-10-13)
Re: Flex and Lex interpreting regex differently jdenny@ces.clemson.edu (Joel E. Denny) (2008-10-13)
Re: Flex and Lex interpreting regex differently mjmjenks@gmail.com (2008-10-13)
| List of all articles for this month |
From: mjmjenks@gmail.com
Newsgroups: comp.compilers
Date: Mon, 13 Oct 2008 00:01:45 -0700 (PDT)
Organization: Compilers Central
Keywords: lex
Posted-Date: 13 Oct 2008 05:37:09 EDT

Hi,


It looks like I'm having an issue with the portability of one of my
regular expressions.


The following is a regular expression for a real number in a language:


real -> digit (digit)* '.' digit (digit)* ScaleFactor
ScaleFactor -> ('E' | 'D') ('+' | '-' )? digit (digit)*


where terminals are in single quotes.


I've implemented this with the following Lex rule (with extra brackets
to be safe):


digit [0-9]
ScaleFactor [ED]([\+\-]?){digit}+


%%


({digit}+)[\.]({digit}+)({ScaleFactor}?) {printf("Real number
token");};




This works for me on my Linux box using Flex, but doesn't seem to work
on a Solaris machine using Lex.


I believe Flex is a superset of Lex. So am I using some sort of Flex
construct that isn't supported by Lex? Or just doing something non-
portable in general? I can't see anything wrong myself :\




Thanks!


Mike
[Lex is really buggy, one of the reasons that nobody uses it any more.
(I would complain to the guy who wrote it, but he's busy with his day
job at Google.) As I recall, nested macros don't work very well so
you might try expanding out the digit and scalefactor macros and see
if that helps. But my advice would be to run your lexer through flex
on another machine, then include the generated .c file in your collection
of source code for the benefit of the few systems still using lex. -John]



Post a followup to this message

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