DParser for Python
DParser is a simple but powerful tool for parsing, written by J. Plevyak. DParser for Python gives Python
programmers a seamless interface to DParser.
The features that set this Python parser apart from other Python parsers are:
- it can deal with any grammar (GLR)
- it is fast (based in C)
- it does not require a compiler to operate.
DParser for Python also has many easy-to-use features found in other Python parsers:
- it does not require explicit definitions of tokens
- it does not require a separate, non-Python grammar file
- it uses function documentation strings to specify grammar rules
- it does not output parser code that the user must compile or run.
A simple example-- a grammar to add numbers:
from dparser import Parser
def d_add(t): # actions must start with 'd_'
"exp : exp '+' exp" # literals are put directly into grammar rules
return t[0] + t[2]
def d_number(t):
'exp : "[0-9]+" ' # regular expressions are enclosed in double quotes
return int(t[0])
print Parser().parse("2+3+4")
==> 9
Also see the slightly longer requisite calculator example.
Documentation
DParser for Python Documentation
DParser for Python requires at least Python 2.2
Contact
Brian Sabbey (sabbey_at_u_dot_washington_dot_edu.)