Ejemplo n.º 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);
Ejemplo n.º 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)
Ejemplo n.º 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__)
Ejemplo n.º 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__)