Package com.wesleyhome.math.equation.grammer

Examples of com.wesleyhome.math.equation.grammer.EquationGrammarParser$OpContext


import com.wesleyhome.math.equation.grammer.EquationGrammarParser.ProgContext;

class StringEquationParser {

  ExpressionNode parseExpression(final String expression) throws ParseCancellationException {
    final EquationGrammarParser parser = getParser(expression);
    final EqContext eq = parser.eq();
    final List<TerminalNode> equation1 = parseTree(eq);
    final ExpressionopContext expressionop = parser.expressionop();
    final List<TerminalNode> operatorTree = parseTree(expressionop);
    final EqContext eq2 = parser.eq();
    final List<TerminalNode> equation2 = parseTree(eq2);
    return new ExpressionNode(getString(equation1), operatorTree.get(0), getString(equation2));
  }
View Full Code Here


   * @return
   * @throws ParseCancellationException
   *             throws if equation is invalid
   */
  List<TerminalNode> parseEquation(final String equation) throws ParseCancellationException {
    final EquationGrammarParser parser = getParser(equation);
    final ProgContext tree = parser.prog();
    return parseTree(tree);
  }
View Full Code Here

  private EquationGrammarParser getParser(final String equation) {
    final ANTLRInputStream input = new ANTLRInputStream(equation);
    final EquationGrammarLexer lexer = new EquationGrammarLexer(input);
    final TokenStream tokenStream = new CommonTokenStream(lexer);
    final EquationGrammarParser parser = new EquationGrammarParser(tokenStream);
    final ANTLRErrorStrategy handler = new BailErrorStrategy();
    parser.setErrorHandler(handler);
    final ParseTreeListener listener = new EquationGrammerListener();
    parser.addParseListener(listener);
    return parser;
  }
View Full Code Here

TOP

Related Classes of com.wesleyhome.math.equation.grammer.EquationGrammarParser$OpContext

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.