help-bison
[Top][All Lists]
Advanced

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

Re: better error reporting with bison and flex


From: Guillaume Rousse
Subject: Re: better error reporting with bison and flex
Date: Thu, 22 Jun 2006 17:01:20 +0200
User-agent: Thunderbird 1.5.0.4 (X11/20060618)

Satya wrote:
> hi,
> As I understand, you want to refer to the user's exact input symbol in
> the error message rather than the grammar symbol associated with it..
> ?
Rather the whole input line than just an isolated part of it.

> Well, flex provides a global variable 'yytext' that contains the value
> of the symbol. Suppose you have a definition like this in your lexer:
> 
> [0-9]+   {  return TOK_NUM; }
> 
> then, what bison knows about is ONLY the symbol TOK_NUM and nothing
> else (i.e if the number is 5 or 100 or whatever);
> 
> so you have to catch yytext and store it in yylval like this:
> 
> [0-9]+   {  yylval = atoi(yytext); return TOK_NUM; } //assuming your
> YYSTYPE is int -- otherwise use the appropriate field of the union.
Unfortunatly, the appropriate field is context dependant: in an action
rule, it is known, but not in yyerror(). I can use yytext, indeed, but
this only give me found symbol, not expected ones:

syntax error, unexpected TYPE_FLOAT_BINARY, expecting TYPE_INT or
TYPE_STRING or TYPE_FLOAT <- bison message
found token: %fb <- yytext

-- 
Guillaume Rousse
Projet Estime, INRIA
Domaine de Voluceau
Rocquencourt - B.P. 105
78153 Le Chesnay Cedex - France




reply via email to

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