help-bison
[Top][All Lists]
Advanced

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

Re: bison 1.35: end of file?


From: Akim Demaille
Subject: Re: bison 1.35: end of file?
Date: 24 May 2002 11:27:46 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

| Hi, all.
| When I remeber right, a bison parser called yyerror() if yylex()
| returns 0 inside a rule. I mean the unexpected case:
| 
| rule    : T1 T2 T3 T4
|         ;
| 
| yylex() returns T1, T2 and then 0 by some unexpected reason, a comment
| has not been closed and reaches until the end of file or something
| like that.
| 
| A bison 1.35 parser does not call yyerror() in this case. Is this
| right? It seems as if the entire grammar is terminated successfully.
| 
| Does anybody know how to detect an unexpected end of file?

I can't reproduce your problem.

/tmp % cat error-1.y                                             nostromo Err 1
%{
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#define YYERROR_VERBOSE 1
#define YYDEBUG 1

static int yylex (void);
static void yyerror (const char *msg);
%}
%%
prog: 'x' 'y' 'z' 't'
    ;
%%
static int
yylex (void)
{
  static const int input[] =
    {
      'x', 'y'
    };
  static int counter = 0;

  if (counter < (sizeof(input) / sizeof (input[0])))
    return input[counter++];
  else
    return EOF;
}

static void
yyerror (const char *msg)
{
  fprintf (stderr, "%s\n", msg);
}

int
main (void)
{
  yydebug = !!getenv ("YYDEBUG");
  return yyparse ();
}
/tmp % ~/src/bison-1.29/tests/bison --version                    nostromo 11:26
bison (GNU Bison) 1.35

Copyright 1984, 1986, 1989, 1992, 2000, 2001, 2002
Free Software Foundation, Inc.
Ce logiciel est libre; voir les sources pour les conditions de
reproduction. AUCUNE garantie n'est donnée; tant pour des raisons
COMMERCIALES que pour RÉPONDRE À UN BESOIN PARTICULIER.
/tmp % ~/src/bison-1.29/tests/bison error-1.y                    nostromo 11:26
/tmp % gcc -Wall error-1.tab.c                                   nostromo 11:26
/tmp % ./a.out                                                   nostromo 11:26
parse error, unexpected $, expecting 'z'
/tmp %                                                           nostromo Err 1 



reply via email to

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