From owner-freebsd-hackers Fri Dec 6 11:21:51 1996 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id LAA06959 for hackers-outgoing; Fri, 6 Dec 1996 11:21:51 -0800 (PST) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id LAA06954 for ; Fri, 6 Dec 1996 11:21:49 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id MAA24232; Fri, 6 Dec 1996 12:01:44 -0700 From: Terry Lambert Message-Id: <199612061901.MAA24232@phaeton.artisoft.com> Subject: Re: Yacc -p is broken To: rb@gid.co.uk (Bob Bishop) Date: Fri, 6 Dec 1996 12:01:44 -0700 (MST) Cc: terry@lambert.org, hackers@freebsd.org In-Reply-To: from "Bob Bishop" at Dec 6, 96 10:21:34 am X-Mailer: ELM [version 2.4 PL24] 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 > At 7:13 pm 5/12/96, Terry Lambert wrote: > >[...] > >Frequently, if you are mixing grammars, you have a -P on the lex > >to go with the -p on the yacc... > > I agree it's broken. I suspect it's always been broken, but there are other > ways to skin that particular cat. Several times I've seen people stuffing > lex/yacc output thru sed to fix the prefixes; I don't like that much. > > What I usually do is use a 'super-grammar' whose top-level rule just > switches between the real gramars based on a token which I arrange to stuff > up the pipe when the parser starts. Lex/yacc output seems to restartable: > this works OK. Actually, I screwed up. According to: lex & yacc John R. Levine, Tony Mason, & Doug Brown O'Reilly & Associates, Inc. ISBN 1-56592-000-7 The "-p" flag ("-P" for flex -- stupid flex) is supposed to affect: yyback yybgin yycrank yyerror yyestate yyextra yyfnd yyin yyinput yyleng yylex yylineno yylook yylsp yylstate yylval yymatch yymorfg yyolsp yyout yyoutput yyprevious yysbuf yysptr yysvec yytchar yytext yytop yyunput yyvstop yywrap For the record, it doesn't. 8-(. Also for the record, I believe yytext_ptr should be affected as well, or it should at least be static. I was sent some yacc patches from one of the other BSD's; apparently yacc fails on two variables as well. I still think that, even though the behaviour is documented, the yylval is an external reference from the yacc; I may choose to not use the same prefix for my yacc "-p" and my lex "-p"; if so, I think they should still be capable of interoperating using the inclusion of y.tab.h and an explicit {yy}lex() call replacement stub. In any case, with all the non-static globals, it's inlikely that you could safely use multiple lexers in the same program without seriously fixing lex. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.