[pypy-dev] EBNF translation error

Timothy Baldridge tbaldridge at gmail.com
Fri Mar 4 14:14:43 CET 2011


I hope this is the right place for this question. I'm trying to write
a simple JIT-enabled interpreter. However, I'm hitting a odd error
when it comes to translation. I've copied the JavaScript example
parser almost verbatim, but here's my issues:

 First of all, here's parser (almost 100% like the JS example):

from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
from pypy.rlib.parsing.parsing import ParseError, Rule
import py
import sys

GFILE = py.magic.autopath().dirpath().join("grammar.txt")

try:
	t = GFILE.read(mode="U")
	regexs, rules, ToAST = parse_ebnf(t)
except ParseError, e:
	print e.nice_error_message(filename=str(GFILE), source=t)
	raise

parsef = make_parse_function(regexs, rules, eof=True)

def parse(code):
	t = parsef(code)
	return ToAST().transform(t)

and my grammar:

STRING: "\\"[^\\\\"]*\\"";
SYMBOL: "[A-Za-z+-_*<>]+";
KEYWORD: ":[A-Za-z+-_*<>]+";
INTEGER: "\-?([0-9]+)";
DECIMAL: "\-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][\+\-]?[0-9]+)?";
IGNORE: " |\n|\t|,";
value: <KEYWORD> | <SYMBOL> | <STRING> | <DECIMAL> | <INTEGER> |
<hash> | <vector> | <sexps>;
hash: ["{"] (entry [","])* entry ["}"];
vector: ["["] value* ["]"];
entry: STRING [":"] value;
sexps: ["("] value+ [")"];

I'm doing the following to compile the code to c:

import parse
t = Translation(parse.parse)
t.annotate([str])
t.rtype()
t.compile_c()
>>>
<---snip---->
File "/home/tbaldridge/pypy/pypy/translator/c/genc.py", line 339, in
getentrypointptr
    self._wrapper = new_wrapper(self.entrypoint, self.translator)
  File "/home/tbaldridge/pypy/pypy/translator/llsupport/wrapper.py",
line 57, in new_wrapper
    r_to = pyobj_repr)
  File "/home/tbaldridge/pypy/pypy/rpython/rtyper.py", line 931, in convertvar
    (r_from, r_to))
pypy.rpython.error.TyperError: don't know how to convert from
<InstanceRepr for pypy.rlib.parsing.tree.Node> to <PyObjRepr *
PyObject>

What am I missing? This seemed so straight-forward....

Thanks,

Timothy


-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)



More information about the Pypy-dev mailing list