From wghicks@bellsouth.net Fri Sep  3 16:06:10 1999
Return-Path: <wghicks@bellsouth.net>
Received: from mail1.atl.bellsouth.net (mail1.atl.bellsouth.net [205.152.0.28])
	by hub.freebsd.org (Postfix) with ESMTP id E9ED614BE4
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  3 Sep 1999 16:06:08 -0700 (PDT)
	(envelope-from wghicks@bellsouth.net)
Received: from wghicks.bellsouth.net (host-216-78-37-111.ath.bellsouth.net [216.78.37.111])
	by mail1.atl.bellsouth.net (3.3.2/8.9.3) with ESMTP id TAA16380
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 3 Sep 1999 19:02:06 -0400 (EDT)
Received: (from wghicks@localhost)
	by wghicks.bellsouth.net (8.9.3/8.9.2) id TAA21156;
	Fri, 3 Sep 1999 19:09:58 -0400 (EDT)
	(envelope-from wghicks)
Message-Id: <199909032309.TAA21156@bellsouth.net>
Date: Fri, 3 Sep 1999 19:09:58 -0400 (EDT)
From: wghicks@bellsouth.net
Reply-To: wghicks@bellsouth.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] experimental enhancement for byacc
X-Send-Pr-Version: 3.2

>Number:         13562
>Category:       bin
>Synopsis:       export YYERRCODE to y.tab.h, add parameter support to yyparse
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    obrien
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep  3 16:10:01 PDT 1999
>Closed-Date:    Fri Nov 10 10:28:37 PST 2000
>Last-Modified:  Fri Nov 10 10:29:03 PST 2000
>Originator:     W Gerald Hicks
>Release:        FreeBSD 4.0-CURRENT i386
>Organization:
Fair Play, Uninc.
>Environment:

	FreeBSD 4.0-CURRENT i386

>Description:

We have found that it is sometimes useful for lex to have YYERRCODE
defined for reporting scanning errors back to yacc.  The first section
of the patch emits the defined value into y.tab.h 

The second section of the patch allows for a user specified parameter
to 'yyparse()', in a manner similar to that used by bison.  The names
are consistent with the bison implementation but this one also allows
the type of the parameter to be specified.

We generate an old-style function header for 'yyparse()' in the y.tab.c
outfile.   Generally, we supplement this with a hand-coded prototype
in a shared header file.

for a desired prototype of:

    int yyparse __P((struct yyresult *));


 ... compile like this:

    yacc -dv grammar.y
    cc -c -DYYPARSE_PARAM_TYPE="struct yyresult *" -DYYPARSE_PARAM="parm" \
       y.tab.c

 ... use like this:

${
#include "usrtypes.h"
#include "usrproto.h"
}$

%token NUMBER

%%

goal : NUMBER
       {
               parm->value = yylval; 
       }
;

If YYPARSE_PARAM_TYPE isn't specified then "void *" is the default type

If YYPARSE_PARAM is not specified then the generated code behaves exactly
as traditional byacc.

>How-To-Repeat:

Apply the patch :-)

>Fix:

--- src/usr.bin/yacc/output.c.orig	Sat Aug 28 01:08:01 1999
+++ src/usr.bin/yacc/output.c	Fri Sep  3 21:18:21 1999
@@ -863,6 +863,15 @@
     register int c, i;
     register char *s;
 
+    ++outline;
+    fprintf(code_file, "#define YYERRCODE %d\n", symbol_value[1]);
+
+    if(dflag)
+    {
+        fprintf(defines_file, "#ifndef YYERRCODE\n");
+        fprintf(defines_file, "#define YYERRCODE %d\n", symbol_value[1]);
+        fprintf(defines_file, "#endif\n\n");
+    }
     for (i = 2; i < ntokens; ++i)
     {
 	s = symbol_name[i];
@@ -893,9 +902,6 @@
 	    if (dflag) fprintf(defines_file, " %d\n", symbol_value[i]);
 	}
     }
-
-    ++outline;
-    fprintf(code_file, "#define YYERRCODE %d\n", symbol_value[1]);
 
     if (dflag && unionized)
     {
--- src/usr.bin/yacc/skeleton.c.orig	Sat Aug 28 01:08:03 1999
+++ src/usr.bin/yacc/skeleton.c	Fri Sep  3 22:42:40 1999
@@ -67,10 +67,6 @@
     "#define yyclearin (yychar=(YYEMPTY))",
     "#define yyerrok (yyerrflag=0)",
     "#define YYRECOVERING() (yyerrflag!=0)",
-#if 0
-    "extern int yylex();",
-    "extern int yyparse();",
-#endif
     "static int yygrowstack();",
     0
 };
@@ -163,12 +159,19 @@
     "#define YYACCEPT goto yyaccept",
     "#define YYERROR goto yyerrlab",
     "",
-    "int",
-    "#if defined(__cplusplus) || __STDC__",
-    "yyparse(void)",
+    "#ifndef YYPARSE_PARAM",
+    "#define YYPARSE_PARAM",
+    "#define YYPARSE_PARAM_DECL",
     "#else",
-    "yyparse()",
+    "#ifndef YYPARSE_PARAM_TYPE",
+    "#define YYPARSE_PARAM_TYPE void *",
+    "#endif",
+    "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;",
     "#endif",
+    "",
+    "int",
+    "yyparse (YYPARSE_PARAM)",
+    "    YYPARSE_PARAM_DECL",
     "{",
     "    register int yym, yyn, yystate;",
     "#if YYDEBUG",


>Release-Note:
>Audit-Trail:

From: Jeroen Ruigrok/Asmodai <asmodai@wxs.nl>
To: wghicks@bellsouth.net
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/13562: [PATCH] experimental enhancement for byacc
Date: Sat, 4 Sep 1999 10:36:50 +0200

 FWIW:
 
 patch applied cleanly to yesterday's CURRENT. Made cleanly, installed
 cleanly. Then after installation made world from scratch with the new
 yacc installed. Compiled and installed with no problems.
 
 I am in favour of the patches.
 
 JFYI, HTH.
 
 -- 
 Jeroen Ruigrok van der Werven                          asmodai(at)wxs.nl
 The BSD Programmer's Documentation Project <http://home.wxs.nl/~asmodai>
 Network/Security Specialist        BSD: Technical excellence at its best
 Might makes right.
 
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Thu Oct 7 00:04:21 PDT 1999 
Responsible-Changed-Why:  
I did the last Yacc commit. 

From: "David O'Brien" <obrien@NUXI.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc: wghicks@bellsouth.net
Subject: Re: bin/13562: export YYERRCODE to y.tab.h, add parameter support to yyparse
Date: Sat, 15 Jan 2000 19:10:33 -0800

 Weren't there suppose to be more patches following this PR?
 
 -- 
 -- David    (obrien@NUXI.com)
 
State-Changed-From-To: open->closed 
State-Changed-By: obrien 
State-Changed-When: Fri Nov 10 10:28:37 PST 2000 
State-Changed-Why:  
There were supose to be followup patches to this PR that never were 
received. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=13562 
>Unformatted:
