Exemplo n.º 1
0
def test_parser(expr):
    parser = parser2.Parser()  # tree type is parser wrapper
    parser.lex.newtext(expr)  # subtrees evaluate when clicked
    tree = parser.analyse()  # input line parses new expr
    entry.delete(0, END)  # vars set in wrapper dictionary
    entry.insert(0, expr)  # see lang/text chapter for parser
    if tree: viewer.drawTree(tree)
Exemplo n.º 2
0
 def _testNodes(self, index, EX, NODES):
     try:
         nodes = None
         parser = parser2.Parser()
         nodes = parser.parse('EX'+str(index), EX)
         self.failUnlessEqual(nodes, NODES)
     except:
         print "EXAMPLE #%s" % index
         print "EX:"
         print EX
         print "RESULT:", nodes
         print "EXPECT:", NODES
         raise
Exemplo n.º 3
0
 def onInputLine(self, line, viewer):  # on input line
     p = parser2.Parser()  # parse expr text
     p.lex.newtext(line)  # draw resulting tree
     t = p.analyse()
     if t: viewer.drawTree(t)
Exemplo n.º 4
0
            raise CodeGenError(tree)
    
    
def write_pyc_file(code, name):                                      
        pyc_file = name + '.pyc'
        print pyc_file
        with open(pyc_file,'wb') as pyc_f:
            magic = 0x03f30d0a
            pyc_f.write(struct.pack(">L",magic))
            pyc_f.write(struct.pack(">L",time.time()))
            marshal.dump(code.func_code, pyc_f)
            
               
if __name__ == '__main__':

    f = open(sys.argv[1])
    expr = f.read()
    f.close()
       
    s = scanner.Scanner(expr)
    tokens = s.scan()
    p = parser.Parser(tokens)
    tree = p.parse()
    
    print tree
    
    cg = CodeGen(tree)
    code = cg.generate()
    
    name = sys.argv[1].split('.')
    write_pyc_file(code, name[0])