Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Dec 1996 00:56:12 -0700 (MST)
From:      Ade Barkah <mbarkah@hemi.com>
To:        terry@lambert.org (Terry Lambert)
Cc:        hackers@freebsd.org
Subject:   Re: Lex/Yacc question
Message-ID:  <199612020756.AAA17064@hemi.com>
In-Reply-To: <199611292054.NAA03886@phaeton.artisoft.com> from "Terry Lambert" at Nov 29, 96 01:54:57 pm

next in thread | previous in thread | raw e-mail | index | archive | help
Terry Lambert wrote:

> <ST_HELO>[\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 - <http://www.hemi.com/>;
-------------------------------------------------------------------



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612020756.AAA17064>