From d0d5aa6425c8e7f5453a7173b74f95351f7db266 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 2 Feb 2004 22:35:53 +0000 Subject: [PATCH] (yytokenName): Bullet-proof against YYEMPTY token. (yyreportSyntaxError): Handle case where lookahead token is YYEMPTY. --- data/glr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/data/glr.c b/data/glr.c index eb270a17..586da61e 100644 --- a/data/glr.c +++ b/data/glr.c @@ -1,7 +1,7 @@ m4_divert(-1) -*- C -*- # GLR skeleton for Bison -# Copyright (C) 2002, 2003 Free Software Foundation, Inc. +# Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -636,6 +636,9 @@ yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...) static inline const char* yytokenName (yySymbol yytoken) { + if (yytoken == YYEMPTY) + return ""; + return yytname[yytoken]; } #endif @@ -1653,7 +1656,8 @@ yyreportSyntaxError (yyGLRStack* yystack, if (yymsg != 0) { char* yyp = yymsg; - sprintf (yyp, "syntax error, unexpected %s", + sprintf (yyp, "syntax error%s%s", + (*yytokenp == YYEMPTY ? "" : ", unexpected "), yytokenName (*yytokenp)); yyp += strlen (yyp); if (yycount < 5) -- 2.45.2