Solved

Creating a Formula Parser that can work with Dates, Strings, and Numbers

Posted on 2004-08-16
6
236 Views
Last Modified: 2013-11-18
Hi all,

i am puzzled with a problem that came up in my application. I have built an application that shows a list of Data Items (lets assume it would be Tasks for a project) in an Excel style manner, in a HTML form. The display which tasks are actually shown to the user is configurable by the user by the means of a formula. There currently exists code to enter a simple formula like "status=open" - where the application will filter the list of tasks based on the value contained in the status field of the individual tasks. In the example, it would only show tasks that have the value "open" set.

I would like to make this system much more flexible now. I support a few different types of data, most noteworthy dd.mm.yyyy date formats, integers, and Strings. What i would like to create is a system that allows me to create arbitray formulas that will decide whether an Item will be shown or not. For this, I though about creating something like this:

1) the system would still decide on the basis of field<operator>condition --- where operator can be one of ==,~=,!=,<,>,<=,>=
2) first, the system should look for so-called macros -- basically placeholders for values provided by the system --- e.g. today() would evaluate to 16.08.2004 or title() would yield the current items title --- lets assume there is a working set of these macros available.
3) the condition field should be able to notice when it finds a date, and apply further math to the field based on date processing logic -- for example: enddate<22.12.2004+2 would show all items that have end dates smaller than 24.12.2004
4) if no dates are found the system should try to create an integer result out of the formula , e.g. "completeinpercent>32+18" would match all items with the completeinprecent field set to 51 and higher
5) if it all fails, concatenate the strings and compare to the field value -- e.g. title=="Hello"+3+"World" would match the "Hello3World" titled items only
6)Finally, if all of this fails, it should error out.

The tricky bit on this for me is how to implement the parser in a flexible enough way to handle the comparisons of different kinds of data, while being open to formulas with several elements, maybe only noticing the final return data type in the last step. For example, the formula 2+3+"bar" only knows its going to return "23bar" on encounter of the last string as per the rules above.

I am REALLY curious if someone can help me find a good, flexible solution path for this. I will not need a fully fledged implementation, only a hint how this is to be done properly and open to future expansion for more different types of data.

Thanks
Emanuel Schleussinger
0
Comment
Question by:tubooboo
6 Comments
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 300 total points
ID: 11815113
I suggest you to use Java Expression parser which is an open source

http://www.3plus4software.de/downloads/index.html

Best regards
Sudhakar
0
 

Author Comment

by:tubooboo
ID: 11815265
Thanks for that - however i think that one is overkill for the expressions i need covered. Basically, all i need is support for + - * and /

The actual problem i need solved is more how to create a parser that ll decide what comparison rules to apply based on the individual tokens presented (Dates, Strings, numbers)

Thanks
Emanuel
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 200 total points
ID: 11818060
Can you not indicate somehow what type of tokens they are? I guess you will have some rules to identify placeholders, for example by using the # symbol (e.g. #today()#) or something like that. You might as well indicate what data type the placeholder will hold by using a (lets say) letter, for instance #d-today()# will indicate that the today() should be a date. Similarly for the rest of the placeholders, use s for strings and n for numbers. But I also believe you use one of the already existing imnplementations, at least -if they do not satisfy your needs- try to extend one of them (most of them are open-source). There is no need to reinvent the wheel.
0
 
LVL 20

Expert Comment

by:Venabili
ID: 11851298
Thanks for closing this question

Venabili
0
 
LVL 35

Expert Comment

by:girionis
ID: 11851519
:)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 62
GUI builder for Eclipse? 8 27
Powershell Script need assistance to make some changes 4 58
Arrays.asList  VS  ArrayList 4 43
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now