Ejemplo n.º 1
0
 private arithmetic_operator GetArithOp(Token token)
 {
     if (token == '+')
     {
         return new arithmetic_operator() { op = arith_operator.add };
     }
     else if (token == '-')
     {
         return new arithmetic_operator() { op = arith_operator.sub };
     }
     else if (token == '*')
     {
         return new arithmetic_operator() { op = arith_operator.mul };
     }
     else if (token == '/')
     {
         return new arithmetic_operator() { op = arith_operator.div };
     }
     else if (token == '%')
     {
         return new arithmetic_operator() { op = arith_operator.mod };
     }
     else if (token == '^')
     {
         return new arithmetic_operator() { op = arith_operator.pow };
     }
     else
     {
         throw new Exception("Token is not an operator: " + token);
     }
 }
Ejemplo n.º 2
0
 private bool IsTokenArithmeticOperator(Token token)
 {
     if (token == TokenType.symbol)
     {
         return (token == '+' || token == '-' || token == '*' || token == '/' || token == '%' || token == '^');
     }
     else
     {
         return false;
     }
 }
Ejemplo n.º 3
0
 private int ArithmeticOperatorPriority(Token token)
 {
     if (token == '+' || token == '-')
     {
         return 1;
     }
     else if (token == '*' || token == '/' || token == '%')
     {
         return 2;
     }
     else if (token == '^')
     {
         return 4;
     }
     else if (token == '(')
     {
         return 5;
     }
     else
     {
         return 0;
     }
 }