简体   繁体   中英

Slow compilation of bison and lex grammar

I used bison and flex for generating a C parser using a grammar.y file. It compiles properly and so fast in about 10 seconds. I have changed my bison and flex arguments in order to get C++ output, although it generate correct results but it take about 1 minute to compile and output CPP result of grammar. Does anyone have any idea for solving this problem? The grammar file is about 6000 lines.

It is quite common to have C++ compilation run slow as molasses, depending on the complexity of the C++ code. The C++ compiler has a lot of work to do, to figure things out. Much work more than a C compiler has to do. I have some C++ code that takes several minutes, and close to a gig of RAM, to chew through.

With a robo-generated LALR(1) parser that bison spews out from a 6000-line ruleset, that's not entirely an unexpected result. You could probably speed things up by dropping the -O optimization options, for the robo-generated grammar file, if the runtime performance from the parser is not critical. That will probably speed things up a bit.

You could also try updating your compiler. gcc has improved its performance noticeably, in recent releases, so if you're using an older gcc, you might see an improvement.

Welcome to C++.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM