简体   繁体   English

在Python中解析无上下文语法

[英]Parsing a context-free grammar in Python

What tools are available in Python to assist in parsing a context-free grammar? Python中有哪些工具可以帮助解析无上下文语法?

Of course it is possible to roll my own, but I am looking for a generic tool that can generate a parser for a given CFG. 当然可以自己滚动,但我正在寻找一个可以为给定的CFG生成解析器的通用工具。

I warmly recommend PLY - it's a Lex/Yacc clone in Python that uses the language's introspection facilities in a sophisticated manner to allow for a very natural specification of the grammar. 我热烈推荐PLY - 它是Python中的Lex / Yacc克隆,它以复杂的方式使用语言的内省工具,以允许非常自然的语法规范。 Yacc, if you recall, is the very embodiment of CFGs in an understandable DSL that defines how one parses them. 如果你还记得,Yacc是可理解的DSL中CFG的一个体现,它定义了如何解析它们。

I used it to implement my parser for ANSI C and the interaction with PLY was almost effortless. 我用它来实现ANSI C的解析器,与PLY的交互几乎毫不费力。

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

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