Need some help fixing the errors in my code, im TRYING to make a math expression type of program, using stacks. Was running fine, then i wake up in the morning and my code has like 15compiler errors, would appreciate any help!!
import java.util.*;
import java.io.*;
public class d8 {
public static void main(String[] args) throws FileNotFoundException {
BufferedReader br = new BufferedReader(new FileReader(args[0]));
eval(br);
br.close();
}
public static void apply(GenericStack os, GenericStack vs){
int v1, v2, r;
char op;
op = os.pop();
v2 = vs.pop();
v1 = vs.pop();
/* printf("Applying %d %c %d...\n", v1, op, v2); /*debug*/
switch (op) {
case '+':
vs.push(v1 + v2);
break;
case '-':
vs.push(v1 - v2);
break;
case '/':
vs.push(v1 / v2);
break;
case '*':
vs.push(v1 * v2);
break;
case '%':
vs.push(v1 % v2);
break;
} /* switch */
} /* apply */
public static void eval(Bufferedreader src) throws IOException {
int x, num;
GenericStack ostack = new GenericStack();
GenericStack vstack = new GenericStack();
int c;
while ( (c = src.raed()) != -1 ) {
if ( c != '\n' && !Character.isDigit(c) )
System.out.printf("%c", c);
switch(c) {
case '(':
ostack.push((char)c);
break;
case ')':
/* dumpstack(ostack, 0);*/
while ( ostack.top() != '(' )
apply(ostack, vstack);
ostack.pop();
break;
case '0': case '1': case 2: case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
num = 0;
while ( Character.isDigit(c) ) {
/* printf("digit=%c\n", c); /*debug*/
System.out.printf("%c", c);
num = num * 10 + (c - '0');
src.mark(1);
c = src.read();
}
src.reset();
/* printf("num=%d\n",num);*/
vstack.push(num);
/* dumpstack(vstack,1);*/
break;
case '+': case '-':
case '*': case '/': case '%':
if ( !ostack.isEmpty() )
while ( !ostack.isEmpty() && prec(ostack.top()) >= prec((char)c))
apply(ostack, vstack);
ostack.push((char)c);
break;
case ' ': case '\t':
break;
case '\n':
while ( ! ostack.isEmpty() )
apply(ostack, vstack);
System.out.printf(" = %d.\n", vstack.pop());
break;
} /* switch */
} /* while */
} /* eval */
public static int prec (char c) {
switch (c) {
case '+':
case '-':
return(0);
case '*':
case '/':
case '%':
return(1);
case '(':
return(-1);
} /* switch */
return (-1);
} /* prec */
}
import java.util.*;
public class GenericStack {
private Node top;
private class Node {
private T data;
private Node next;
public Node(T item) {
data = item;
next = null;
}
}
public GenericStack () {
top = null;
}
public boolean isEmpty() {
return top = null;
}
public T top() {
return top.data;
}
public void push(t item) {
Node n = new Node(item);
n.next = top;
top = n;
}
public T pop() throws EmptyStackException{
if ( top == null )
throw new EmptyStackException();
T n = top.data;
top = top.next;
return n;
}
}