From owner-freebsd-hackers Sun Dec 1 23:57:38 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id XAA08940 for hackers-outgoing; Sun, 1 Dec 1996 23:57:38 -0800 (PST) Received: from hemi.com (hemi.com [204.132.158.10]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id XAA08935 for ; Sun, 1 Dec 1996 23:57:35 -0800 (PST) Received: (from mbarkah@localhost) by hemi.com (8.8.3/8.7.3) id AAA17064; Mon, 2 Dec 1996 00:56:12 -0700 (MST) From: Ade Barkah Message-Id: <199612020756.AAA17064@hemi.com> Subject: Re: Lex/Yacc question To: terry@lambert.org (Terry Lambert) Date: Mon, 2 Dec 1996 00:56:12 -0700 (MST) Cc: hackers@freebsd.org In-Reply-To: <199611292054.NAA03886@phaeton.artisoft.com> from "Terry Lambert" at Nov 29, 96 01:54:57 pm X-Mailer: ELM [version 2.4 PL24] Content-Type: text Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Terry Lambert wrote: > [\r\n] { > BEGIN INITIAL; > return HELO_END; > } > > The use of a "HELO_END" token lets us recognize the end of the statement > for a partial statement (HELO STR_DOMAIN HELO_END is otherwise ambiguous). You can also avoid states if you want to... for example, in your rfc821.l: | %{ | #include "y.tab.h" | %} | | %% | | helo { return HELO; } | | \n { return CR; } | | . { return CHAR; } Then in rfc821.y you can do: | %token HELO CR CHAR | | %start command | | %% | | command: /* nothing*/ | | command incomplete_helo | | command helo_command | { yyerrok; } | ; | | incomplete_helo : HELO CR | { printf ("Helo requires DOMAIN.\n"); } | | helo_command : HELO string CR | { printf ("Got HELO\n"); /* Do something */ } | | string : CHAR | | string CHAR (Yea, that CR should probably a CR LF.) I have a hand-crafted rfc821 daemon I use for a custom email-to-paging gateway which I'll probably rewrite using the above approach. The above code is from a quicky version I wrote which understands MAIL, RCPT, RSET, QUIT, and DATA. (Trivial to add.) Regards, -Ade Barkah ------------------------------------------------------------------- Inet: mbarkah@hemi.com - HEMISPHERE ONLINE - -------------------------------------------------------------------