help-bison
[Top][All Lists]
Advanced

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

Re: error handling


From: Hans Aberg
Subject: Re: error handling
Date: Wed, 23 May 2001 19:47:48 +0200

At 15:11 +0200 2001/05/23, alexandre.gouraud wrote:
>I did a parser with bison and flex (bison 1.28 and flex-2.5).
>I am parsing strings in memory instead of strings from the
>standart input. Each time I encounter an error in the string,
>I would like the parser to finish reading the entire string
>(up to the end of the string), so that the flex routine can
>close its buffer properly.
>My grammar looks like :
>
>%%
>
>hostname_group : hostname
>   | hostname hostname_group
>   | error
>      {
>         yyerrok;
>         yyclearin;
>      }
>;
>
>hostname : case1
>      {
>          /* do some stuff */
>      }
>   | case2
>      {
>           yyerror("this case is not supported yet\n");
>           YYABORT;
>      }

Here, YYABORT always causes program termination; try YYERROR instead.

However, if the only thing you want is to clear the buffer, then it is more
prudent to use a better source to read from:

In C++, one can read a stream from memory by using the class
std::stringstream (or std::istringstream if you only need to read from it).

  Hans Aberg





reply via email to

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