Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!hao!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.wizards Subject: Re: Do start conditions work in lex? Message-ID: <8706@mimsy.UUCP> Date: Wed, 23-Sep-87 00:54:32 EDT Article-I.D.: mimsy.8706 Posted: Wed Sep 23 00:54:32 1987 Date-Received: Sat, 26-Sep-87 00:48:03 EDT References: <6@radix> <1516@epimass.EPI.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 26 Keywords: lex, bug >In article <6@radix> jimv@radix.UUCP (Jim Valerio) writes: >>... it looks like lex is not doing the right thing with start conditions. In article <1516@epimass.EPI.COM> jbuck@epimass.EPI.COM (Joe Buck) writes: >Your problem is that a pattern without a start condition matches >regardless of start condition. So with the following lex code: >> 0 { printf("0\n"); BEGIN Z; } >> 1 { printf("shouldn't get here!\n"); } >> 1 { printf("1\n"); } >... Solution: reverse the order, to > 0 { printf("0\n"); BEGIN Z; } > 1 { printf("1\n"); } > 1 { printf("shouldn't get here!\n"); } Or use 1 { printf("shouldn't get here!\n"); } 1 { printf("1\n"); } Lex begins in state INITIAL; if there are no `%state's or BEGIN directives, it stays that way forever. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris