Using JavaCC to infer semantics from a Composite tree
Posted
by Skice
on Stack Overflow
See other posts from Stack Overflow
or by Skice
Published on 2010-05-07T14:56:29Z
Indexed on
2010/05/07
15:08 UTC
Read the original article
Hit count: 310
Hi all,
I am programming (in Java) a very limited symbolic calculus library that manages polynomials, exponentials and expolinomials (sums of elements like "x^n * e^(c x)"). I want the library to be extensible in the sense of new analytic forms (trigonometric, etc.) or new kinds of operations (logarithm, domain transformations, etc.), so a Composite pattern that represent the syntactic structure of an expression, together with a bunch of Visitors for the operations, does the job quite well.
My problem arise when I try to implement operations that depends on the semantics more than on the syntax of the Expression (like integrals, for instance: there are a lot of resolution methods for specific classes of functions, but these same classes can be represented with more than a single syntax).
So I thought I need something to "parse" the Composite tree to infer its semantics in order to invoke the right integration method (if any). Someone pointed me to JavaCC, but all the examples I've seen deal only with string parsing; so, I don't know if I'm digging in the right direction.
Some suggestions? (I hope to have been clear enough!)
© Stack Overflow or respective owner