Results 1 to 4 of 4
Thread: Help with postfix expression
- 11-12-2010, 08:10 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 1
- Rep Power
- 0
Help with postfix expression
I have a question about postfix expressions. Is there a way to tell if the expression is a valid postfix expression without actually evaluating it? For example, the expression 12+345+** is a valid postfix expression but 12+345+*** is not. If someone could help shed some light i'd appreciate it!
- 11-12-2010, 08:41 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,386
- Blog Entries
- 7
- Rep Power
- 17
Scan the expression (string) from left to right and keep track of a counter. If you have scanned an operand add one to the counter; if you have scanned an operator subtract the arity of the operator from the counter and add one to it again. If the counter reaches a value below one the expression is invalid. If the counter isn't one after you have scanned the entire expression, it is also invalid.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-12-2010, 10:47 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Basically it's the combination evaluation of operands and operators.
Scan the expression from left to right, each character at a time. If the scanned character is operand then move to the next. While the next is an operator proceed. Say you've comes with an operator, then there should be atleast two operands of the left. This is the continuous pattern to check.
- 11-12-2010, 11:11 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,386
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Infix to Postfix using array
By Franneldort in forum New To JavaReplies: 0Last Post: 10-11-2010, 05:57 PM -
Postfix this!!
By hasysf in forum New To JavaReplies: 4Last Post: 09-07-2009, 06:44 PM -
Postfix into prefix and vice versa
By sfe23 in forum New To JavaReplies: 9Last Post: 02-19-2009, 10:37 PM -
Postfix Evaluation using a Stack, Help?
By dalangley in forum New To JavaReplies: 2Last Post: 02-16-2009, 10:43 PM -
Postfix-Notation
By little_polarbear in forum New To JavaReplies: 9Last Post: 09-09-2008, 04:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks