import java.util.*;
public class Calc {
int rc;
static int src;
double result;
double evalexpr;
double m;
String s;
String token;
String operator;
String expr;
String peektoken;
int cursor = 0;
public static void main(String[] args)
{
Calc x = new Calc();
src = x.process();
return;
}
private int process()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter an expression");
s = sc.nextLine();
boolean keepgoing = true;
while(keepgoing == true)
{
String j = sc.nextLine();
j = j.trim();
if (j== null)
{
keepgoing = false;
System.out.println("The input is" + token);
result = evalexpr();
continue;
}
}
return 0;
}
double evalterm()
{
double a = evalfactor();
token = peektoken();
if((token.equals("*")) || (token.equals("/")))
{
operator = token;
cursor++;
double b = evalfactor();
if ("*".equals(operator))
{
a=a*b;
}else{
a=a/b;
}
}
return a;
}
double evalexpr()
{
double x = evalterm();
token = peektoken();
double z;
if((token.equals("+")) || (token.equals("-")))
{
operator = token;
cursor++;
double y = evalterm();
if (operator == "+")
z = x + y;
else
z = x - y;
}
return x;
}
double evalfactor(){
token = peektoken();
if(token.equals("("))
{
cursor++;
double K = evalexpr();
}
else{
cursor++;
double r = Double.parseDouble(token);
}
return x;
}
private String peektoken() {
{
String j = "";
while(cursor<expr.length())
{
j = expr.substring(cursor,cursor+1);
if(j.matches("[0-9]"))
{
return j;
}
if(j.equals(" "))
{
cursor++;
continue;
}
if(j.matches("[+-*/]"))
{
return j;
}
System.out.println("Error");
return j;
}
return null;
}
}
String token(){
double evalterm();
return main;
}
}