From owner-freebsd-hackers Thu Nov 28 04:37:53 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id EAA24022 for hackers-outgoing; Thu, 28 Nov 1996 04:37:53 -0800 (PST) Received: from zwei.siemens.at (zwei.siemens.at [193.81.246.12]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id EAA24013 for ; Thu, 28 Nov 1996 04:37:50 -0800 (PST) Received: from scegud01 (root@[10.1.143.100]) by zwei.siemens.at (8.7.5/8.7.3) with ESMTP id NAA20006; Thu, 28 Nov 1996 13:30:42 +0100 (MET) Received: from ws2301.gud.siemens.co.at by scegud01 with ESMTP (1.39.111.2/16.2) id AA063474243; Thu, 28 Nov 1996 13:30:43 +0100 Received: by ws2301.gud.siemens.co.at (1.37.109.16/1.37) id AA245952340; Thu, 28 Nov 1996 12:59:00 +0100 From: "Hr.Ladavac" Message-Id: <199611281159.AA245952340@ws2301.gud.siemens.co.at> Subject: Re: Lex/Yacc question To: rb@gid.co.uk (Bob Bishop) Date: Thu, 28 Nov 1996 12:59:00 +0100 (MEZ) Cc: terry@lambert.org, stesin@gu.net, chuckr@Glue.umd.edu, hackers@FreeBSD.org In-Reply-To: from "Bob Bishop" at Nov 28, 96 09:57:45 am X-Mailer: ELM [version 2.4 PL24 ME8a] Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk E-mail message from Bob Bishop contained: > At 10:14 am 28/11/96, Andrew Stesin wrote: > >> > echo This is an undelimited yytext[] to my eol to pass to echo() > > > >lex: > > > >[^\n]+\n return UNDELIMITED_YYTEXT; > > > >yacc: > > > >UNDELIMITED_YYTEXT > > { > > echo($1); > > } > > > >or something like the above (I used lex+yacc years ago). > > I think that's right (except that yytext (ie $1) will include the trailing > newline which you may want to strip). The main pitfall to watch out for is > that `.' in a lex RE will never match newline. How about: lex: '\n' /* ignore? */ ^.*$ { yyval = strdup( yyytext ); return UNDELIMITED_YYTEXT; } yacc: UNDELIMITED_YYTEXT: { echo( $1 ); } This strips newlines and returns everything on the line (and the empty string for an empty line). /Marino > > IMHO, the original papers are still the best general texts on lex and yacc; > they can be found in the 4.4-Lite distribution under /usr/share/doc/psd. > > Come to think of it, why doesn't /usr/share/doc figure in FreeBSD distributions? > > > -- > Bob Bishop (0118) 977 4017 international code +44 118 > rb@gid.co.uk fax (0118) 989 4254 between 0800 and 1800 UK > > >