Polonaise.java

import java.io.*;
import java.util.*;
public class Polonaise {
  public static void main(String[] args) throws IOException {
    double g,d;
    Double value;
    Stack stack = new Stack();
    StreamTokenizer in =
      new StreamTokenizer(new InputStreamReader(System.in));
    in.wordChars('+','+'); // Les opérateurs constituent
    in.wordChars('-','-'); // les mots pour le tokenizer
    in.wordChars('/','/');
    in.wordChars('*','*');
    in.eolIsSignificant(false);
    loop: do {
      in.nextToken();
      if (in.ttype==StreamTokenizer.TT_NUMBER) {
        stack.push(new Double(in.nval));
    continue loop;
      }
      if (in.ttype==StreamTokenizer.TT_WORD) {
        if (in.sval.length()==1) {
          switch (in.sval.charAt(0)) {
          case '+':
            try{
          value = new Double(((Double)stack.pop()).doubleValue() +
                 ((Double)stack.pop()).doubleValue());
          stack.push(value);
          System.out.println(value);
            } catch(EmptyStackException e) {
          System.out.println("Pile vide !");
        }
            continue loop;
        // Autres opérateurs ...
          }
        }
      }
    } while (in.ttype!=StreamTokenizer.TT_EOF);
  }
}