diff options
author | David E. O'Brien <obrien@FreeBSD.org> | 1999-10-27 17:51:37 +0000 |
---|---|---|
committer | David E. O'Brien <obrien@FreeBSD.org> | 1999-10-27 17:51:37 +0000 |
commit | c3584b3b4eefd14cfcc5a82a641a016031ff88be (patch) | |
tree | e45e4006625eb522b52507d20820cbe1a130a9dc | |
parent | 6877f580defcd4ab57997719d49896285f6c9310 (diff) | |
download | src-c3584b3b4eefd14cfcc5a82a641a016031ff88be.tar.gz src-c3584b3b4eefd14cfcc5a82a641a016031ff88be.zip |
Allow 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.
For a desired prototype of:
int yyparse __P((struct yyresult *));
and compile like this:
yacc -dv grammar.y
cc -c -DYYPARSE_PARAM_TYPE="struct yyresult *" \
-DYYPARSE_PARAM="parm" y.tab.c
and 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.
PR: 13562
Submitted by: W Gerald Hicks <wghicks@bellsouth.net>
Notes
Notes:
svn path=/head/; revision=52569
-rw-r--r-- | usr.bin/yacc/skeleton.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/usr.bin/yacc/skeleton.c b/usr.bin/yacc/skeleton.c index f3d6dd0d3630..90235cb0e937 100644 --- a/usr.bin/yacc/skeleton.c +++ b/usr.bin/yacc/skeleton.c @@ -67,10 +67,6 @@ char *banner[] = "#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 @@ char *body[] = "#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", |