Ejemplo n.º 1
0
  /**
   * Process an input string through the tokenizer and then parser.
   *
   * <p>A sequence of <code>$x=(3+5)/2;</code> will return an IExpressionNode with a value of <code>
   * 4.0</code>.
   *
   * @param sequence input to parse
   * @return IExpressionNode result
   * @throws ParserException
   */
  public List<IExpressionNode> parse(String sequence) throws ParserException {
    if (tokenizer == null) {
      tokenizer = new Tokenizer();
      initialiseTokenizer();
    }

    tokenizer.tokenize(sequence);
    statementList = tokenizer.getStatementList();

    return parse();
  }
Ejemplo n.º 2
0
 /** Add the set tokens for Parser's Tokenizer */
 private void initialiseTokenizer() {
   tokenizer.addToken("sin|cos|exp|ln|sqrt", FUNCTION);
   tokenizer.addToken("\\(", LPAREN);
   tokenizer.addToken("\\)", RPAREN);
   tokenizer.addToken("[+-]", PLUSMINUS);
   tokenizer.addToken("[*/]", MULTDIV);
   tokenizer.addToken("\\<|\\>|\\<\\=|\\>\\=|\\!\\=", COMPARATOR);
   tokenizer.addToken("\\^", RAISED);
   tokenizer.addToken("[0-9]+", NUMBER);
   tokenizer.addToken("\\$[a-zA-Z][a-zA-Z0-9_]*", VARIABLE);
   tokenizer.addToken("\\=", EQUALS);
   tokenizer.addToken("\\;", ITokens.SEMICOLON);
   tokenizer.addToken("print", PRINT);
 }