示例#1
0
 def assertCompile(self, source, testValue ):
   parser = Parser()
   ast = parser.parse(parser.lex( source ), "")
   gen = Generator().compile(ast)
   result = gen.execute()
   print gen.module
   self.assertEquals(result.as_real(Type.double()), testValue);
示例#2
0
 def assertCompile(self, source, testValue):
     parser = Parser()
     ast = parser.parse(parser.lex(source), "")
     gen = Generator().compile(ast)
     result = gen.execute()
     print gen.module
     self.assertEquals(result.as_real(Type.double()), testValue)
示例#3
0
  def test_parser(self):
    parser = Parser()
    state = parser.lex( "add(1,2)" )
    ast = parser.parse(state, "")

    assert(FunctionCall == ast[0].__class__)
    self.assertEquals("add", ast[0].name)
    self.assertEquals(2, len(ast[0].args))
    assert(Number == ast[0].args[0].__class__)
    assert(Number == ast[0].args[1].__class__)
示例#4
0
    def test_parser(self):
        parser = Parser()
        state = parser.lex("add(1,2)")
        ast = parser.parse(state, "")

        assert (FunctionCall == ast[0].__class__)
        self.assertEquals("add", ast[0].name)
        self.assertEquals(2, len(ast[0].args))
        assert (Number == ast[0].args[0].__class__)
        assert (Number == ast[0].args[1].__class__)