Date: Fri, 3 Sep 1999 19:09:58 -0400 (EDT) From: wghicks@bellsouth.net To: FreeBSD-gnats-submit@freebsd.org Subject: bin/13562: [PATCH] experimental enhancement for byacc Message-ID: <199909032309.TAA21156@bellsouth.net>
next in thread | raw e-mail | index | archive | help
>Number: 13562
>Category: bin
>Synopsis: export YYERRCODE to y.tab.h, add parameter support to yyparse
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Fri Sep 3 16:10:01 PDT 1999
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909032309.TAA21156>
