Postfix Evaluation

I am having trouble understanding why the PostfixEvaluator method in the class PostfixEvaluator is causing a number of problems; everything else works fine.
import java.io.*;          
import javax.swing.JOptionPane;
class Stack
   private int maxSize;
   private char[] stackArray;
   private int top;
   public Stack(int s)       // Constructor of Stack
      maxSize = s;
      stackArray = new char[maxSize];
      top = -1;
   public void push(char j) {  // Puts item on top of stack
       stackArray[++top] = j; }
   public char pop(){         // Takes an item from the top of stack
   return stackArray[top--]; }
   public char peek(){        // Shows item at the top of the stack
   return stackArray[top]; }
   public boolean isEmpty(){  // Returns true if stack is empty
   return (top == -1); }
class Converter                  // This class converts Infix input to Postfix output
   private Stack theStack;
   private String input;
   private String output = "";
   public Converter(String in) { // Constructor for the Converter class
      input = in;
      int stackSize = input.length();
      theStack = new Stack(stackSize);
   public String toPostFix()    // toPostFix method
      for(int j=0; j<input.length(); j++)     
         char ch = input.charAt(j);           
         switch(ch)
            case '+':              
            case '-':
               gotOper(ch, 1);     
               break;              
            case '*':              
               gotOper(ch, 2);     
               break;              
            case '(':              
               theStack.push(ch);  
               break;
            case ')':              
               gotParen(ch);       
               break;
            default:              
               output = output + ch;
               break;
            }  // end switch
         }  // end for
      while( !theStack.isEmpty() )    
         output = output + theStack.pop();
      return output;                   // Returns Postfix Answer to User
   public void gotOper(char opThis, int prec1) // Get Operator from entered Expression
      while( !theStack.isEmpty() )
         char opTop = theStack.pop();
         if( opTop == '(' )            // if it's a '(' (left parentheses)
            theStack.push(opTop);      // Push '(' into the stack
            break;
         else                          // If it isn't a left parentheses
            int prec2;                 //
            if(opTop=='+' || opTop=='-')  // Gets precedence of operator
               prec2 = 1;     //
            else
          prec2 = 2;       // Assigns Precedence
            if(prec2 < prec1)          // Compares Precedence
               theStack.push(opTop);  
               break;
            else                      
               output = output + opTop; 
  theStack.push(opThis);
   public void gotParen(char ch)
      while( !theStack.isEmpty() )
         char chx = theStack.pop();
         if( chx == '(' )         
            break;                
         else                      
            output = output + chx; 
public class PostfixEvaluator
       StackArray stackArray = new StackArray();
       StringTokenizer tok;
       private int val1,val2;
       private int result;
    public PostfixEvaluator(String output)
    tok = new StringTokenizer(output);
     while(tok.hasMoreElements())
     String token = tok.nextToken();
     if(Numeral.isOperand(token))
     stack.push(token);
     else if(Numeral.isOperator(token))
     if(token.equals("+"))
     val1 = Integer.parseInt(stackArray.pop().toString());
     val2 = Integer.parseInt(stackArray.pop().toString());
     result = val1 + val2;
     stack.push(new Integer(result));
     else if(token.equals("-"))
     val1 = Integer.parseInt(stackArray.pop().toString());
     val2 = Integer.parseInt(stackArray.pop().toString());
     result = val2 - val1;
     stackArray.push(new Integer(result));
     else if(token.equals("*"))
     val1 = Integer.parseInt(stackArray.pop().toString());
     val2 = Integer.parseInt(stackArray.pop().toString());
     result = val1 * val2;
     stackArray.push(new Integer(result));
     else if(token.equals("/"))
     val1 = Integer.parseInt(stackArray.pop().toString());
     val2 = Integer.parseInt(stackArray.pop().toString());
     result = val2 / val1;
     stackArray.push(new Integer(result));
     public String getResult()
     return String.valueOf(stackArray.top());
class Calculator
   public static void main(String[] args) throws IOException
      String input, output;
           input = JOptionPane.showInputDialog(null, "Enter an Infix Expression:"); // Enter an infix expression
         Converter docalculation = new Converter(input); // --> See Converter Class
          output = docalculation.toPostFix(); // Does Infix to Postfix Calculation
         JOptionPane.showMessageDialog(null, "The Postfix Expression is: " + output); // Outputs the postfix expression
         JOptionPane.showMessageDialog(null, "The evaluated expression is: " + getResult(output));
   }  Edited by: babypurin on Oct 14, 2009 10:37 PM

