Lex and initial start conditions
Randal Schwartz
merlyn at iwarp.intel.com
Fri Jun 1 02:18:00 AEST 1990
In article <116 at bohra.cpg.oz>, ejp at bohra (Esmond Pitt) writes:
| There are two even simpler ways.
|
| Instead of effectively changing the initial condition to <Text>, either:
|
| 1. Ensure each start-state is equipped with enough rules to handle any
| possible input, and, as the documentation does state, place all the
| unlabelled rules after all the labelled rules, and/or
|
| 2. Label all the rules you only want applied in the INITAL state with
| <INITIAL>, so they won't be applied as defaults in other states.
|
| Placing non-labelled rules before labelled rules is probably the single
| most common error in writing LEX scripts, even after 15 years.
|
| I don't know why.
Because it is insufficient. It's not "first match", but "longest
match" that determines rule triggering. ("first match" applies when
the rules have the same length.)
...
<FOO>a { something; }
...
ab { something_else; }
...
will match the "something_else" clause if "ab" is seen, even in state
"FOO". I know... this bit me once.
Just another lex hacker,
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
More information about the Comp.unix.wizards
mailing list