AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Syntax checker

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
dhanya
Guest





PostPosted: Fri Dec 22, 2006 4:07 pm    Post subject: Syntax checker Reply with quote



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=20. 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.

Thanks in advance,
Dhanya
Back to top
Steve W. Jackson
Guest





PostPosted: Fri Dec 22, 2006 9:31 pm    Post subject: Re: Syntax checker Reply with quote



In article <1166782060.023296.203420 (AT) h40g2000cwb (DOT) googlegroups.com>,
"dhanya" <dhanya.aishwarya (AT) gmail (DOT) com> wrote:

Quote:
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=20. 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.

Thanks in advance,
Dhanya

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...

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
Back to top
Oliver Wong
Guest





PostPosted: Fri Dec 22, 2006 9:54 pm    Post subject: Re: Syntax checker Reply with quote



"Steve W. Jackson" <stevewjackson (AT) knology (DOT) net> wrote in message
news:stevewjackson-C9235E.09310922122006 (AT) individual (DOT) net...
Quote:
In article <1166782060.023296.203420 (AT) h40g2000cwb (DOT) googlegroups.com>,
"dhanya" <dhanya.aishwarya (AT) gmail (DOT) 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=20. 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
up on compiler theory, and maybe ask for advice in the comp.compilers
newsgroup.

- Oliver
Back to top
Hemal Pandya
Guest





PostPosted: Sat Dec 23, 2006 12:14 am    Post subject: Re: Syntax checker Reply with quote

dhanya wrote:
Quote:
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=20. 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.

Thanks in advance,
Dhanya

Other posters have already described one approach, of writing a
parser. If you take this approach, my advice is to keep the language
simple. Also look at ANTLR besides JavaCC, I have used ANTLR in past
for very similar functionality (allowing users to extend) and was quite
happy with it.

A couple other approaches that may be suitable:

1. Define a Java interface that the user has to implement. You can
compile there java code using javac (or the compiler api), load the
class dynamically, instantiate an object and call some method(s) on it.
This is on the lines of plug-in architecture.

2. Embed a javascript engine. I think Java 6 already does this. Can the
functionality the user has to provide be implemented in javascript?
Back to top
dhanya
Guest





PostPosted: Tue Dec 26, 2006 8:10 am    Post subject: Re: Syntax checker Reply with quote

Hemal Pandya wrote:
Quote:
dhanya 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=20. 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.

Thanks in advance,
Dhanya

Other posters have already described one approach, of writing a
parser. If you take this approach, my advice is to keep the language
simple. Also look at ANTLR besides JavaCC, I have used ANTLR in past
for very similar functionality (allowing users to extend) and was quite
happy with it.

A couple other approaches that may be suitable:

1. Define a Java interface that the user has to implement. You can
compile there java code using javac (or the compiler api), load the
class dynamically, instantiate an object and call some method(s) on it.
This is on the lines of plug-in architecture.

2. Embed a javascript engine. I think Java 6 already does this. Can the
functionality the user has to provide be implemented in javascript?

Thank You all, for your replies. I have some few doubts. I have
designed a JSP Page as an UI for the user to enter formulas. If the
user enters a formula like if(price>localPrice) then price=10 else
price = 20.
1) When should i check this line for errors? Like it should be done
before saving this formula or while entering itself?
2) Also can i save these in the database itself? If yes what should i
do to retreive and convert to java code, as placing braces "{" properly
etc.

This is not a class room assignment. Pls help me in this.
Back to top
Oliver Wong
Guest





PostPosted: Wed Dec 27, 2006 11:18 pm    Post subject: Re: Syntax checker Reply with quote

"dhanya" <dhanya.aishwarya (AT) gmail (DOT) com> wrote in message
news:1167112191.245821.21350 (AT) 42g2000cwt (DOT) googlegroups.com...
Quote:

I have
designed a JSP Page as an UI for the user to enter formulas. If the
user enters a formula like if(price>localPrice) then price=10 else
price = 20.
1) When should i check this line for errors? Like it should be done
before saving this formula or while entering itself?

You can do it either way, but writing a parser which can assyne the
input is complete is easier.

Quote:
2) Also can i save these in the database itself?

Any information which you can represent on a computer can be saved in a
DB, if only as a binary stream.

Quote:
If yes what should i
do to retreive and convert to java code, as placing braces "{" properly
etc.

This is the first time I see you stating your intent to convert the
formula to Java. Doing this would require writing a full blown compiler. As
I mentioned earlier, ask on comp.compilers.

- Oliver
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.