"Steve W. Jackson" <stevewjackson@knology.net> wrote in message
In article <1166782060.023296.203420@h40g2000cwb.googlegroups.com>,
"dhanya" <dhanya.aishwarya@gmail.com> wrote:
Hi folks,
Have an interesting problem. Hope someone can help me out. I have a
GUI where the end user enters some formula, mostly price calculations.
Also they can enter conditions like
IF(a>b) THEN a=10 ELSE a . I have to check whether the syntax is
correct and save this. Later in the application i have to get these
formulas and convery into java if else stmts. Please give me your views
about how to deal with this.
Depending on whether this is a classroom assignment or not, you might
look into JavaCC.
JavaCC allows you to define a syntax for a language. In our usage of
it, we have an application which allows users to include what we call
"expression language" statements. JavaCC was used to define the syntax
and generate base code for all the various statement types. We then had
to fill in the internals of many of the resulting classes, and add some
code to others. But it's not for the faint of heart...
More generally, you're going to have to write a parser. You can do it by
hand, or use a parser generator like JavaCC or ANTLR. You might want to read
newsgroup.