Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bbn!papaya.bbn.com!rsalz From: rsalz@bbn.com (Richard Salz) Newsgroups: comp.lang.c Subject: Re: whats wrong with this lex grammer? (help) Message-ID: <187@papaya.bbn.com> Date: Tue, 22-Sep-87 10:15:22 EDT Article-I.D.: papaya.187 Posted: Tue Sep 22 10:15:22 1987 Date-Received: Thu, 24-Sep-87 04:39:22 EDT References: <443@aucs.UUCP> Reply-To: rsalz@bbn.com (Rich Salz) Distribution: na Organization: BBN Laboratories, Cambridge MA Lines: 37 In comp.lang.c (<443@aucs.UUCP>), 820785gm@aucs.UUCP (ANDREW MACLEOD) writes: ] how do I write a lex regexp that recognizes comments (* .... *) ? You're probably better off doing what I did. This is from "real-life" code: /* State of our comment automata. */ typedef enum { S_STAR, S_NORMAL, S_END } STATE; "/*" { /* Comment. */ register STATE S; for (S = S_NORMAL; S != S_END; ) switch (input()) { case '\0': S = S_END; break; case '*': S = S_STAR; break; case '/': if (S == S_STAR) { S = S_END; break; } /* FALLTHROUGH */ default: S = S_NORMAL; break; } } -- For comp.sources.unix stuff, mail to sources@uunet.uu.net.