Exemple #1
0
def test_print_escape_newlines():
    assert parse([
        tokens.ID('print'),
        tokens.WS(' '),
        tokens.ID('butt\\n'),
        tokens.WS('\n'),
    ]) == ast.Module(ast.Print(), ast.String(' butt\n'))
Exemple #2
0
def test_print():
    assert parse([
        tokens.ID('print'),
        tokens.WS(' '),
        tokens.ID('butt'),
        tokens.WS('\n'),
    ]) == ast.Module(ast.Print(), ast.String(' butt'))
Exemple #3
0
def my_compile(source, filename='<unknown>', mode='exec'):
    try:
        from mylang.parse import parse
    except ImportError:
        raise ImportError('PLY is not installed')

    ast_root = parse(source, filename, mode)
    return compile(ast_root, filename, mode)
Exemple #4
0
def hic(source):
    llsource = str(compiler(parse(lex(source))))

    _, s = mkstemp('.s')
    interpreter = Popen(('llc', '-o', s), stdin=PIPE)
    interpreter.communicate(llsource)
    assert interpreter.returncode == 0, interpreter.returncode

    clang = Popen(('clang', s))
    clang.wait()
    assert clang.returncode == 0, clang.returncode
    os.unlink(s)
Exemple #5
0
def test_parse_hello():
    assert parse([tokens.ID('hello')]) == ast.Module(ast.Hello())
Exemple #6
0
def test_parse_null():
    assert parse([]) == ast.Module()
Exemple #7
0
def test_parse_hello_with_whitespace():
    assert parse([tokens.WS('\n\n   '),
                  tokens.ID('hello'),
                  tokens.WS('\n\t')]) == ast.Module(ast.Hello())
Exemple #8
0
def hello(source):
    return interpret(str(compiler(parse(lex(source)))))