def test_equal_without_int_error_interpreter(self):
     a="a = 1 ;"
     """ =
       /   \
      a     1 """
     root=CParser.oneTimeParse(a)
     self.assertRaises(SyntaxError,root[0].interpreter)
 def test_while_infinity_lopp_raise_syntax_interpreter(self):
     a="""int x = 0 ;
          while ( 1 ) x ++ ;
         """
     root=CParser.oneTimeParse(a)
     root[0].interpreter()
     self.assertRaises(SyntaxError,root[1].interpreter)
 def test_do_while_loop_interpreter_2nd(self):
     a="""int x = 0 ;
             do { }
          while ( x < 3 ) ;"""
     root=CParser.oneTimeParse(a)
     root[0].interpreter()
     self.assertRaises(SyntaxError,root[1].interpreter)
 def test_braceket_interpreter(self):
     a=" ( 2 + 3 ) * 4 ;"
     """     *
           /    \
          (      4
          |
          +
        /   \
       2     3 """
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertEqual(value,20)
     bracket=root[0].first
     value=bracket.interpreter()
     self.assertEqual(value,5)
     four=root[0].second
     value=four.interpreter()
     self.assertEqual(value,4)
     plus=bracket.first
     value=plus.interpreter()
     self.assertEqual(value,5)
     two=plus.first
     value=two.interpreter()
     self.assertEqual(value,2)
     three=plus.second
     value=three.interpreter()
     self.assertEqual(value,3)
 def test_while_loop_None_interpreter(self):
     a="""int x = 0 ;
          while ( x == 0 )  ;
         """
     root=CParser.oneTimeParse(a)
     root[0].interpreter()
     self.assertRaises(SyntaxError,root[1].interpreter)
 def test_int_limit_assign_after_declare_interpreter(self):
     a="""int main ( )
          {
             short int a = 70000 , b = - 70000 ;
             unsigned short int c = 70000 , d = - 70000 ;
             unsigned int e = 5000000000 , f = - 5000000000 ;
             int g = 5000000000 , h = - 5000000000 ;
             long int i = 5000000000 , j = - 5000000000 ;
          }"""
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('a')
     self.assertEqual(temp[1],32767)
     temp=scope.findVariable('b')
     self.assertEqual(temp[1],-32768)
     temp=scope.findVariable('c')
     self.assertEqual(temp[1],65535)
     temp=scope.findVariable('d')
     self.assertEqual(temp[1],0)
     temp=scope.findVariable('e')
     self.assertEqual(temp[1],4294967295)
     temp=scope.findVariable('f')
     self.assertEqual(temp[1],0)
     temp=scope.findVariable('g')
     self.assertEqual(temp[1],2147483647)
     temp=scope.findVariable('h')
     self.assertEqual(temp[1],-2147483648)
     temp=scope.findVariable('i')
     self.assertEqual(temp[1],2147483647)
     temp=scope.findVariable('j')
     self.assertEqual(temp[1],-2147483648)
 def test_add_function_declaration_interpreter(self):
     a="""int add ( int , int ) ;
         int add ( int a , int b ) { }"""
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('add')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1],root[1])
 def test_equalequal_condition_interpreter(self):
     a=" 1 == 1 ;"
     """ ==
        /  \
       1    1"""
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertTrue(value)
 def test_postfix_negative_interpreter(self):
     a="- 1 ;"
     """ -
         |
         1"""
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertEqual(value,-1)
 def test_not_bit_interpreter(self):
     a=" ! 2 ;"
     """ !
         |
         2"""
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertEqual(value,0)
 def test_xor_bit_interpreter(self):
     a=" ~ 2 ;"
     """ ~
         |
         2"""
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertEqual(value,-3)
 def test_and_bit_interpreter(self):
     a=" 5 & 6 ;"
     """ &
        /  \
       5    6"""
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertEqual(value,4)
 def test_shiftright_bit_interpreter(self):
     a=" 8 >> 3 ;"
     """ >>
        /  \
       8    3"""
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertEqual(value,1)
 def test_shiftleft_bit_interpreter(self):
     a=" 1 << 3 ;"
     """ <<
        /  \
       1    3"""
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertEqual(value,8)
 def test_smallerequal_condition_interpreter(self):
     a=" 2 < 1 ;"
     """ <=
        /  \
       2    1"""
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertFalse(value)
 def test_biggerequal_condition_interpret(self):
     a=" 2 >= 1 ;"
     """ >=
        /  \
       2    1"""
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertTrue(value)
 def test_for_loop_with_declaration_interpreter(self):
     a="""int x ;
          for ( x = 0 ; x < 5 ; x ++ ) ;"""
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('x')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1], 5)
 def test_int_a_without_value_interpreter(self):
     a="int a ;"
     """int-a"""
     root=CParser.oneTimeParse(a)
     root[0].interpreter()
     temp=scope.findVariable('a')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1],0)
 def test_int_a_with_value_plusplus_interpreter(self):
     a="""int a = 1 ;
         a ++ ;"""
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('a')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1] , 2 )
 def test_define_only_one_statement_interpreter(self):
     a="""#define Str  2 + 3 +
         int a = 0 ;
        { a = Str 4 ; }"""
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('a')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1], 9 )
 def test_array_interpreter(self):
     a="""int a [ 2 ] ;"""
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('a')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[0][1].id,'[')
     self.assertEqual(temp[1][0],None)
     self.assertEqual(temp[1][1],None)
 def test_do_while_loop_interpreter(self):
     a="""int x = 0 ;
             do {  x ++ ; }
          while ( x < 3 ) ;  """
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('x')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1], 3)
 def test_int_a_with_a_divide_by_two_interpreter(self):
     a="""int a = 1 ;
         a = a / 2 ;
         """
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('a')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1],0)
 def test_while_interpreter(self):
     a="""int x = - 1 ;
         while ( x < 1 ) x ++ ;
         """
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('x')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1], 1 )
 def test_plus_multiply_interpreter(self):
     a=" 2 + 3 * 4 ;"
     """       +
             /   \
           2      *
                 /  \
               3      4"""
     root=CParser.oneTimeParse(a)
     value=root[0].interpreter()
     self.assertEqual(value,14)
 def test_if_with_condition_interpreter(self):
     a="""
             int a = 5 ;
             if ( a == 1 ) a = 4 ;
         """
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('a')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1], 5 )
 def test_int_a_with_negative_value_interpreter(self):
     a="int a = -1 ;"
     """     =
           /   \
       int-a    1 """
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('a')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1],-1)
 def test_equal_with_double_zero_point_nine_interpreter(self):
     a="double a = 0.9 ;"
     """     =
           /   \
       double-a    1 """
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('a')
     self.assertEqual(temp[0][0],symbolTable['double'])
     self.assertEqual(temp[1],0.9)
 def test_main_function_interpreter(self):
     a=""" int main ( )
             {
                 int a ;
                 a = 3 ;
             }"""
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('a')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1],3)
 def test_if_with_else_if_true_interpreter(self):
     a="""
            int a = 5 ;
            if ( 0 ) a = 4 ;
            else if ( 1 ) a = 3 ;
         """
     root=CParser.oneTimeParse(a)
     Runinterpreter(root)
     temp=scope.findVariable('a')
     self.assertEqual(temp[0][0],symbolTable['int'])
     self.assertEqual(temp[1], 3 )