开发者

How Can I Get a Flex Scanner To Return Bison's Error Token?

开发者 https://www.devze.com 2022-12-20 03:10 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消