Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-spam!ames!sdcsvax!ucsdhub!esosun!seismo!uunet!mcvax!dnlunx!stan From: stan@dnlunx.UUCP Newsgroups: comp.unix.wizards Subject: Re: Do start conditions work in lex? Message-ID: <263@dnlunx.UUCP> Date: Mon, 21-Sep-87 10:17:42 EDT Article-I.D.: dnlunx.263 Posted: Mon Sep 21 10:17:42 1987 Date-Received: Sat, 26-Sep-87 13:46:55 EDT References: <6@radix> Organization: Dr Neher Laboratory (PTT) Lines: 26 Keywords: lex, bugs Summary: not a bug, a feature. In article <6@radix>, jimv@radix (Jim Valerio) writes: > [...] it looks like lex is not doing the right thing with > start conditions [...] > [...] > Am I missing something obvious here, or is there a bug in lex? > If it is a bug, can someone suggest a reasonable workaround? First of all, when lex tries to match some part of the input string against the specified rules, it will take the rule with the longest match. When more than one rule matches, lex decides in favor of the rule which is first encountered in the lex file. After the `BEGIN Z;' statement all rules starting with `' are active, together with all rules without a start condition. -------- ---- --- ----- ------- - ----- --------- Your example should work if you swap the rules in which the `1' is matched, resulting in: %% 0 { printf("0\n"); BEGIN Z; } 1 { printf("1\n"); } 1 { printf("shouldn't get here!\n"); } . { printf("Error! (%c)\n", yytext[0]); } Stan ----