Exemple #1
0
def pypy_parse(source, mode='exec', lineno=False):
    from pypy.interpreter.pyparser.pythonparse import PythonParser, make_pyparser
    # parser = build_parser_for_version("2.4", PythonParser())
    parser = make_pyparser('stable')
    builder = TupleBuilder(parser)
    parser.parse_source(source, mode, builder)
    return builder.stack[-1].as_tuple(lineno)
Exemple #2
0
def source2ast(source, mode='exec', version='2.4', space=None):
    from pypy.interpreter.pyparser.pythonparse import PythonParser, make_pyparser
    from pypy.interpreter.pyparser.astbuilder import AstBuilder
    parser = make_pyparser(version)
    builder = AstBuilder(parser, version, space=space)
    parser.parse_source(source, mode, builder)
    return builder.rule_stack[-1]
Exemple #3
0
def pypy_parse(source, mode='exec', lineno=False):
    from pypy.interpreter.pyparser.pythonparse import PythonParser, make_pyparser
    # parser = build_parser_for_version("2.4", PythonParser())
    parser = make_pyparser('stable')
    builder = TupleBuilder(parser)
    parser.parse_source(source, mode, builder)
    return builder.stack[-1].as_tuple(lineno)
Exemple #4
0
def source2ast(source, mode='exec', version='2.4', space=None):
    from pypy.interpreter.pyparser.pythonparse import PythonParser, make_pyparser
    from pypy.interpreter.pyparser.astbuilder import AstBuilder
    parser = make_pyparser(version)
    builder = AstBuilder(parser, version, space=space)
    parser.parse_source(source, mode, builder)
    return builder.rule_stack[-1]
Exemple #5
0
def ast_from_input(input, mode, transformer, parser):
    """converts a source input into an AST

     - input : the source to be converted
     - mode : 'exec', 'eval' or 'single'
     - transformer : the transfomer instance to use to convert
                     the nested tuples into the AST
     XXX: transformer could be instantiated here but we don't want
          here to explicitly import compiler or stablecompiler or
          etc. This is to be fixed in a clean way
    """
    builder = TupleBuilder(parser, lineno=True)
    parser.parse_source(input, mode, builder)
    tuples = builder.stack[-1].as_tuple(True)
    return transformer.compile_node(tuples)
Exemple #6
0
def ast_from_input(input, mode, transformer, parser):
    """converts a source input into an AST

     - input : the source to be converted
     - mode : 'exec', 'eval' or 'single'
     - transformer : the transfomer instance to use to convert
                     the nested tuples into the AST
     XXX: transformer could be instantiated here but we don't want
          here to explicitly import compiler or stablecompiler or
          etc. This is to be fixed in a clean way
    """
    builder = TupleBuilder(parser, lineno=True)
    parser.parse_source(input, mode, builder)
    tuples = builder.stack[-1].as_tuple(True)
    return transformer.compile_node(tuples)
Exemple #7
0
def eval_file(file_):
    from parser import parse_source

    with open(file_) as f:
        source = f.read()

    ast_node = parse_source(source)

    evaluator = Evaluator()
    # The print will be avoided after implementation of print in the language
    print(evaluator.eval_program(ast_node))
Exemple #8
0
        ofacts.append(f)
        del facts[0]
        defined.add(f.f)  # either it here already or we have to add it
        defined.add(f.x)
        defined.add(f.rhs)

    return ofacts


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if __name__ == "__main__":

    from docopt import docopt
    arguments = docopt(__doc__, version="pychuriso 0.001")

    defines, variables, uniques, facts, shows = parse_source(
        arguments['<input>'])

    # Set the search basis
    import combinators
    combinators.set_search_basis(arguments['--search-basis'])

    # set up the starting solution
    start = dict()
    for d, v in defines.items():
        start[d] = v  # add the defines
    for v in variables:
        start[
            v] = v  # variables have themselves as values, already asserted to be single chars

    # test out the ordering of facts
    if not arguments['--no-order']: