[Tutor] grammer
Kent Johnson
kent37 at tds.net
Fri Mar 21 13:01:23 CET 2008
Eric Walker wrote:
> Hello,
> I have been reading about python grammers for processing text files. Does anyone have any simple examples?
Do you mean parsers written in Python for processing text files? A
grammar is usually an abstract specification of a format, not something
that will actually process the format.
There are many add-on packages for writing parsers in Python. A good
list is here:
http://nedbatchelder.com/text/python-parsers.html
IMO pyparsing is one of the easiest to use. It comes with many examples:
http://pyparsing.wikispaces.com/
One of the pyparsing examples parses grammar descriptions in Extended
Backus-Naur Form (EBNF) and produces a pyparsing parser for the grammar:
http://pyparsing.wikispaces.com/space/showimage/ebnf.py
David Mertz' book Text Processing in Python has many examples:
http://gnosis.cx/TPiP/
HTH
Kent
More information about the Tutor
mailing list