Just yesterday there was a post about a java expression evaluator called JEval going open source. This brought back memories of early part of last year when I had wanted the software for a rule engine I was developing. I am not sure what I hoped to achieve by doing this because in my case the rules were in java syntax. Some products I tested were
1. jep
2. jeplite
3. jformula
None of these would suit my need and I decided to write my own using javacc. I wanted a parser that would parse the expression and return me an AST. The parsers were in fact capable of evaluating the AST. But I didn't want that and just wanted only the AST. I found that while JavaCC would compile the expression and tell me if it was correct, I couldn't get a handle to the AST. The AST is used in a parser as an intermediate between a parse tree and a data structure
and differs from a parse tree by omitting nodes and edges for syntax rules that do not affect the semantics of the program. For example, grouping parentheses are omitted in an AST as the grouping of operands is explicit in the tree structure. In the end, I tried AST and the Calculator sample program was what fit my need to a T and I could get the AST that I wanted. I was a little
sad in the end because once I came to know of JavaCC, I had come to the conclusion that JavaCC would solve all my parsing needs. Only this time, javaCC proved inadequate and had to use ANTLR.
Showing posts with label java parser math expression javacc antlr rules. Show all posts
Showing posts with label java parser math expression javacc antlr rules. Show all posts
Subscribe to:
Posts (Atom)