By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

parsing tree

P: 27
hi

i need help with this program:
input: x=y+z*5

output:
x ---> identifier
= ---> equal operator
y ---> identifier
+ ---> Plus operator
z ---> identifier
* ---> Multiply operator
5 ---> constant

thats complete example and i believe its better than long explanation
so how can i do it?
Mar 16 '07 #1
Share this Question
Share on Google+
4 Replies


RedSon
Expert 5K+
P: 5,000
hi

i need help with this program:
input: x=y+z*5

output:
x ---> identifier
= ---> equal operator
y ---> identifier
+ ---> Plus operator
z ---> identifier
* ---> Multiply operator
5 ---> constant

thats complete example and i believe its better than long explanation
so how can i do it?
Looks like this assignment is a precursor to an infix to postfix calculator. A good strategy to go by this is to read in one character. Then compare that character to a list of known characters and once you identify that character then add it to a collection either identifier, operator, or constant.
Mar 16 '07 #2

P: 27
shall i compare each character with all possible cases?!!
like if i have 'a', then ts should be compared to all letters, numbers and operators?!!
im sure its not that way, but dont no how
Mar 16 '07 #3

RedSon
Expert 5K+
P: 5,000
shall i compare each character with all possible cases?!!
like if i have 'a', then ts should be compared to all letters, numbers and operators?!!
im sure its not that way, but dont no how
Thats one way to do it, but can you think of another way that might be easier. Out of all the possible sets of letters, numbers and operators, which sets are going to have less members in them? Wouldn't it be safe to check characters against these smaller sets and then if they do not match any of the smaller sets, assume that they are part of the larger set?
Mar 16 '07 #4

P: 27
well i got it
i'll use ascii code to check the input, then put it into the appropriate array accordingly. now i only need the syntax of using ASCII code.
thnx for help.
Mar 16 '07 #5

Post your reply

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