#NEWLINE# def evalRPN( self , tokens ) : #NEWLINE# #INDENT# '\n        stack\n        basic in bytecode operation\n        basic in compiler technique\n        :param tokens:\n        :return:\n        ' #NEWLINE# ops = [ '+' , '-' , '*' , '/' ] #NEWLINE# def arith( a , b , op ) : #NEWLINE# #INDENT# if ( op == '+' ) : #NEWLINE# #INDENT# return ( a + b ) #NEWLINE# #UNINDENT# if ( op == '-' ) : #NEWLINE# #INDENT# return ( a - b ) #NEWLINE# #UNINDENT# if ( op == '/' ) : #NEWLINE# #INDENT# return int ( ( float ( a ) / b ) ) #NEWLINE# #UNINDENT# if ( op == '*' ) : #NEWLINE# #INDENT# return ( a * b ) #NEWLINE# #UNINDENT# #UNINDENT# stack = [ ] #NEWLINE# for token in tokens : #NEWLINE# #INDENT# if ( token not in ops ) : #NEWLINE# #INDENT# stack . append ( int ( token ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# arg2 = stack . pop ( ) #NEWLINE# arg1 = stack . pop ( ) #NEWLINE# result = arith ( arg1 , arg2 , token ) #NEWLINE# stack . append ( result ) #NEWLINE# #UNINDENT# #UNINDENT# return stack . pop ( )