Re: Lex and Start Conditions

peter@objy.com (Peter Moore)
Thu, 24 Jan 91 22:48:14 GMT

          From comp.compilers

Related articles
Lex and Start Conditions eifrig@server.cs.jhu.edu (1991-01-24)
Re: Lex and Start Conditions bliss@sp64.csrd.uiuc.edu (1991-01-24)
Re: Lex and Start Conditions peter@objy.com (1991-01-24)
| List of all articles for this month |
Newsgroups: comp.compilers
From: peter@objy.com (Peter Moore)
Keywords: lex
Organization: Objectivity Inc.
References: <eifrig.664691313@voronoi.cs.jhu.edu>
Date: Thu, 24 Jan 91 22:48:14 GMT

In article <eifrig.664691313@voronoi.cs.jhu.edu>, 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]
--


Post a followup to this message

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