How to list lex/yacc or flex/bison patterns?

久未见 提交于 2019-12-13 23:56:41

问题


I would like to extract all patterns from a flex/bison file to look at them altogether. I am not interested in the rules applying to the patterns for now.

Surely someone has written a flex/bison file for this already? :)


回答1:


If you give it the -v command-line option, bison will output a nicely formatted version of the grammar (and all the states) to a file with extension .output. You can specify the precise file name to write to with --report-file=PATH and a list of things to report on with --report=THINGS; see bison --help for details. But afaik, the grammar is always printed, near the beginning of the report file, just after the list of conflicts, if any.

flex does not have an equivalent option, but if you specify the -T flag (intended for debugging flex itself), then flex will dump to stderr a list of the patterns, as well as other information of possibly less use. (The output is a little hard to read if you use start condition blocks, and it has macros expanded, which might or might not be what you're looking for.)



来源:https://stackoverflow.com/questions/33416547/how-to-list-lex-yacc-or-flex-bison-patterns

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