Re: First lex script. Parsing C expressions.

Pete Jinks <peter.jinks@manchester.ac.uk>
3 Aug 2006 10:52:58 -0400

          From comp.compilers

Related articles
First lex script. Parsing C expressions. patrik.weibull@gmail.com (2006-07-31)
Re: First lex script. Parsing C expressions. peter.jinks@manchester.ac.uk (Pete Jinks) (2006-08-03)
| List of all articles for this month |

From: Pete Jinks <peter.jinks@manchester.ac.uk>
Newsgroups: comp.compilers
Date: 3 Aug 2006 10:52:58 -0400
Organization: School of Computer Science, University of Manchester
References: 06-07-112
Keywords: parse, lex

patrik.weibull@gmail.com wrote:
> Hello. I'm writing my first lex-fil. It's supposed to recognize tokens
> from C - ultimately, I want to match expressions. An expression can
> contain an expression - so there is recursion allowed.


I wouldn't want to use lex by itself for something this complicated,
I would use lex and yacc together.
How do you intend to cope with the recursion otherwise?


> W [ \t]* /* Whitespace */


Don't try to use comments like this


> {UNARY_POSTFIX_EXPRESSION}|sizeof{{W}*{VALUE}{W}*}|({W}*TYPE{W}*){W}*{IDENTIFIER}


You have extra { } after sizeof


> But, flex complains about unrecognized rules when I try matching
> {EXPRESSION} later in the
> script. This is my first lex program, and my wish is that anyone here
> would point out simple errors that I've made.


flex accepts it with these fixes.
I haven't tested it to see what it actually matches.


> ~Patrik
> [I've never had much luck with complicated named patterns. -John]


I've never tried to use anything this complex.


--
Peter J. Jinks, Room 2.72, School of Computer Science,
University of Manchester, Oxford Road, Manchester, M13 9PL, U.K.
(+44/0)161-275 6186 http://www.manchester.ac.uk/cs/people/jinks



Post a followup to this message

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