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

Re: Bug#189332: flex: unput(char) not valid outside body of grammar

>> On Fri, 18 Apr 2003 00:50:08 -0700 (PDT),
>> Paul Eggert <eggert@CS.UCLA.EDU> said: 

 > This email is following up to a Debian bug report about flex
 >> http://bugs.debian.org/189332>, which reports that flex test
 >> http://bugs.debian.org/189332>version
 > 2.5.31 breaks Bison 1.875.

 >> From: Manoj Srivastava <srivasta@debian.org> Date: Date: Wed, 16
 >> Apr 2003 17:40:13 -0500

 > This change means that flex no longer conforms to POSIX
 > 1003.1-2001.  The POSIX specification for lex
 >> http://www.opengroup.org/onlinepubs/007904975/utilities/lex.html>
 > says that the functions yylex, yymore, yyless, input, and unput are
 > all accessible to user code included in the lex input.  As far as I
 > can tell, POSIX imposes no restriction that the functions are
 > accessible only to user actions.

 > The change to flex may be necessary for reentrant scanners, but it
 > shouldn't be necessary for traditional scanners such as those
 > specified by POSIX.

	Indeed. The full POSIX references are:
 ISO/IEX 9945-2: 1993(3)   Information Technology -- POSIX
 IEEE Std 1003.2-1992      Part 2: Shell and Utilities
  A.2.7.5 lex Actions

	It also says that it is unspecified whether the functions or
 macros appear in the C code output of lex, or are accessible only
 through the -l l operand og the c compiler. 

	I have, however, noticed something bizarre: adding a %nounput
 options defines unput, but never undefines it, this seems like a bug
/* A template scanner file to build "scanner.c". */
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
/*#include "parser.h" */

static void f(const char *x);


%option 8bit outfile="scanner.c" prefix="test"
%option nomain noyywrap nounput
%option warn

 void f(const char *x) { unput(*x); }

[0-9]              { unput('?'); }
[a-z]              { f("?"); }

int main(void);

main ()
    yyin = stdin;
    yyout = stdout;
    printf("TEST RETURNING OK.\n");
    return 0;

>> Please consider the following modification to the flex file
 >> you submitted in th patch

 > I tried doing something like that for Bison (along the lines suggested
 > by Peter Muir in
 > <http://mail.gnu.org/archive/html/bison-patches/2003-04/msg00002.html>),
 > but this had other problems: it called yyunput before it was declared,
 > and this violates C99.

	Umm, the modification I provided was tested, and it did not
 call yyunput before it was declared (the trick is to place the
 functions in the _rules_ section in %{ %} stanzas. 

God gave you that gifted tongue of yours, and set it between your
teeth, to make known your true meaning to us, not be rattled like a
muffin man's bell. Carlyle

Manoj Srivastava   <srivasta@debian.org>  <http://www.debian.org/%7Esrivasta/>
1024R/C7261095 print CB D9 F4 12 68 07 E4 05  CC 2D 27 12 1D F5 E8 6E
1024D/BF24424C print 4966 F272 D093 B493 410B  924B 21BA DABB BF24 424C

Reply to: