Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!epiwrl!epimass!jbuck From: jbuck@epimass.EPI.COM (Joe Buck) Newsgroups: comp.unix.wizards Subject: Re: Do start conditions work in lex? Message-ID: <1516@epimass.EPI.COM> Date: Tue, 22-Sep-87 13:43:11 EDT Article-I.D.: epimass.1516 Posted: Tue Sep 22 13:43:11 1987 Date-Received: Thu, 24-Sep-87 05:33:31 EDT References: <6@radix> Reply-To: jbuck@epimass.EPI.COM (Joe Buck) Organization: Entropic Processing, Inc., Cupertino, CA Lines: 27 Keywords: lex, bug Summary: Yes, they do In article <6@radix> jimv@radix.UUCP (Jim Valerio) writes: >I've been debugging a problem parsing dates in MH mail, and have narrowed it >down to the point where it looks like lex is not doing the right thing with >start conditions. I'm having this problem on a System Vr3 80386 system, and >have reproduced the problem on a 4.3bsd Vax system. Your problem is that a pattern without a start condition matches regardless of start condition. So with the following lex code: > %start Z > %% > 0 { printf("0\n"); BEGIN Z; } > 1 { printf("shouldn't get here!\n"); } > 1 { printf("1\n"); } and the input "01", the first "1" rule matches even though you are in the Z state, because if no state is given in the rule it always matches. Solution: reverse the order, to 0 { printf("0\n"); BEGIN Z; } 1 { printf("1\n"); } 1 { printf("shouldn't get here!\n"); } since the first rule found is the one that is used. -- - Joe Buck {uunet,ucbvax,sun,decwrl,}!epimass.epi.com!jbuck Old internet mailers: jbuck%epimass.epi.com@uunet.uu.net