Postfix error checking eval code

By Psono

I am trying to error check possibilities of when there are too many operands/ few operands. Would like some insight as to why my code is wrong or am I doing this wrong.
Many thanks in advance

public static int eval(List postfixExpression) {

    StackLinked<Integer> o = new StackLinked<Integer>();
    StackLinked<ExpressionToken> p = new StackLinked<ExpressionToken>();
    String result = new String();
    int counter = 0;
    int counter2 = 0;
    int op2 = 0;
    int op1 = 0;
    Integer value = 0;
    for(ExpressionToken token: postfixExpression){
        p.push(token);
        if(!o.isEmpty()){
                    throw new SyntaxErrorException ("Few operands");
                }else if (p.isEmpty()){
                        throw new SyntaxErrorException ("Too many operators");
                        }
        if (p.peek().kind == 4){
            p.pop();
                o.push(p.pop().value);
                o.push(p.pop().value);
                value = (o.pop() + o.pop());
                    if(p.isEmpty() == false){
                        ExpressionToken string = new ExpressionToken(Integer.toString(value));
                        p.push(string);
                    }
        }else
        if(p.peek().kind == 5){
            p.pop();
                o.push(p.pop().value);
                o.push(p.pop().value);
                value = (o.pop() - o.pop());
                    if(p.isEmpty() == false){
                        ExpressionToken string = new ExpressionToken(Integer.toString(value));
                        p.push(string);
                    }
        }
        else
        if(p.peek().kind == 6){
            p.pop();
                o.push(p.pop().value);
                o.push(p.pop().value);
                value = (o.pop() * o.pop());
                    if(p.isEmpty() == false){
                        ExpressionToken string = new ExpressionToken(Integer.toString(value));
                        p.push(string);
                    }
        }
        else
        if (p.peek().kind == 7){
            p.pop();
                o.push(p.pop().value);
                o.push(p.pop().value);
                value = (o.pop() / o.pop());
                    if(p.isEmpty() == false){
                        ExpressionToken string = new ExpressionToken(Integer.toString(value));
                        p.push(string);
                    }
        }
        else
        if (p.peek().kind == 8){
            p.pop();
                o.push(p.pop().value);
                o.push(p.pop().value);
                value = (o.pop() % o.pop());
                    if(p.isEmpty() == false){
                        ExpressionToken string = new ExpressionToken(Integer.toString(value));
                        p.push(string);
                    }
        }
    }
        //checking for errors
        List<ExpressionToken> b = postfixExpression;
        StackLinked<Integer> a = new StackLinked<Integer>();
        StackLinked<ExpressionToken> error = new StackLinked<ExpressionToken>();
            for (ExpressionToken tokenCheck: postfixExpression){
                error.push(tokenCheck);
                if(error.peek().kind == 3){
                    throw new SyntaxErrorException("It does not exist");
                }
                if (error.peek().kind == 7){
                    error.pop();
                        a.push(error.pop().value);
                        a.push(error.pop().value);
                        a.pop();
                            if (a.pop() == 0){
                                throw new SyntaxErrorException("Can't Divide by zero");
                            }
                }
            }
    return value;
}

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273