I get the following compiling errors (I am having trouble interpreting what these error messages mean).
Calculator.java:123: cannot find symbolsymbol : class StackArraylocation: class Converter.PostfixEvaluator     StackArray stackArray = new StackArray();     
Calculator.java:124: cannot find symbolsymbol : class StringTokenizerlocation: class Converter.PostfixEvaluator     StringTokenizer tok;     
Calculator.java:123: cannot find symbolsymbol : class StackArraylocation: class Converter.PostfixEvaluator     StackArray stackArray = new StackArray();     Calculator.java:131: cannot find symbolsymbol : class StringTokenizerlocation: class Converter.PostfixEvaluator tok = new StringTokenizer(output);
Calculator.java:135: cannot find symbolsymbol : variable Numerallocation: class Converter.PostfixEvaluator     if(Numeral.isOperand(token))     
Calculator.java:137: cannot find symbolsymbol : variable stacklocation: class Converter.PostfixEvaluator     stack.push(token);     
Calculator.java:139: cannot find symbolsymbol : variable Numerallocation: class Converter.PostfixEvaluator     else if(Numeral.isOperator(token))     
Calculator.java:146: cannot find symbolsymbol : variable stacklocation: class Converter.PostfixEvaluator     stack.push(new Integer(result));     
Calculator.java:200: cannot find symbolsymbol : variable output2location: class Converter.Calculator     output2 = output.PostfixEvaluator(); // Calculates value of postfix expression     Calculator.java:200: cannot find symbolsymbol : method PostfixEvaluator()location: class java.lang.String     output2 = output.PostfixEvaluator(); // Calculates value of postfix expression     
Calculator.java:204: cannot find symbolsymbol : variable output2location: class Converter.Calculator JOptionPane.showMessageDialog(null, "The evaluated expression is: " + output2);
Calculator.java:188: inner classes cannot have static declarations public static void main(String[] args) throws IOException

