Package tools.dictionary

Examples of tools.dictionary.Collection


public class App {
  public static void main (String[] args) throws IOException {
    BufferedReader we = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter wy = new PrintWriter(new OutputStreamWriter(System.out),true);
    PrintWriter bl = new PrintWriter(new OutputStreamWriter(System.err),true);
    Collection varCollection = new Collection();
    bl.println("hello");
    bl.print("> ");
    bl.flush();

    for (String instr=we.readLine(); instr!=null; instr=we.readLine())
      try {
        instr = instr.trim();
        if (instr.matches("^\\s*calc\\s+[\\x00-\\xff]*$") || instr.equals("calc")) {
          Pattern pattern = Pattern.compile("^\\s*calc\\s+([\\x00-\\xff]*)$");
          Matcher matcher = pattern.matcher(instr);
          if (matcher.find()) {
            Expression e = new Expression(varCollection,matcher.group(1));
            wy.format("%s\n",e.calculate());
            varCollection=e.getVarCollection();
          }
          else  
            throw new ExceptionRPN("calc needs expression");
        }
        else if (instr.matches("^\\s*clear\\s+[\\x00-\\xff]*$") || instr.equals("clear")) {
          String[] token = instr.split(" ");
          if (token.length==1)
            for (String s : varCollection.clear())
              wy.format("remove %s\n",s);
          else
            for (int i=1; i<token.length; ++i)
              try {
                varCollection.delete(token[i]);
                wy.format("remove %s\n",token[i]);
              }
              catch (Exception ex) {
                throw new RPN_VarNotFound(token[i]);
              }
View Full Code Here

TOP

Related Classes of tools.dictionary.Collection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.