Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,398 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,102 people online right now. Registration is fast and FREE... Join Now!




C++ method that will parse an expression

 
Reply to this topicStart new topic

C++ method that will parse an expression, expression parsing

nano72
15 Sep, 2006 - 12:26 AM
Post #1

New D.I.C Head
*

Joined: 6 Sep, 2006
Posts: 19


My Contributions
Hi guys ,

Anyone out there have a neat way to parse an arithmetic expression

It could be like command line expr ( A * B ) / 2
Now I have the Arithmetic methods written that is multiple and add

but need a neat way to parse the expression to pass the values into the Arithmetic methods ...

Any ideas out there .
all ideas appreciated
Thanks

This post has been edited by nano72: 15 Sep, 2006 - 12:29 AM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: C++ Method That Will Parse An Expression
15 Sep, 2006 - 05:17 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Sorry to ask, but are you looking for help in creating such a parser, or do you want an exisiting one?
User is offlineProfile CardPM
+Quote Post

nano72
RE: C++ Method That Will Parse An Expression
15 Sep, 2006 - 08:32 AM
Post #3

New D.I.C Head
*

Joined: 6 Sep, 2006
Posts: 19


My Contributions
QUOTE(Amadeus @ 15 Sep, 2006 - 06:17 AM) *

Sorry to ask, but are you looking for help in creating such a parser, or do you want an exisiting one?


Well if there is a simple and neat one out there I would be grateful to integrate into my code .

what i have is the string been passed in for eg (vala* valb) / vala
need to parse it out taking into account precedence

the multiply and division methods are written

thanks
User is offlineProfile CardPM
+Quote Post

Videege
RE: C++ Method That Will Parse An Expression
15 Sep, 2006 - 09:08 AM
Post #4

rêvant.toujours
Group Icon

Joined: 25 Mar, 2003
Posts: 1,406


Dream Kudos: 150
My Contributions
A sometimes not so simple way to do it is simply to write a parser that functions within a while loop, incrementing one character at a time and doing different things depending on the character; this usually involves a bunch of boolean switches and whatnot.

Another nifty way to do it is to construct a binary tree of expressions and parse the equation like an HP calculator does it. Check out an article describing this right here.
User is offlineProfile CardPM
+Quote Post

nano72
RE: C++ Method That Will Parse An Expression
20 Sep, 2006 - 12:43 AM
Post #5

New D.I.C Head
*

Joined: 6 Sep, 2006
Posts: 19


My Contributions
QUOTE(Videege @ 15 Sep, 2006 - 10:08 AM) *

A sometimes not so simple way to do it is simply to write a parser that functions within a while loop, incrementing one character at a time and doing different things depending on the character; this usually involves a bunch of boolean switches and whatnot.

Another nifty way to do it is to construct a binary tree of expressions and parse the equation like an HP calculator does it. Check out an article describing this right here.


Thanks for that -Is there any code that supports this so that i can integrate it into my program ?????????
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 03:06AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month