简体   繁体   English

野牛和词法语法编译缓慢

[英]Slow compilation of bison and lex grammar

I used bison and flex for generating a C parser using a grammar.y file. 我使用bison和flex使用grammar.y文件生成了C解析器。 It compiles properly and so fast in about 10 seconds. 它可以正确编译,并在大约10秒钟内快速完成。 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. 我已经更改了bison和flex参数以获取C ++输出,尽管它会生成正确的结果,但是编译和输出CPP语法结果大约需要1分钟。 Does anyone have any idea for solving this problem? 有谁有解决这个问题的想法? The grammar file is about 6000 lines. 语法文件约为6000行。

It is quite common to have C++ compilation run slow as molasses, depending on the complexity of the C++ code. 使C ++编译像糖蜜一样缓慢运行是很常见的,具体取决于C ++代码的复杂性。 The C++ compiler has a lot of work to do, to figure things out. C ++编译器有很多工作要做,以解决问题。 Much work more than a C compiler has to do. 比C编译器要做的工作更多。 I have some C++ code that takes several minutes, and close to a gig of RAM, to chew through. 我有一些C ++代码需要几分钟的时间,并且要花费将近一个GB的RAM。

With a robo-generated LALR(1) parser that bison spews out from a 6000-line ruleset, that's not entirely an unexpected result. 使用机器人自动生成的LALR(1)解析器,野牛从6000行规则集中喷涌而出,这并不是完全出乎意料的结果。 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. 如果解析器的运行时性能不是至关重要的,则可以通过删除针对robo生成的语法文件的-O优化选项来加快处理速度。 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. 在最近的版本中,gcc的性能已显着提高,因此,如果您使用的是较旧的gcc,则可能会看到改进。

Welcome to C++. 欢迎使用C ++。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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