It is not simple. You should
- have a grammar for arithmetic expressions
- build lexer / parser from grammar
- parse your string with the help of a parser and ask the parser to perform semantic actions corresponding to the arithmetic operators of your grammar.
You can find a simple example in the ANTLR documentation : section 2.1 Creating a simple grammar, there is a Java example with a grammar for basic arithmetic expressions.
source
share