Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Nov 1996 12:59:00 +0100 (MEZ)
From:      "Hr.Ladavac" <lada@ws2301.gud.siemens.co.at>
To:        rb@gid.co.uk (Bob Bishop)
Cc:        terry@lambert.org, stesin@gu.net, chuckr@Glue.umd.edu, hackers@FreeBSD.org
Subject:   Re: Lex/Yacc question
Message-ID:  <199611281159.AA245952340@ws2301.gud.siemens.co.at>
In-Reply-To: <v01540b0caec30fb3ed73@[194.32.164.2]> from "Bob Bishop" at Nov 28, 96 09:57:45 am

next in thread | previous in thread | raw e-mail | index | archive | help
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
> 
> 
> 




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