argv --> stdin IN LEX

Esmond Pitt ejp at ausmelb.OZ
Fri Dec 12 09:24:39 AEST 1986




In article <3060 at rsch.WISC.EDU> mcvoy at rsch.WISC.EDU (Lawrence W. McVoy) writes:
>In article <1367 at brl-adm.ARPA> rbbb at 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<argc; 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 at ausmelb.oz
Austec International Ltd,		UUCP: ...!seismo!munnari!ausmelb.oz!ejp
344 St Kilda Rd,			ARPA: ejp%ausmelb.oz at SEISMO.CSS.GOV
Melbourne, 3004, AUSTRALIA.		Phone: +61 3 699 4511; Telex: AA38559
D



More information about the Comp.unix.wizards mailing list