How Can I Get a Flex Scanner To Return Bison's Error Token?
Bison uses a special error token (called 'error') that one can use in a Bison par开发者_Go百科ser to recover from errors. Is there a way to return this specific token from a scanner generated by Flex?
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.
精彩评论