2016-12-05 22:15:40 +01:00
;Task:
Given the operator characteristics and input from the [[wp:Shunting-yard_algorithm|Shunting-yard algorithm]] page and tables, use the algorithm to show the changes in the operator stack and RPN output
2013-04-10 23:57:08 -07:00
as each individual token is processed.
* Assume an input of a correct, space separated, string of tokens representing an infix expression
* Generate a space separated output string representing the RPN
2016-12-05 22:15:40 +01:00
* Test with the input string:
:::: <big><big><code> 3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3 </code></big></big>
* print and display the output here.
2013-04-10 23:57:08 -07:00
* Operator precedence is given in this table:
:{| class="wikitable"
2016-12-05 22:15:40 +01:00
! operator !! [[wp:Order_of_operations|precedence]] !! [[wp:Operator_associativity|associativity]] !! operation
2013-04-10 23:57:08 -07:00
|- || align="center"
2016-12-05 22:15:40 +01:00
| <big><big> ^ </big></big> || 4 || right || exponentiation
2013-04-10 23:57:08 -07:00
|- || align="center"
2016-12-05 22:15:40 +01:00
| <big><big> * </big></big> || 3 || left || multiplication
2013-04-10 23:57:08 -07:00
|- || align="center"
2016-12-05 22:15:40 +01:00
| <big><big> / </big></big> || 3 || left || division
2013-04-10 23:57:08 -07:00
|- || align="center"
2016-12-05 22:15:40 +01:00
| <big><big> + </big></big> || 2 || left || addition
2013-04-10 23:57:08 -07:00
|- || align="center"
2016-12-05 22:15:40 +01:00
| <big><big> - </big></big> || 2 || left || subtraction
2013-04-10 23:57:08 -07:00
|}
2016-12-05 22:15:40 +01:00
<br>
;Extra credit
Add extra text explaining the actions and an optional comment for the action on receipt of each token.
;Note
The handling of functions and arguments is not required.
2013-04-10 23:57:08 -07:00
;See also:
* [[Parsing/RPN calculator algorithm]] for a method of calculating a final value from this output RPN expression.
* [[Parsing/RPN to infix conversion]].
2016-12-05 22:15:40 +01:00
<br><br>