Xref: utzoo comp.lang.c:29262 comp.unix.wizards:22238 Path: utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!swrinde!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.c,comp.unix.wizards Subject: Re: Lex and initial start conditions Message-ID: <1990May31.161800.11133@iwarp.intel.com> Date: 31 May 90 16:18:00 GMT References: <6342@crabcake> <1990May30.174745.1161@csrd.uiuc.edu> <116@bohra.cpg.oz> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Followup-To: comp.lang.c Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 36 In-Reply-To: ejp@bohra.cpg.oz (Esmond Pitt) In article <116@bohra.cpg.oz>, ejp@bohra (Esmond Pitt) writes: | There are two even simpler ways. | | Instead of effectively changing the initial condition to , 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 | , 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.) ... 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@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/