在Python中解析无上下文语法

时间:2022-04-14 22:33:02

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生成解析器的通用工具。

1 个解决方案

#1


7  

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. Yacc, if you recall, is the very embodiment of CFGs in an understandable DSL that defines how one parses them.

我热烈推荐PLY - 它是Python中的Lex / Yacc克隆,它以复杂的方式使用语言的内省工具,以允许非常自然的语法规范。如果你还记得,Yacc是可理解的DSL中CFG的一个体现,它定义了如何解析它们。

I used it to implement my parser for ANSI C and the interaction with PLY was almost effortless.

我用它来实现ANSI C的解析器,与PLY的交互几乎毫不费力。

#1


7  

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. Yacc, if you recall, is the very embodiment of CFGs in an understandable DSL that defines how one parses them.

我热烈推荐PLY - 它是Python中的Lex / Yacc克隆,它以复杂的方式使用语言的内省工具,以允许非常自然的语法规范。如果你还记得,Yacc是可理解的DSL中CFG的一个体现,它定义了如何解析它们。

I used it to implement my parser for ANSI C and the interaction with PLY was almost effortless.

我用它来实现ANSI C的解析器,与PLY的交互几乎毫不费力。