Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Dec 2000 01:20:04 -0800 (PST)
From:      Bill Fenner <fenner@research.att.com>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/23254: yacc accepts bad grammer
Message-ID:  <200012040920.eB49K4o90201@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/23254; it has been noted by GNATS.

From: Bill Fenner <fenner@research.att.com>
To: freebsd-gnats-submit@freebsd.org, marka@nominum.com
Cc: fenner@research.att.com
Subject: Re: bin/23254: yacc accepts bad grammer
Date: Mon, 4 Dec 2000 01:14:05 -0800 (PST)

 Ugh.  Would you believe that yacc's scanner treats semicolons as
 whitespace?  I wonder if semicolons were added to the input syntax
 "late" in the game (like in the mid'80's or so :-) ).
 
 This patch makes semicolons a little more explicitly part of
 yacc's input grammar; I'm sure I've missed something since I've
 been testing on a relatively unsophisticated grammar, but it's
 a start.  It parses test/ftp.y and /usr/src/usr.sbin/mrouted/cfparse.y,
 at least, and gives a (nonsensical but at least some) error when I
 stick in bogus semicolons in various places.
 
   Bill
 
 cvs diff: Diffing .
 Index: reader.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/yacc/reader.c,v
 retrieving revision 1.6.2.1
 diff -u -r1.6.2.1 reader.c
 --- reader.c	1999/08/29 15:35:09	1.6.2.1
 +++ reader.c	2000/12/04 09:08:12
 @@ -255,7 +255,6 @@
  	case '\r':
  	case '\v':
  	case ',':
 -	case ';':
  	    ++s;
  	    break;
  
 @@ -551,7 +550,11 @@
  	goto loop;
  
      case '}':
 -	if (--depth == 0)
 +	if (--depth < 0) syntax_error(lineno, line, cptr);
 +	goto loop;
 +
 +    case ';':
 +	if (depth == 0)
  	{
  	    fprintf(text_file, " YYSTYPE;\n");
  	    FREE(u_line);
 @@ -1198,6 +1201,8 @@
  {
      register int i;
  
 +    if (!plhs[nrules]) return;
 +
      if (!last_was_action && plhs[nrules]->tag)
      {
  	for (i = nitems - 1; pitem[i]; --i) continue;
 @@ -1259,7 +1264,6 @@
      c = nextc();
      if (c == ':')
      {
 -	end_rule();
  	start_rule(bp, s_lineno);
  	++cptr;
  	return;
 @@ -1569,6 +1573,11 @@
  	else if (c == '%')
  	{
  	    if (mark_symbol()) break;
 +	}
 +	else if (c == ';')
 +	{
 +	    ++cptr;
 +	    end_rule();
  	}
  	else
  	    syntax_error(lineno, line, cptr);
 cvs diff: Diffing test
 


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?200012040920.eB49K4o90201>