Python解析器模块教程 [英] Python parser Module tutorial

查看:122
本文介绍了Python解析器模块教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,该应用程序读取当前具有自己的语法的输入文件,该文件由lex/yacc处理.

I am writing an application which reads an input file that currently has its own grammar, which is processed by lex/yacc.

我正在尝试对此进行修改,以使该输入文件成为Python脚本,并且想知道是否有人可以向我介绍在Python中使用解析器模块的入门指南.我对Python本身还很陌生,但是已经完成了在线教程的相当一部分.

I'm looking to modify this so as to make this input file a Python script instead, and was wondering if someone can point me to a beginner's guide to using the parser module in Python. I'm fairly new to Python itself, but have worked through a fair chunk of the online tutorial.

根据我的研究,我知道有一些选项(例如pyparsing)可以使我保留现有的语法,并使用Pyparsing代替lex/yacc.但是,我很好奇要更详细地学习Python解析器模块并探索其可行性.

From what I have researched, I know there are options (such as pyparsing) which can allow me to keep the existing grammar and use Pyparsing as a replacement for lex/yacc. However, I am curious to learn the Python parser module in more detail and explore its feasibility.

谢谢.

推荐答案

正如Jochen所说,解析器模块用于解析Python代码.我认为您最好查看内德·巴切尔德(Ned Batchelder)的解析器列表. PyParsing所做的事情与Lex和Yacc完全不同,因此我不确定为什么您认为可以保留现有的语法和lexer.最好的选择可能是David Beazley的 PLY 工具包.它坚固并且具有出色的文档.

As Jochen said, the parser module is for parsing Python code. I think you're best off checking out Ned Batchelder's list of parsers. PyParsing does things pretty differently from Lex and Yacc, so I'm not sure why you think you could keep your existing grammar and lexer. A better bet might be David Beazley's PLY toolkit. It's solid and has excellent documentation.

这篇关于Python解析器模块教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