Re: Lex and Start Conditions (Brian Bliss)
Thu, 24 Jan 91 21:54:49 GMT

          From comp.compilers

Related articles
Lex and Start Conditions (1991-01-24)
Re: Lex and Start Conditions (1991-01-24)
Re: Lex and Start Conditions (1991-01-24)
| List of all articles for this month |

Newsgroups: comp.compilers
From: (Brian Bliss)
Keywords: lex
Organization: Center for Supercomputing Research and Development
References: <>
Date: Thu, 24 Jan 91 21:54:49 GMT

To make you lexer start out in a non-default start condition,
just write a routine lex_init (), and put it in the routines
section of the lex file:

void lex_init () { BEGIN STATE; }

then call lex_init () from the main program before parsing.
these's no reason it hash to be in the main program.


P.S. You wouldn't want to use the undocumented INITIAL start condition.
Even if you are in the COMMENT start condition, rules which have
INITIAL start condition will still be recognized. Then,
lex will try to break up the inside of your comments into tokens
before it realizes that the entire comment is a longer token itself,
and chooses this based on the fact that it is longer. all of this
makes the lexer take up much more space: a simple pascal lexer I wrote,
using the INITIAL start condition for normal code (idents, etc),
produced a 300K object file, but when I added the NORMAL start condition
to every rule which had the INITIAL start condition, the object
shrunk to 30K!

[From (Brian Bliss)]

Post a followup to this message

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