Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

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

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? :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...