Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!munnari!mulga!ausmelb!ejp
From: ejp@ausmelb.OZ (Esmond Pitt)
Newsgroups: comp.unix.wizards
Subject: Re: argv --> stdin IN LEX
Message-ID: <81@ausmelb.OZ>
Date: Thu, 11-Dec-86 18:24:39 EST
Article-I.D.: ausmelb.81
Posted: Thu Dec 11 18:24:39 1986
Date-Received: Sun, 14-Dec-86 19:28:39 EST
References: <1367@brl-adm.ARPA> <3060@rsch.WISC.EDU>
Reply-To: ejp@ausmelb.UUCP (Esmond Pitt)
Organization: Austec International Limited, Melbourne
Lines: 44
Summary: RTFM is right, and RYFC too
cc: ejp




In article <3060@rsch.WISC.EDU> mcvoy@rsch.WISC.EDU (Lawrence W. McVoy) writes:
>In article <1367@brl-adm.ARPA> rbbb@rice.EDU (David Chase) writes:
>>RTFM! RTFM! RTFM!  I QUOTE:
>
>  After RTFM! RTFM! RTFM!-ing again and wading through lex 
>output (gag):  Yup.  Works neat.  With lex.  Doesn't work at all 
>with yacc.  If y'all go back and read the original posting, you 
>will notice that I kinda asked for a solution that works with 
>lex and yacc.  
>  
>  The relevant parts of the code are included below.  My guess 
>is that yacc makes some assumptions about buffers, though 
>I can't see where.

Bad guess. Your code kinda has at least two bugs:

1. Your yyerror() function is wrong, so you didn't see the parser
trying to print 'syntax error'. (Why not use yyerror() from -ly?)

2. The syntax error occurs because the grammar expects a newline,
but you didn't append one to the argument buffer.

>main(argc, argv)
...
>    for (i=1; i	for (s=argv[i]; *s; *ptr++ = *s++)
>	    ;
>    
!    *ptr++ = '\n';	/* Terminate argument list with newline	*/
>    ptr = buf;
...
>yyerror(s)
>    char* s;
>{
/*    fprintf(stderr, "%s\n");	*/	/* WRONG	*/
!     fprintf(stderr, "%s\n",s);	/* RIGHT	*/
>}

Fix & it works fine.
-- 
Esmond Pitt,				ACSnet: ejp@ausmelb.oz
Austec International Ltd,		UUCP: ...!seismo!munnari!ausmelb.oz!ejp
344 St Kilda Rd,			ARPA: ejp%ausmelb.oz@SEISMO.CSS.GOV
Melbourne, 3004, AUSTRALIA.		Phone: +61 3 699 4511; Telex: AA38559
D