[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
yyprint does not work with glr-parser
From: |
Csaba Raduly |
Subject: |
yyprint does not work with glr-parser |
Date: |
Fri, 5 Feb 2010 17:01:41 +0100 |
The C code generated from the following grammar will not compile,
because yytoknum is not defined when glr-parser is in use.
%{
// C header part
#include <stdio.h>
static int yylex();
#define YYERROR_VERBOSE
void yyerror(const char *s)
{
puts(s);
}
union YYSTYPE;
static void yyprint(FILE *file, int type, const YYSTYPE& value);
#define YYPRINT(f,t,v) yyprint(f,t,v)
//static int yytoknum[500] = {0};
// Hack to get it compile
%}
%verbose
%glr-parser
%start GrammarRoot
%token foo
%token bar
%token baz
%union {
int i;
char *s;
}
%%
GrammarRoot:
foo
| bar
| baz
;
%%
int yylex()
{
static int index = 0, tokens[] = { bar, -1 };
return tokens[index++];
}
void yyprint(FILE *file, int type, const YYSTYPE& value)
{
(void)value;
fprintf(file, "printing type %3d", type);
switch (type) {
case foo:
fputs(" foo", file);
break;
case bar:
fputs(" bar", file);
break;
default:
break;
}
}
int main()
{
yydebug = 1;
return yyparse();
}
Discovered, with bison 2.3; verified present with bison 2.4.1
Csaba
--
Life is complex, with real and imaginary parts
- yyprint does not work with glr-parser,
Csaba Raduly <=