Got it to work! I added a few checks for parenthesis in logical areas, Here is the final:
public void makePost(String e)
{
String[] arr = e.split("");
for(int i = 0; i < arr.length; i++)
{
System.out.println(postfix + " " + i + " " + ops);
if(arr[i].equals(" "))
{
continue;
}
if(arr[i].equals("(")){
ops.push(new Paran("("));
continue;
}
if(!ops.isEmpty() && arr[i].equals(")")){
while(!ops.isEmpty() && !ops.peek().isOpen()){
postfix += " " + ops.pop();
}
ops.pop();
}
Operator o = OperatorList.getOpMap().get(arr[i]);
if(o == null){
postfix += " " + arr[i];
continue;
}
if(ops.isEmpty()){
ops.push(o);
continue;
}
else
{
while((!ops.isEmpty() && (ops.peek().getPresedence() <= o.getPresedence()) && !(ops.peek() instanceof Paran))){
postfix += " " + ops.pop();
}
ops.push(o);
continue;
}
}
while(!ops.isEmpty())
{
postfix += " " + ops.pop();
}
postfix = postfix.replaceAll("\\s[)]","");
}
I have the replaceall() call because the output kept return closing parenthesis along with the corrent postfix, ex:
2 4 * 7 8 4 * 4 4 5 * ) / ) * ) +
I have no idea why it does that, but I am glad it works