[pypy-dev] Customized parser
arigo at tunes.org
Tue Oct 9 11:05:08 CEST 2007
On Fri, Oct 05, 2007 at 09:24:48PM +0200, Franck Pommereau wrote:
> I'd like to build a CPython program that would include a parser for a
> Python-like language. My idea was to start from PyPy's parser that is
> already written in pure Python. All I need is a parser that builds an
> AST or something equivalent.
> This is the idea. But from now on, I'm lost in PyPy's sources. I did not
> even figure out how to call the parser correctly...
> Does any one has an example that could guide me?
PyPy itself has optionally the ability to modify its own grammar at
run-time. You have to translate it with --withmod-dyngram (or
--allworkingmodules) to enable the 'dyngram' module. See a usage
example in pypy/module/recparser/test/test_dyn_grammarrules (I didn't
try to run this code myself on a pypy-c though).
That's not really answering your question, though, which was how to grab
PyPy's bytecode compiler and start playing with it. Unfortunately I
cannot really answer this question, as it seems that nobody is left
around here which really cares about this part of the code. But you
should be able to get started by looking at the helper function
source2ast() in pypy/interpreter/pyparser/test/test_astbuilder.
More information about the Pypy-dev