473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Expression Tree

1
I have written an expression tree (binary tree) that works so that it gives priority to brackets.

However I need to add the functionality of BODMAS to the making of the tree. How would I do this so it can solve expressions such as :

1 + ((4 -2)*3)*3

I though about putting brackets around the times and divide parts of an expression so that it would do those bits first. Though this isn't the best way as it would not give precedence of divide over times, or precedence of add over subtract (although in a lot of cases this would not have an effect on the result)

I would like to point out that this is coursework, so the theory behind what I need to do would be brilliant.

Thanks
Dec 21 '07 #1
2 2540
BigDaddyLH
1,216 Expert 1GB
It's not clear to me what your question is. Is your question: "how do I parse strings into expression trees?"

Note, by the way, despite the order of letters in "BODMAS", + and - are normally given the same precedence, and * and / are normally given the same precedence, too. Are you certain your assignment gives then differing precedence?
Dec 21 '07 #2
JosAH
11,448 Expert 8TB
In the Java 'howto' section I talk a bit about compilers and a bit about recursive
descent parsers; they can handle those expressions perfectly well.

If you can still find it: the book "data structures" by Horrowitz and Sahni (sorry,
no ISBN, I'm not at my office room) explains a simple non-recursive stack algorithm
that maps an operator to two different priorities: an in-stack and on-stack priority
that tells the algorithm when to push/pop operator elements from that stack.

kind regards,

Jos
Dec 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: KidLogik | last post by:
Hello! I am converting an infix expression string into a postfix so that I will be able to evaluate it easier -> (5*(((9+8)*(4*6))+7)) == 598+46**7+* I believe the rule is "Replace all...
22
by: Tony Johansson | last post by:
Hello Experts! I'm reading i a book about C++ and they mention infix with telling what it is. I hope you out there can do so. Many thanks! //Tony
6
by: david | last post by:
For example, I can call <xsl:value-of select="concat('name','(',value,')')"/>, is there anyway I can pass the expression concat('name','(',value,')') as a variable from outside the template? ...
4
by: ad | last post by:
We can use RegularExpressionValidator to valid the input of TextBox. Can we use RegularExpression to valid a string in run time? Like I have a regular expression "\d{3}" Can I use this regular...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
15
by: Matt | last post by:
Hi There, Can anyone explain me the real advantages of (other than syntax) lambda expressions over anonymous delegates? advantage for one over the other. delegate int F(int a); F fLambda = a...
16
by: rowe_newsgroups | last post by:
Ok, I'm tired and I'm sure I know the answer to this, but I can't seem to come up with it right now. What is the VB.NET equivalent to the following C# code? /////////////...
56
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.