Click here to Skip to main content
14,975,411 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi...
I want to create a formula parser which can parse formulas similar to the ones created in Excel...
for example formula like...
If(Condition(s),ValueIfTrue,ValuIfFalse)

can anyone please tell me if I can get such a parser....
Posted

You can avoid creating your own parser. You can use the one already available as a C# or VB.NET compiler, which are the part of Framework redistributable and are always available via CodeDOM.

Here is how to do it:
code generating using CodeDom[^];
See also:
Create WPF Application that uses Reloadable Plugins...[^].

—SA
   
v2
Comments
Nuri Ismail 7-Apr-11 6:02am
   
Good advice. My 5.
And your linked answers, I wish I could give more than 5 for them. :)
   
Do you means you voted 5 three times? This is more then enough :-)
Thank you, Nuri.
--SA
Nuri Ismail 7-Apr-11 6:16am
   
Yes I 5-ed the linked answers, too. But IMHO, your efforts deserve more... :)
   
Thank you. You not gonna believe that, but I just answered another Question about using CodeDOM and dynamically compiled Assembly with even more tricky (and crazy, of course) requirements.

This is most funny:
http://www.codeproject.com/Answers/178490/how-to-get-the-text-of-a-label-using-codedom.aspx

I suspect the patient has no idea where she or he is trying to get into. Hope my answer can be sobering, no more. I can't believe that new OP would be able to write anything working in any observable period of time. And the purpose of it hardly can justify such work.

Take a look, this is really funny.

--SA
Nuri Ismail 8-Apr-11 5:49am
   
This sounds very interesting. I'll check out your answer right now. :)
   
Amrita,

Please understand that my absolute skepticism about the work of the other Inquirer commented above has nothing to do with your work. In contrast to that crazy (but probably somehow interesting) Question, your work is quite realistic and makes full sense.

You purpose is probably compiling and running some calculation. Doing it with CodeDOM is quite feasible and has one big benefit: instead of inventing and processing your own syntax and language rules you use something available, robust and well tested. It can justify your effort.

--SA
walterhevedeich 7-Apr-11 21:49pm
   
Good point. voted 5.
   
Thank you.
--SA
This article could be interesting for you: Evaluation Engine[^]
   
Comments
walterhevedeich 7-Apr-11 21:49pm
   
Good point. voted 5.
Wendelius 8-Apr-11 1:24am
   
Thank you :)
Have also a look at Simple Math Parser[^].
:-)
   
Comments
walterhevedeich 7-Apr-11 21:49pm
   
Good point. voted 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900