Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!mintaka!spdcc!iecc!compilers-sender From: bliss@sp64.csrd.uiuc.edu (Brian Bliss) Newsgroups: comp.compilers Subject: Re: Lex and Start Conditions Keywords: lex Message-ID: <1991Jan24.215449.17993@csrd.uiuc.edu> Date: 24 Jan 91 21:54:49 GMT References: Sender: compilers-sender@iecc.cambridge.ma.us Reply-To: bliss@sp64.csrd.uiuc.edu (Brian Bliss) Organization: Center for Supercomputing Research and Development Lines: 28 Approved: compilers@iecc 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. bb 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! bb [From bliss@sp64.csrd.uiuc.edu (Brian Bliss)] -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.