Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!samsung!think.com!mintaka!spdcc!iecc!compilers-sender From: peter@objy.com (Peter Moore) Newsgroups: comp.compilers Subject: Re: Lex and Start Conditions Keywords: lex Message-ID: <1991Jan24.224814.24607@objy.com> Date: 24 Jan 91 22:48:14 GMT References: Sender: compilers-sender@iecc.cambridge.ma.us Reply-To: peter@objy.com (Peter Moore) Organization: Objectivity Inc. Lines: 32 Approved: compilers@iecc.cambridge.ma.us In article , eifrig@server.cs.jhu.edu (Jonathan Eifrig) writes: ..... |> This works great, except that the automaton has to be started up in the |> correct (meta) state (in this case, NORM). What is the best way to do this? This (along with the documentation) are my two biggest complaints with lex. Here is my solution (with minor flame intact). Peter Moore peter@objy.com . | \n { /* * Lex has the misfeature that all unlabeled rules are * always active. This makes interference between labeled * and unlabeled rules a big problem. To overcome this, * every rule is labeled, with the normal state being * NORMAL_MODE. To get ourselves into NORMAL_MODE at the * start, we use this rule that matches any character. It * simply switches to NORMAL_MODE and pushes back the * character that triggered it. Anytime after, this rule * is shielded by .|\n rules in all the other modes. */ unput(yytext[0]); START_MODE(NORMAL_MODE); NLSTATE; /* otherwise beginning of line rules won't work */ } [Should work, but I still like exclusive start states in flex. -John] -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.