tags:

views:

176

answers:

1

Bison uses a special error token (called 'error') that one can use in a Bison parser to recover from errors. Is there a way to return this specific token from a scanner generated by Flex?

+1  A: 

The 'error' token is not really a token. It's used for error handling only.

On http://dinosaur.compilertools.net/yacc/index.html you can read: The token name error is reserved for error handling, and should not be used naively.

In my own parser I use the error token like this (to parse a C-like macro-language:

StatementList  :
               |  StatementList Statement ';'
               |  error ';'

If the user makes an error, yacc/bison will go on until the next semi-colon (end of a statement) and then go on with the next statement.

Patrick
Thanks. I realized what I really wanted was REJECT.
Jack