Lex/Flex - Scanning for the EOF character

僤鯓⒐⒋嵵緔 提交于 2019-12-04 02:56:16

问题


Other people have had the following problem that I am having but I can't find anyone that has reported a solution.. getting Flex to spot the EOF (end of file). I need Flex to find EOF and return a token indicating that it has found it so it can tell Yacc/Bison that it has reached the end of an input source file and can report a successful parse.

Note that this question is not the same as this one because this is about Lex/Flex.

Any help would be awesome. Thank you.


回答1:


Flex has <<EOF>> pattern which matches only end-of-file. Probably you can return some token indicating end-of-file to the parser as the following.

<<EOF>>     return END_OF_FILE;


来源:https://stackoverflow.com/questions/6614834/lex-flex-scanning-for-the-eof-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!