def eval(string): infile = StringIO(string) tokens = analysis.lexical(Toolchain, infile) tree = analysis.syntax(Toolchain, tokens) node = analysis.semantic(Toolchain, tree) result = evaluate(node, Toolchain.Evaluator()) outfile = StringIO() formatter = Toolchain.formatters['text'](outfile) visit(result, formatter) formatter.finish() assert (outfile.getvalue()[-1] == '\n') return outfile.getvalue()[:-1]
def p(text): tokens = analysis.lexical(Toolchain, StringIO(text)) tree = analysis.syntax(Toolchain, tokens) node = analysis.semantic(Toolchain, tree) return node
def typeof(string): infile = StringIO(string) tokens = analysis.lexical(Toolchain, infile) tree = analysis.syntax(Toolchain, tokens) node = analysis.semantic(Toolchain, tree) return Toolchain.typeof(node)