bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: undefining YYRHSLOC in the GLR parser


From: Frank Heckenbach
Subject: Re: undefining YYRHSLOC in the GLR parser
Date: Sun, 12 Dec 2004 12:47:24 +0100
User-agent: semail 20041018

Paul Eggert wrote:

> Frank Heckenbach <address@hidden> writes:
> 
> > The version contains the problem I reported here 2004-11-19 which
> > Akim Demaille promised to revert:
> 
> Sorry, I hadn't paid attention to that issue.  I thought Akim had
> looked into it, since he made further changes to glr.c after that
> exchange.
> 
> For lack of a better idea I installed this patch.  Can you please try
> it?  Thanks.

It works for me, thanks.

I wrote a test for it (below), though I could test it only manually,
because I don't have autom4te installed, so I hope the test suite
format is ok.

However, on that occasion I noticed another problem. glr.c contains
(line ~1737):

            /* We throw away the lookahead, but the error range
               of the shifted error token must take it into account. */
            yyGLRState *yys = yystack->yytops.yystates[0];
            yys->yyloc.last_line   = yyllocp->last_line;
            yys->yyloc.last_column = yyllocp->last_column;]])[
            yydestruct ("Error: discarding",
                        *yytokenp, yylvalp]b4_location_if([, yyllocp])[);

This directly accesses fields of YYLTYPE values. If the fields are
named differently, it will fail. Worse, if e.g. you have a last_file
field in addition, it might will silently produce wrong results,
AFAICS.

I don't know the context exactly, so I can't tell if it's possibly
to copy the complete structure, or to use YYLLOC_DEFAULT in some
way. Otherwise one might need another macro there ...

--- tests/glr-regression.at.orig        Wed Jun  4 07:53:44 2003
+++ tests/glr-regression.at     Sun Dec 12 11:11:45 2004
@@ -218,3 +218,49 @@
 
 
 AT_CLEANUP
+
+## --------------------------------------- ##
+## Inability to use YYRHSLOC in a function ##
+## --------------------------------------- ##
+
+AT_SETUP([Inability to use YYRHSLOC in a function])
+
+AT_DATA_GRAMMAR([glr-regr3.y],
+[[/* Regression Test: Inability to use YYRHSLOC in a function  */
+/* Reported by Frank Heckenbach */
+
+%{
+  int yylex (void);
+  void yyerror (char const *);
+
+  typedef struct
+  {
+    int last_line, last_column;
+  } YYLTYPE;
+  #define YYLTYPE_IS_DECLARED
+
+  union yyGLRStackItem;
+
+  static void locations (YYLTYPE *, const union yyGLRStackItem *, int);
+  #define YYLLOC_DEFAULT(DEST, SRC, N) locations (&DEST, SRC, N)
+%}
+
+%glr-parser
+%locations
+
+%%
+exp: 'a';
+%%
+
+static void
+locations (YYLTYPE *dest, const union yyGLRStackItem *src, int n)
+{
+  dest->last_line = YYRHSLOC (src, n).last_line;
+  dest->last_column = YYRHSLOC (src, n).last_column;
+}
+
+]])
+
+AT_CHECK([[bison -o glr-regr3.c glr-regr3.y]], 0, [], [])
+AT_COMPILE([glr-regr3])
+AT_CLEANUP


Frank

-- 
Frank Heckenbach, address@hidden
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]