On subsequent executions, lextab.py will simply be imported to build the lexer. This approach substantially improves the startup time of the lexer and it works in Python's optimized mode.
When running in optimized mode, it is important to note that lex disables most error checking. Thus, this is really only recommended if you're sure everything is working correctly and you're ready to start releasing production code.
Since the generation of the LALR tables is relatively expensive, previously generated tables are cached and reused if possible. The decision to regenerate the tables is determined by taking an MD5 checksum of all grammar rules and precedence rules. Only in the event of a mismatch are the tables regenerated.
您想使用optimized mode,方法是调用lex:
一。在
值得强调的是(from the same link):
因为这是生产代码,这听起来正是您想要的。
一。在
在研究这个问题时,我遇到了miscellaneous Yacc notes:
深入研究
^{pr2}$yacc.py
中的yacc
函数,我们发现Optimize在下面的片段中忽略了这种不匹配:其中
signature
与存储在parsetab.py
(作为_lr_signature
)中的校验和进行比较。我最终做的是关闭优化。我在浏览PLI3.4源代码时,在lexer代码中发现了一个小亮点:
通过将构建lexer和解析器的代码更改为:
self.lexer = lex.lex(module=self, optimize=False, debug=False, **kwargs)
以及
self.lexer = lex.lex(module=self, optimize=False, debug=False, **kwargs)
我避免了所有的文件写出来。调试器将
.out
文件写入目录,Python文件是optimize
标志的结果。在虽然这暂时有效,但我不能说我对这种方法完全满意。想必,有某种方法来保持优化,同时保持工作目录的干净,将是一个更好的解决方案,将导致更好的性能。如果别人有更好的方法,我会非常乐意接受。在
使用
相关问题 更多 >
编程相关推荐