Exemplo n.º 1
0
def repl():
    space = getspace()
    interp = Interpreter(space)
    print
    print '-=- Hippy -=-'
    print
    while True:
        try:
            line = raw_input("<? ")
        except EOFError:
            print
            break
        if not line.lstrip() or line.lstrip().startswith('//'):
            continue
        try:
            pc = parse(space, line, 0)
            bc = compile_ast("<input>", line, pc, space, print_exprs=True)
        except Exception, e:
            print >> sys.stderr, '%s: %s' % (e.__class__.__name__, e)
            continue
        try:
            interp.run_main(space, bc)
        except ExplicitExitException, e:
            os.write(1, e.message)
            sys.exit(e.code)
Exemplo n.º 2
0
def repl():
    space = getspace()
    interp = Interpreter(space)
    print
    print '-=- Hippy -=-'
    print
    while True:
        try:
            line = raw_input("<? ")
        except EOFError:
            print
            break
        if not line.lstrip() or line.lstrip().startswith('//'):
            continue
        try:
            pc = parse(space, line, 0, '<input>')
            bc = compile_ast("<input>", line, pc, space, print_exprs=True)
        except Exception, e:
            print >> sys.stderr, '%s: %s' % (e.__class__.__name__, e)
            continue
        try:
            interp.run_main(space, bc)
        except ExplicitExitException, e:
            os.write(1, e.message)
            sys.exit(e.code)
Exemplo n.º 3
0
def compile_php(filename, source, space, interp=None):
    """Parse and compile a PHP file, starting in literal mode (i.e.
    dumping all input directly) until the first '<?' or '<?php'.
    Supports a mixture of blocks of code between the blocks of texts."""

    phplexerwrapper = PHPLexerWrapper(source, filename, interp)
    if DEBUG:
        lst = []
        while True:
            tok = phplexerwrapper.next()
            if tok is None:
                break
            else:
                lst.append(tok)
        print[x.__dict__ for x in lst]
        phplexerwrapper = iter(lst + [None])
    parser = SourceParser(space, None, filename=filename)
    tokens = parser.parser.parse(phplexerwrapper, state=parser)
    bc = compile_ast(filename, source, tokens, space)
    return bc
Exemplo n.º 4
0
                else:
                    endpos = self.lexer.pos
                w_end = self.interp.space.newint(endpos)
                self.interp.constants['__COMPILER_HALT_OFFSET__'] = w_end
        #
        return None

DEBUG = False


def compile_php(filename, source, space, interp=None):
    """Parse and compile a PHP file, starting in literal mode (i.e.
    dumping all input directly) until the first '<?' or '<?php'.
    Supports a mixture of blocks of code between the blocks of texts."""

    phplexerwrapper = PHPLexerWrapper(source, filename, interp)
    if DEBUG:
        lst = []
        while True:
            tok = phplexerwrapper.next()
            if tok is None:
                break
            else:
                lst.append(tok)
        print [x.__dict__ for x in lst]
        phplexerwrapper = iter(lst + [None])
    parser = SourceParser(space, None, filename=filename)
    tokens = parser.parser.parse(phplexerwrapper, state=parser)
    bc = compile_ast(filename, source, tokens, space)
    return bc