Similar Messages

  • Need help with creating a postfix evaluator WILL GIVE DUKE DOLLARS

    I know this is long but it needs to be so that you may understand:
    I was given a template for a class PostFixEvaluator and need to create a method for a postfix evaluator named evaluatePostfixExpression that reads the expression of single number digits and operands into a stringbuffer. I have an algorithm for the process which is :
    a) append a right parentheis to end the postfix expression. when it is encountered no further processing is necessary.
    b) if the right parenthesis is not encountered, read the expression from left to right. if the current char is digit then pust its int value on the stack otherwise if the char is an operator pop the two top elements off the stack into variables x,y. calculate y operator x. push the result of the calculation onto the stack.
    c) when the right parenthesis is encountered, pop value off the stack. this is result of the postfix expression.
    this is what i have, can you please let me know where i am going wrong?:
    public class PostfixEvaluator
    public static void main (String [] args)
    StringBuffer expression = new StringBuffer(
    JOptionPane.showInputDialog( " Enter a positive expression: " ));
    int answer = evaluatePostfixExpression(expression); // I GET AN ERROR HERE
    System.out.println(" The value of the expression is: " + answer + "\n");
    System.exit(0);
    public int evaluatePostfixExpression(String str) {
    StringBuffer postfix = new StringBuffer(str);
    StringBuffer digits;
    IntegerStack is = new IntegerStack(256);
    int x, y;
    char current = postfix.charAt('0');
    postfix.append(')');
    for(int i=0; current != ')'; i++) {
    if (Character.isDigit(current)) {
    digits = new StringBuffer();
    if (Character.isDigit(current)) {
    do {
    digits.append(current);
    i++;
    } while (Character.isDigit(current));
    i--;
    is.pushInt(Integer.parseInt(digits.toString()));
    } else if (current == '+' || current == '-' || current == '*'
    || current == '/' || current == '^' ) {
    y = is.popInt();
    x = is.popInt();
    is.pushInt(calculate(x, y, current));
    return is.popInt();
    private int calculate(int op1, int op2, char oper) {
    switch(oper) {
    case '+':
    return op1+op2;
    case '-':
    return op1-op2;
    case '*':
    return op1*op2;
    case '/':
    return op1/op2;
    case '^':
    return (int) Math.pow(op1, op2);
    return 0;
    class IntegerStack extends StackInheritance
    public int stackTop()
    int temp = popInt();
    pushInt(temp);
    return temp;
    public int popInt()
    return ((Integer)super.pop()).intValue();
    public void pushInt (int c)
    super.push(new Integer(c) );

    last time i checked String was not the same as StringBuffer.
    maybe you would like to turn your expression into a String?!!
    for that you need to check the API, for what methods might help you on doing that...
    just maybe you find in java.lang.StringBuffer's specification that it has some method called to_string() or something very similar....
    then you could do the following:
    int answer = evaluatePostfixExpression( expression.to_string() );of course "to_string" would need replacement by method name you find from the API...

  • Stack and queue problem

    hi i am trying to change infix expression to postfix and also the opposite, like
    ((a+b)*(a-c*d)/(b+d*e)) to ab+acb*-bde+/
    using stack and queue
    I am so confuse

    Hello,
    See this URL :
    http://www24.brinkster.com/premshree/perl
    You will find the algorithms here.
    Here is a Perl version :
    #     Script:          infix-postfix.pl
    #     Author:          Premshree Pillai
    #     Description:     Using this script you can :
    #               - Convert an Infix expression to Postfix
    #               - Convert a Postfix expression to Infix
    #               - Evaluate a Postfix expression
    #               - Evaluate an Infix expression
    #     Web:          http://www.qiksearch.com
    #     Created:     23/09/02 (dd/mm/yy)
    #     � 2002 Premshree Pillai. All rights reserved.
    sub isOperand
         ($who)=@_;
         if((!isOperator($who)) && ($who ne "(") && ($who ne ")"))
              return 1;
         else
              return;
    sub isOperator
         ($who)=@_;
         if(($who eq "+") || ($who eq "-") || ($who eq "*") || ($who eq "/") || ($who eq "^"))
              return 1;
         else
              return;
    sub topStack
         (@arr)=@_;
         my $arr_len=@arr;
         return($arr[$arr_len-1]);
    sub isEmpty
         (@arr)=@_;
         my $arr_len=@arr;
         if(($arr_len)==0)
              return 1;
         else
              return;
    sub prcd
         ($who)=@_;
         my $retVal;
         if($who eq "^")
              $retVal="5";
         elsif(($who eq "*") || ($who eq "/"))
              $retVal="4";
         elsif(($who eq "+") || ($who eq "-"))
              $retVal="3";
         elsif($who eq "(")
              $retVal="2";
         else
              $retVal="1";
         return($retVal);
    sub genArr
         ($who)=@_;
         my @whoArr;
         for($i=0; $i<length($who); $i++)
              $whoArr[$i]=substr($who,$i,1);
         return(@whoArr);
    sub InfixToPostfix
         ($infixStr)=@_;
         my @infixArr=genArr($infixStr);
         my @postfixArr;
         my @stackArr;
         my $postfixPtr=0;
         for($i=0; $i<length($infixStr); $i++)
              if(isOperand($infixArr[$i]))
                   $postfixArr[$postfixPtr]=$infixArr[$i];
                   $postfixPtr++;
              if(isOperator($infixArr[$i]))
                   if($infixArr[$i] ne "^")
                        while((!isEmpty(@stackArr)) && (prcd($infixArr[$i])<=prcd(topStack(@stackArr))))
                             $postfixArr[$postfixPtr]=topStack(@stackArr);
                             pop(@stackArr);
                             $postfixPtr++;
                   else
                        while((!isEmpty(@stackArr)) && (prcd($infixArr[$i])<prcd(topStack(@stackArr))))
                             $postfixArr[$postfixPtr]=topStack(@stackArr);
                             pop(@stackArr);
                             $postfixPtr++;
                   push(@stackArr,$infixArr[$i]);
              if($infixArr[$i] eq "(")
                   push(@stackArr,$infixArr[$i])
              if($infixArr[$i] eq ")")
                   while(topStack(@stackArr) ne "(")
                        $postfixArr[$postfixPtr]=pop(@stackArr);
                        $postfixPtr++;
                   pop(@stackArr);
         while(!isEmpty(@stackArr))
              if(topStack(@stackArr) eq "(")
                   pop(@stackArr)
              else
                   $temp=@postfixArr;
                   $postfixArr[$temp]=pop(@stackArr);
         return(@postfixArr);
    sub PostfixToInfix
         ($postfixStr)=@_;
         my @stackArr;
         my @postfixArr=genArr($postfixStr);
         for($i=0; $i<length($postfixStr); $i++)
              if(isOperand($postfixArr[$i]))
                   push(@stackArr,$postfixArr[$i]);
              else
                   $temp=topStack(@stackArr);
                   pop(@stackArr);
                   $pushVal=topStack(@stackArr).$postfixArr[$i].$temp;
                   pop(@stackArr);
                   push(@stackArr,$pushVal);
         return((@stackArr));
    sub PostfixEval
         ($postfixStr)=@_;
         my @stackArr;
         my @postfixArr=genArr($postfixStr);
         for($i=0; $i<length($postfixStr); $i++)
              if(isOperand($postfixArr[$i]))
                   push(@stackArr,$postfixArr[$i]);
              else
                   $temp=topStack(@stackArr);
                   pop(@stackArr);
                   $pushVal=PostfixSubEval(topStack(@stackArr),$temp,$postfixArr[$i]);
                   pop(@stackArr);
                   push(@stackArr,$pushVal);
         return(topStack(@stackArr));
    sub PostfixSubEval
         ($num1,$num2,$sym)=@_;
         my $returnVal;
         if($sym eq "+")
              $returnVal=$num1+$num2;
         if($sym eq "-")
              $returnVal=$num1-$num2;
         if($sym eq "*")
              $returnVal=$num1*$num2;
         if($sym eq "/")
              $returnVal=$num1/$num2;
         if($sym eq "^")
              $returnVal=$num1**$num2;
         return($returnVal);
    sub joinArr
         (@who)=@_;
         my $who_len=@who;
         my $retVal;
         for($i=0; $i<$who_len; $i++)
              $retVal.=$who[$i];
         return $retVal;
    sub evalInfix
         ($exp)=@_;
         return PostfixEval(joinArr(InfixToPostfix($exp)));
    sub init
         my $def_exit="\n\tThank you for using this Program!\n\tFor more scripts visit http://www.qiksearch.com\n";
         printf "\n\tInfix - Postfix\n";
         printf "\n\tMenu";
         printf "\n\t(0) Convert an Infix Expression to Postfix Expression";
         printf "\n\t(1) Convert a Postfix Expression to Infix Expression";
         printf "\n\t(2) Evaluate a Postifx Expression";
         printf "\n\t(3) Evaluate an Infix Expression";
         printf "\n\t(4) Exit this Program";
         printf "\n\t(5) About this Program\n";
         printf "\n\tWhat do you want to do? (0/1/2/3/4/5) ";
         $get=<STDIN>;
         chomp $get;
         if(!(($get eq "0") || ($get eq "1") || ($get eq "2") || ($get eq "3") || ($get eq "4") || ($get eq "5")))
              printf "\n\t'$get' is an illegal character.\n\tYou must enter 0/1/2/3/4/5.";
         if(($get ne "4") && ($get ne "5") && (($get eq "0") || ($get eq "1") || ($get eq "2") || ($get eq "3")))
              printf "\n\tEnter String : ";
              $getStr=<STDIN>;
              chomp $getStr;
         if($get eq "0")
              printf "\tPostfix String : ";
              print InfixToPostfix($getStr);
         if($get eq "1")
              printf "\tInfix String : ";
              print PostfixToInfix($getStr);
         if($get eq "2")
              printf "\tPostfix Eval : ";
              print PostfixEval($getStr);
         if($get eq "3")
              printf "\tExpression Eval : ";
              print evalInfix($getStr);
         if($get eq "4")
              printf $def_exit;
              exit 0;
         if($get eq "5")
              printf "\n\t======================================================";
              printf "\n\t\tInfix-Postfix Script (written in Perl)";
              printf "\n\t\t(C) 2002 Premshree Pillai";
              printf "\n\t\tWeb : http://www.qiksearch.com";
              printf "\n\t======================================================\n";
              printf "\n\tUsing this program, you can : ";
              printf "\n\t- Convert an Infix Expression to Postfix Expression.";
              printf "\n\t Eg : 1+(2*3)^2 converts to 123*2^+";
              printf "\n\t- Convert a Postfix Expression to Infix Expression.";
              printf "\n\t Eg : 123*+ converts to 1+2*3";
              printf "\n\t- Evaluate a Postfix Expression";
              printf "\n\t Eg : 37+53-2^/ evaluates to 2.5";
              printf "\n\t- Evaluate an Infix Expression";
              printf "\n\t Eg : (5+(4*3-1))/4 evaluates to 4";
              printf "\n\n\tYou can find the algorithms used in this Program at : ";
              printf "\n\t-http://www.qiksearch.com/articles/cs/infix-postfix/index.htm";
              printf "\n\t-http://www.qiksearch.com/articles/cs/postfix-evaluation/index.htm";
              printf "\n\n\tYou can find a JavaScript implementation of 'Infix-Postfix' at : ";
              printf "\n\t-http://www.qiksearch.com/javascripts/infix-postfix.htm";
         printf "\n\n\tDo you want to continue? (y/n) ";
         my $cont=<STDIN>;
         chomp $cont;
         if($cont eq "y")
              init();
         else
              printf $def_exit;
              exit 0;
    init;

  • Infix to Postfix, and evaluation

    Hi,
    Right now I'm coding a program that transforms a string representing an infix expression (a+b) to a string result that represents the same expression but in postfix notation (a b +) and then evaluates it. The only difficulty is that I'm not using java, I'm requested to use PCSpim which is an assembly language. Could anybody help me by referrencing me to an algorithm, please note that assembly language is a low level language, therefore, structures are not defined, but can be simulated and registers are limited...
    Even better, if you know of any url that contains PCSpim codes, please let me know...
    thanks,
    Alessandro.

    The result was
    a 10k (that's another advantage of programming in
    assembly language) file which runs very fast. I
    recommend assembly language for operations that
    require speed! and Java for anything you wish!.That's true but what happens to portability. To move your program to some other platform you face writing a 10k assembly program (for a processor you may know nothing about). I think you should use assembly only as a last resort, and carefully consider if you really need that speed.

  • Logical infix expression to postfix error

    Hi,
    I've got a program which takes input at command line as an infix expressions and then aims to convert it to postfix for later evaluation . I carry this out using two stacks. My coding for this to happen is below( only parts i felt needed):
    private String postfix = "";
        private static Stack<Character> operatorStack = new Stack<Character>();
        private static Stack<Character> operandStack = new Stack<Character>();
                userEntry.trim();
                char[] temp = userEntry.toCharArray();
                for (int i = 0 ; i < temp.length ; i++) {
                    char a = temp;
    System.out.println(a);
    dump(temp);
    if(userEntry.startsWith("end")) {
    finished = true;
    System.out.println("Thank You for using Calculator");
    * dump. Places the input into a char array and push each
    * char to stack.
    * @param temp array of strings to be tokenized and
    * pushed ontop of stack
    private void dump(char[] temp)
    for(char c : temp) {
    Character C = new Character(c);
    String token;
    token = C.toString();
    System.out.println("Testing token "+token);
    //its a number just add to the postfix string
    if (Character.isDigit(C)) {
    postfix = postfix + "" + (Integer.parseInt(token));
    System.out.println("new infix"+ postfix);
    //its an operator so push it to operator stack
    else if (token.equals("(")) {
    operatorStack.push(C);
    System.out.println(operatorStack.peek());
    // pop everthing before the ")" until you hit an "(" , this will be the operands
    else if (token.equals(")")) {
    while ((operatorStack.peek()).charValue() != '(') {
    char ch = operatorStack.pop();
    postfix = postfix + " " + ch;
    System.out.println(operatorStack.empty()+"operator stack is empty");
    System.out.println("new postfix 2 "+postfix);
    System.out.println(operatorStack.pop()+"jus kicked somthin off");
    else if (token.equals(" ")){}
    //find the order of operators and put this in to the postfix script, the operators +-,/,- never make it on to the stack
    else {               
    System.out.println(operatorStack.empty()+"operator stack is empty");
    System.out.println(C);
    while (!(operatorStack.empty()) && !((operatorStack.peek()).equals('('))
    && ((setPrecedence(C)) <= (setPrecedence((operatorStack.peek()).charValue())))) {
    System.out.println("precedence test"+operatorStack.peek());
    operatorStack.push(C);
    postfix = postfix + " " + operatorStack.pop();
    System.out.println("just pushed operator");
    while (!operatorStack.empty()) {
    postfix = postfix + " " + operatorStack.pop();
    System.out.println("last postfix :"+postfix);
    public int setPrecedence(char x)
    if (x == '+'|| x == '-') {
    return 1;
    if (x == '*' || x == '/' || x == '%') {
    return 2;
    return 0;
    }if i was to enter at the command line ( 2 + 4 ) * 3 ( must have spaces)
    instead of the postfix conversion being "24+3* it results in "243".
    I've got various print statement in my code but  still can seem to figure out what am doing wrong. I believe the problem lies in my else block of statements.
    Example of entering an expression result :
    ( 2 * 4 ) * 3
    2
    4
    3
    Testing token (
    Testing token 
    Testing token 2
    new infix
    Testing token 
    Testing token *
    falseoperator stack is empty
    Testing token 
    Testing token 4
    new infix24
    Testing token 
    Testing token )
    falseoperator stack is empty
    new postfix 2 24
    (jus kicked somthin off
    Testing token 
    Testing token *
    trueoperator stack is empty
    Testing token 
    Testing token 3
    new infix243
    last postfix :243
    If you can see any reason why its producing this instead of the desired or any thing you disapprove of i would be  greatful if you would kindly say so.
    Thanks alot.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    * CORRECTED CODING INDENTION sorry* hopefully a little clearer.
    Hi,
    I've got a program which takes input at command line as an infix expressions and then aims to convert it to postfix for later evaluation . I carry this out using two stacks. My coding for this to happen is below( only parts i felt needed):
    private String postfix = "";
    private static Stack<Character> operatorStack = new Stack<Character>();
    private static Stack<Character> operandStack = new Stack<Character>();
                userEntry.trim();
                char[] temp = userEntry.toCharArray();
                for (int i = 0 ; i < temp.length ; i++) {
                    char a = temp;
    System.out.println(a);
    dump(temp);
    if (userEntry.startsWith("end")) {
    finished = true;
    System.out.println("Thank You for using Calculator");
    * dump. Places the input into a char array and push each
    * char to stack.
    * @param temp array of strings to be tokenized and
    * pushed ontop of stack
    private void dump(char[] temp)
    for(char c : temp) {
    Character C = new Character(c);
    String token;
    token = C.toString();
    System.out.println("Testing token "+token);
    //its a number just add to the postfix string
    if (Character.isDigit(C)) {
    postfix = postfix + "" + (Integer.parseInt(token));
    System.out.println("new infix"+ postfix);
    //its an operator so push it to operator stack
    else if (token.equals("(")) {
    operatorStack.push(C);
    System.out.println(operatorStack.peek());
    // pop everthing before the ")" until you hit an "(" , this will be the operands
    else if (token.equals(")")) {
    while ((operatorStack.peek()).charValue() != '(') {
    char ch = operatorStack.pop();
    postfix = postfix + " " + ch;
    System.out.println(operatorStack.empty()+"operator stack is empty");
    System.out.println("new postfix 2 "+postfix);
    System.out.println(operatorStack.pop()+"jus kicked somthin off");
    else if (token.equals(" ")) {
    //do nothing
    //find the order of operators and put this in to the postfix script, the operators +-,/,- never make it on to the stack
    else {               
    System.out.println(operatorStack.empty()+"operator stack is empty");
    System.out.println(C);
    while (!(operatorStack.empty()) && !((operatorStack.peek()).equals('('))
    && ((setPrecedence(C)) <= (setPrecedence((operatorStack.peek()).charValue())))) {
    System.out.println("precedence test"+operatorStack.peek());
    operatorStack.push(C);
    postfix = postfix + " " + operatorStack.pop();
    System.out.println("just pushed operator");
    while (!operatorStack.empty()) {
    postfix = postfix + " " + operatorStack.pop();
    System.out.println("last postfix :"+postfix);
    public int setPrecedence(char x)
    if (x == '+'|| x == '-') {
    return 1;
    if (x == '*' || x == '/' || x == '%') {
    return 2;
    return 0;
    }if i was to enter at the command line ( 2 + 4 ) * 3 ( must have spaces)
    instead of the postfix conversion being "24+3* it results in "243".
    I've got various print statement in my code but still can seem to figure out what am doing wrong. I believe the problem lies in my else block of statements.
    Example of entering an expression result :
    ( 2 * 4 ) * 3
    2
    4
    3
    Testing token (
    Testing token
    Testing token 2
    new infix
    Testing token
    Testing token *
    falseoperator stack is empty
    Testing token
    Testing token 4
    new infix24
    Testing token
    Testing token )
    falseoperator stack is empty
    new postfix 2 24
    (jus kicked somthin off
    Testing token
    Testing token *
    trueoperator stack is empty
    Testing token
    Testing token 3
    new infix243
    last postfix :243
    If you can see any reason why its producing this instead of the desired or any thing you disapprove of i would be greatful if you would kindly say so.
    Thanks alot.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Evaluating a String

    Hi,
    I'm trying to find a means of evaluating a mathematical expression contained within a String. For example, the string might be:
    4*2 + (34/(4 -3)), where the output of the function is a solved numberical value, in this case 42.
    I haven't been able to find anything in Java, although functions like this exist in javascript and even BBC basic (EVAL). Does anyone know where I can find something like this?
    Cheers,
    Pete Frederick

    You need to parse it. The easiest thing to do is converting it to postfix and then evaluating. Note that the eval function works in JavaScript because it is interpreted and not compiled. I'm sure there are lots of examples to be found on the web that do this.
    Kind regards,
      Levi

  • Parsing/evaluating conditional statements

    I need some help developing an algorithm for parsing and evaluating conditional statements. I need to be able to handle variables, logical operators, relational operators, mathematical operators, and parentheses.
    For example:
    if ( (a+1 > b*5) and ((c +2) * 6 <= 5) )
    All the variables correspond to a number so the expression could be trivially converted to something like this:
    if ( (8+1 > 4*5) and ((6 +2) * 6 <= 5) )
    I am aware that infix expression can be converted to postfix expressions for easier evaluation, but I don't know exactly how this is done, nor do I know if this would be the best way to do it.
    If more information is needed let me know.
    Thanks in advance,
    Paul

    Thanks, this is very helpful information. I ended up coding it by converting to postfix already and have had good results, but I will look into the tree method when I get some time and see if it works better for me. Also if you know what method would typically yeild the best performace for evaluation of the expressions, let me know.
    Also, for anyone else that might want to do this I coded a simple stack class to get around creating objects for evaluating integer/boolean expressions, as long as its not a problem if exceptions are not thrown if the expression's logic is messed up.
    Thanks again,
    Paul
    public class IntStack
        private int[] stack;
        private int top;
        public IntStack(int maxSize)
            stack = new int[maxSize];
            top = 0;
        public void push(int value)
            top++;
            stack[top] = value;
        public int popInt()
            top--;
            return stack[top+1];
        public void push(boolean value)
            top++;
            if (value)
                stack[top] = 1;
            else
                stack[top] = 0;
        public boolean popBool()
            top--;
            return stack[top+1] == 1;
        public boolean isEmpty()
            return top == 0;
    }

  • 10.6 Email-Server/Postfix Helo command rejected - local SMTP clients won't use FQDN

    Hi,
    I set up a 10.6 server as mail-server which works (more or less) fine. I can send and receive internal and external Emails from various Macs with mail.app and Windows-Boxes with Thunderbird. However, some clients will be rejected due to wrong Helo strings
    e.g. a Windows-Box using Outlook express
    server postfix/smtpd[73194]: NOQUEUE: reject: RCPT from winbox.intranet.example.com[192.168.2.21]: 504 5.5.2 <winbox>: Helo command rejected: need fully-qualified hostname; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<winbox>
    similar happens with my router sending status-Emails (replace "winbox" with "router")
    finally my stand-alone-fax-machine uses it's ip-address as helo-string (helo=<192.168.2.10>, similar error)
    For now I've commented out
    smtpd_helo_restrictions = reject_invalid_helo_hostname
    #reject_non_fqdn_helo_hostname
    which makes things work. But that's not the right way, I guess, moreover since this entry is "fixed" by Server-Admin ever now and then.
    Does this problem arise from misconfigured boxes or a misconfigured OSX-Server? Hope the latter since there're no options to change this in my router nor my fax-machine...
    Thanks

    Try this.
         Symptoms   Users who use Microsoft Outlook as their email client and whoconnect to an email server running on Mac OS X Server v10.6 may not beable to send mail. The following (or similar) alert is returned toOutlook clients:    The message could not be sent becauseone of the recipients was rejected by the server. The rejected emailaddress was "[email protected]" is subject "example", account:"mail.example.com" , server "mail.example.com", protocol: SMTP, serverresponse: "504 5.5.2 < hostname > : Helo command rejected: needfully qualified host name", port: 25, secure (SSL): no, server error:504, error number: 0x800CCC79.      Products Affected   Mac OS X Server 10.6        Resolution    In Mac OS X Server v10.6, Postfix is configuredto require a fully qualified hostname from SMTP clients. This settingis configurable and the restriction can be removed, however anymodification of a security-related setting should be evaluated prior tomaking the change.   Once you have evaluated the change, you can use the following steps to implement it:   Note: Before proceeding, back up the /etc/postfix/main.cf file as a precaution.  
    In /etc/postfix/main.cf, locate the smtpd_helo_restrictions setting
    Remove "reject_non_fqdn_helo_hostname" from the list of settings.
    Restart the Mail service.

  • Postfix operator conflict!!!!

    Try this code segment:
    //assuming all variables are previously declared.
    k = ++i-- + j;
    Why if the postfix operator cannot be evaluated until the operation is completed does it have a higher presedence that the prefix operator.
    When attempting to compile this code an error is generated. This error occurs because the prefix operator has a lower presedence than the postfix operator but Must be evaluated first in order to complete the command.

    The problem is that however it's parsed (++(i--) or (++i)--) one of the operations is applied to an expression rather than a variable which violates the syntax rules for Java.

  • Time Evaluation Re Run in Mid Month & Mid Mont Initialization !

    Hi There,
    i was trying to run Time evaluation for the period 01.04.2011 to 31/12/2011.
    from April, that is 01.04.4011 to 30.06.2011 Time evaluation was good, now time evaluation has to run from 01.07.2011 but time evaluation has repeated from 12.06.2011 to 11.07.2011 as Initialization period 07/2011, and the same scenario is repeated for the rest of the year..all periods are initiated on 12th of each month from 6th month that is 12.06.2011.
    i was been trying to rectify this issue but was not bale to solve it, could any one please look in to it and let me know how to solve it?
    your help is appreciated.
    Thanks
    Kumar

    Can you please regenerate Period Parameters for 2011 year in T-Code for OG00 for period parameter 01 and then give the hire date in the field Forced Recalculation as of run in PT60 and run  the time evaluation.
    Best Regards,

  • Classic report - Condition evaluated for every row

    APEX 4.2.2
    I am seeing something strange in a classic report region. A report started to fail at run-time with a strange error about bad syntax. When I run the page in debug mode, I see the following
    print column headings
    rows loop: 30 row(s)
    ...Execute Statement: begin wwv_flow.g_boolean := '' is not null;
    end;
    ......Result = false
    ...Execute Statement: begin wwv_flow.g_boolean := '' is not null;
    end;
    ......Result = false
    ...Execute Statement: begin wwv_flow.g_boolean := 'string with a embedded ' single quote' is not null;
    end;
    ......Result = true
    Looks like the APEX engine is evaluating a boolean expression after rendering and each and every row in the report. And for some strange reason, it is using a piece of data from my query's resultset and failing because of the bad syntax introduced due to the single-quote in the string.
    I have never seen this before. Any idea what is going on?
    Thanks

    Howdy Paul, sorry should have provided all the details. No, this is a standard generic column template. Ah, you are right, drat I should have looked closer. The template has use a condition to show either a highlighted row or normal one. Sorry for the false alarm, I can take it from here. Enjoy your flight :-)

  • Use of Time Evaluation to generate Absence Quota

    Hi,
    We are planning to use time evaluation to generate absence quota. At the moment we are using RPTQTA00 report to generate Absence Quota. We have negative time management and since, the project has already gone live i have very limited scope to change the basic settings for example we do not have any employee subgroup to identify part time employees, PT & FT are in one employee sub-groups. We have only one ESG & PSG for time recording, time quota etc. The base entitlement is defined for the FT employees and it is reduced propertionately based on the employement percentage in IT0007. Now we are going to adopt a change in design, and planning to have specific work-schedule for PT employees. In that case, we will not have the scope to maintain %age in IT0007 for part time employees but exact no of working hours will be used. It means that system will treat the PT emploees as FT while generating absence quota and output the FT absence entitlement. As i said earlier we can not differentiate PT employees from FT employees based on ESG or PSG, i can not create a separate quota selection rule for part time employees. Hence, we are moving from running RPTQTA00 report to time evaluation for absence quota generation purpose.
    Now can anybody please help finding a alternate solution for the above, if it is possible to do it through report RPTQTA00 or we have to adopt the time evaluation. In case we are going to generate absence quota through time evaluation, can we only generate absence quota and skip anything that is related to payroll.
    Any comments/suggestion/advise will be very helpful to us.
    Thanks.
    Sujit

    We are not able to generate absence quota for part-time employees as when we do that, system is treating PT employees as FT employees and the FT base entitlement is referred while calculating absence quota. i can not define separate absence entitlement for PT employees as we have only one ESG and PSG, and based on this quota selection group is defined. The QUOMO feature is defined based on work contract - employee sub-group (there is no separate emp sub-group for PT employees) - Pay Scale Group. We are having this problem as we have specific work schedule for PT employees now (Ex. we create 3 days work schedule with 15 hours: 4.5,4.5, 6 hours) and we are not maintaining employement percentage for them. So system is treating PT employee as FT employee with 100% employement percentage. Please let me know if you need any specific info to understand my issue.
    Thank you so much for the response.

  • Perform VENDOR EVALUATION for MORE THAN ONE VENDORS at a time

    Hello all,
    Please guide for any process where i can perform Vendor Evaluation for MORE THAN ONE vendors AT A TIME.
    At my location there are around thousand vendors, which are to be evaluated, and difficult to perform the evaluation process one-by-one.
    (ME61/ME62/ME63)
    Detailed replies with various possibilities would be highly appreciated.
    Thanks & Regards,
    Joy Ghosh

    The vendor evaluation for some thousand vendors at the same time has already been in SAP long before they developed LSMW. The purpose of LSMW is to load data from a legacy system, of course you can (mis-)use it for a lot other things.
    But you should not always use LSMW if you are to lazy to go thru the SAP standard menu to find a transaction like ME6G
    There you define a job that runs RM06LBAT report.
    You first have to define a selection variant for this report. this can be done in SE38 by entering the report name, select variant, clicking display, then entering a name for the variant and clicking Create.

  • [OIM 9.1.0.2] Access Policy being evaluated to an OIM user disabled.

    Hi Gurus,
    I have an Access Policy being evaluated and provisioning resource (AD) to an OIM user disabled.
    Any tip on what I should take a look?
    Thanks in advance.

    Hi all,
    I have configured out the XL.EvaluateMembershipForInactiveUser System Property as TRUE, but the membership rule does not get evaluated for disabled users. So the user still remain into the group. I have restarted the OIM.
    I need to active the Evaluate User Policies schedule task for this configuration be effective. Or should I do something more?
    Thanks a lot.

  • Error " In case of evaluated receipt settlement, please maintain tax code", during VI01

    Dear Team
    We have a scenario in our environment where for a delivery made for STO Purchase Order, we are trying to post shipping cost document for Shipping document.
    When we try to save the document, the system returns the error " In case of evaluated receipt settlement, please maintain tax code".
    We have checked in the system. The vendor to whom the PO has been raised is not maintained for Evaluated Receipt Settlement, and as this is a STO , no vendor info record has been maintained for the same.
    The issue has started to come for a new plant and transportation route, for other routes and plants we are still able to proceed successfully for creation of shipment costs
    Can this be an issue of master data maintanence that we may have missed during plant creation or transportation route creation
    Else, Kindly guide.

    Hi Tarunveer,
    Which Vendor are you mentioning: Plant Vendor of STO or Forwarding Agent.
    I am suggesting to check in LFM2 for Forwarding Agent.
    Same way, in the case of Invoice Tab in PO, (Which PO are you mentioning: STO or PO for Forwarding Agent?)
    Regards,
    MJ.

Maybe you are looking for