<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Shunting_yard_algorithm</id>
	<title>Shunting yard algorithm - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Shunting_yard_algorithm"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Shunting_yard_algorithm&amp;action=history"/>
	<updated>2026-05-09T20:09:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Shunting_yard_algorithm&amp;diff=2075040&amp;oldid=prev</id>
		<title>imported&gt;Dgpop: /* top */ phrasing</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Shunting_yard_algorithm&amp;diff=2075040&amp;oldid=prev"/>
		<updated>2025-06-23T15:22:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;top: &lt;/span&gt; phrasing&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Previous revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:22, 23 June 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l10&quot;&gt;Line 10:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 10:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In [[computer science]], the &#039;&#039;&#039;shunting yard algorithm&#039;&#039;&#039; is a method for parsing arithmetical or logical expressions, or a combination of both, specified in [[infix notation]]. It can produce either a postfix notation string, also known as [[reverse Polish notation]] (RPN), or an [[abstract syntax tree]] (AST).&amp;lt;ref&amp;gt;{{cite web|access-date=2020-12-28|title=Parsing Expressions by Recursive Descent|url=http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm|website=www.engr.mun.ca|author=Theodore Norvell|date=1999}}&amp;lt;/ref&amp;gt; The [[algorithm]] was invented by [[Edsger Dijkstra]], first published in November 1961,&amp;lt;ref&amp;gt;{{Cite journal |last=Dijkstra |first=Edsger |date=1961-11-01 |title=Algol 60 translation : An Algol 60 translator for the X1 and making a translator for Algol 60 |url=https://ir.cwi.nl/pub/9251 |language=en |journal=Stichting Mathematisch Centrum}}&amp;lt;/ref&amp;gt; and named &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the &quot;shunting yard&quot; algorithm &lt;/del&gt;because its operation resembles that of a [[classification yard|railroad shunting yard]].&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In [[computer science]], the &#039;&#039;&#039;shunting yard algorithm&#039;&#039;&#039; is a method for parsing arithmetical or logical expressions, or a combination of both, specified in [[infix notation]]. It can produce either a postfix notation string, also known as [[reverse Polish notation]] (RPN), or an [[abstract syntax tree]] (AST).&amp;lt;ref&amp;gt;{{cite web|access-date=2020-12-28|title=Parsing Expressions by Recursive Descent|url=http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm|website=www.engr.mun.ca|author=Theodore Norvell|date=1999}}&amp;lt;/ref&amp;gt; The [[algorithm]] was invented by [[Edsger Dijkstra]], first published in November 1961,&amp;lt;ref&amp;gt;{{Cite journal |last=Dijkstra |first=Edsger |date=1961-11-01 |title=Algol 60 translation : An Algol 60 translator for the X1 and making a translator for Algol 60 |url=https://ir.cwi.nl/pub/9251 |language=en |journal=Stichting Mathematisch Centrum}}&amp;lt;/ref&amp;gt; and named because its operation resembles that of a [[classification yard|railroad shunting yard]].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Like the evaluation of RPN, the shunting yard algorithm is [[stack (data structure)|stack]]-based. Infix expressions are the form of mathematical notation most people are used to, for instance {{nowrap|&amp;quot;3 + 4&amp;quot;}} or {{nowrap|&amp;quot;3 + 4 × (2 − 1)&amp;quot;}}. For the conversion there are two text [[Variable (programming)|variables]] ([[string (computer science)|strings]]), the input and the output. There is also a [[stack (data structure)|stack]] that holds operators not yet added to the output queue. To convert, the program reads each symbol in order and does something based on that symbol. The result for the above examples would be (in [[reverse Polish notation]]) {{nowrap|&amp;quot;3 4 +&amp;quot;}} and {{nowrap|&amp;quot;3 4 2 1 − × +&amp;quot;}}, respectively.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Like the evaluation of RPN, the shunting yard algorithm is [[stack (data structure)|stack]]-based. Infix expressions are the form of mathematical notation most people are used to, for instance {{nowrap|&amp;quot;3 + 4&amp;quot;}} or {{nowrap|&amp;quot;3 + 4 × (2 − 1)&amp;quot;}}. For the conversion there are two text [[Variable (programming)|variables]] ([[string (computer science)|strings]]), the input and the output. There is also a [[stack (data structure)|stack]] that holds operators not yet added to the output queue. To convert, the program reads each symbol in order and does something based on that symbol. The result for the above examples would be (in [[reverse Polish notation]]) {{nowrap|&amp;quot;3 4 +&amp;quot;}} and {{nowrap|&amp;quot;3 4 2 1 − × +&amp;quot;}}, respectively.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>imported&gt;Dgpop</name></author>
	</entry>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Shunting_yard_algorithm&amp;diff=1887688&amp;oldid=prev</id>
		<title>imported&gt;Scrooge Mcduc: /* The algorithm in detail */</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Shunting_yard_algorithm&amp;diff=1887688&amp;oldid=prev"/>
		<updated>2025-02-22T15:19:56Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;The algorithm in detail&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Algorithm to parse a syntax with infix notation to postfix notation}}&lt;br /&gt;
{{More footnotes|date=August 2013}}&lt;br /&gt;
&lt;br /&gt;
{{Infobox algorithm&lt;br /&gt;
|name={{PAGENAMEBASE}}&lt;br /&gt;
|class=[[Parsing]]&lt;br /&gt;
|data=[[Stack (abstract data type)|Stack]]&lt;br /&gt;
|time=&amp;lt;math&amp;gt;O(n)&amp;lt;/math&amp;gt;&lt;br /&gt;
|space=&amp;lt;math&amp;gt;O(n)&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
In [[computer science]], the &amp;#039;&amp;#039;&amp;#039;shunting yard algorithm&amp;#039;&amp;#039;&amp;#039; is a method for parsing arithmetical or logical expressions, or a combination of both, specified in [[infix notation]]. It can produce either a postfix notation string, also known as [[reverse Polish notation]] (RPN), or an [[abstract syntax tree]] (AST).&amp;lt;ref&amp;gt;{{cite web|access-date=2020-12-28|title=Parsing Expressions by Recursive Descent|url=http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm|website=www.engr.mun.ca|author=Theodore Norvell|date=1999}}&amp;lt;/ref&amp;gt; The [[algorithm]] was invented by [[Edsger Dijkstra]], first published in November 1961,&amp;lt;ref&amp;gt;{{Cite journal |last=Dijkstra |first=Edsger |date=1961-11-01 |title=Algol 60 translation : An Algol 60 translator for the X1 and making a translator for Algol 60 |url=https://ir.cwi.nl/pub/9251 |language=en |journal=Stichting Mathematisch Centrum}}&amp;lt;/ref&amp;gt; and named the &amp;quot;shunting yard&amp;quot; algorithm because its operation resembles that of a [[classification yard|railroad shunting yard]].&lt;br /&gt;
&lt;br /&gt;
Like the evaluation of RPN, the shunting yard algorithm is [[stack (data structure)|stack]]-based. Infix expressions are the form of mathematical notation most people are used to, for instance {{nowrap|&amp;quot;3 + 4&amp;quot;}} or {{nowrap|&amp;quot;3 + 4 × (2 − 1)&amp;quot;}}. For the conversion there are two text [[Variable (programming)|variables]] ([[string (computer science)|strings]]), the input and the output. There is also a [[stack (data structure)|stack]] that holds operators not yet added to the output queue. To convert, the program reads each symbol in order and does something based on that symbol. The result for the above examples would be (in [[reverse Polish notation]]) {{nowrap|&amp;quot;3 4 +&amp;quot;}} and {{nowrap|&amp;quot;3 4 2 1 − × +&amp;quot;}}, respectively.&lt;br /&gt;
&lt;br /&gt;
The shunting yard algorithm will correctly parse all valid infix expressions, but does not reject all invalid expressions. For example, {{nowrap|&amp;quot;1 2 +&amp;quot;}} is not a valid infix expression, but would be parsed as {{nowrap|&amp;quot;1 + 2&amp;quot;}}. The algorithm can however reject expressions with mismatched parentheses.&lt;br /&gt;
&lt;br /&gt;
The shunting yard algorithm was later generalized into [[Operator-precedence parser|operator-precedence parsing]].&lt;br /&gt;
&lt;br /&gt;
==A simple conversion==&lt;br /&gt;
&lt;br /&gt;
#Input: {{nowrap|3 + 4}}&lt;br /&gt;
#Push 3 to the output [[Queue (data structure)|queue]] (whenever a number is read it is pushed to the output)&lt;br /&gt;
#[[Stack (data structure)#Basic architecture of a stack|Push]] + (or its ID) onto the operator [[stack (data structure)|stack]]&lt;br /&gt;
#Push 4 to the output queue&lt;br /&gt;
#After reading the expression, [[stack (data structure)#Basic architecture of a stack|pop]] the operators off the stack and add them to the output. &lt;br /&gt;
#:In this case there is only one, &amp;quot;+&amp;quot;.&lt;br /&gt;
#Output: {{nowrap|3 4 +}}&lt;br /&gt;
&lt;br /&gt;
This already shows a couple of rules:&lt;br /&gt;
* All numbers are pushed to the output when they are read.&lt;br /&gt;
* At the end of reading the expression, pop all operators off the stack and onto the output.&lt;br /&gt;
&lt;br /&gt;
==Graphical illustration==&lt;br /&gt;
&lt;br /&gt;
[[File:Shunting yard.svg|frameless|border|center|500px|]]&lt;br /&gt;
Graphical illustration of algorithm, using a [[wye junction|three-way railroad junction]]. The input is processed one symbol at a time: if a variable or number is found, it is copied directly to the output a), c), e), h). If the symbol is an operator, it is pushed onto the operator stack b), d), f). If the operator&amp;#039;s precedence is lower than that of the operators at the top of the stack or the precedences are equal and the operator is left associative, then that operator is popped off the stack and added to the output g). Finally, any remaining operators are popped off the stack and added to the output i).&lt;br /&gt;
&lt;br /&gt;
==The algorithm in detail==&lt;br /&gt;
&lt;br /&gt;
{{for|important terms|token (parser)|function (mathematics)|Operator associativity|Order of operations}}&lt;br /&gt;
&lt;br /&gt;
 {{font color|blue|/* The functions referred to in this algorithm are simple single argument functions such as sine, inverse or factorial. */}}&lt;br /&gt;
 {{font color|blue|/* This implementation does not implement composite functions, functions with a variable number of arguments, or unary operators. */}}&lt;br /&gt;
 &lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;while&amp;#039;&amp;#039;&amp;#039; there are [[token (parser)|token]]s to be read:&lt;br /&gt;
     read a token&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; the token is:&lt;br /&gt;
     - a &amp;#039;&amp;#039;number&amp;#039;&amp;#039;:&lt;br /&gt;
         put it into the output queue&lt;br /&gt;
     - a &amp;#039;&amp;#039;[[function (mathematics)|function]]&amp;#039;&amp;#039;:&lt;br /&gt;
         push it onto the operator stack &lt;br /&gt;
     - an &amp;#039;&amp;#039;operator&amp;#039;&amp;#039; &amp;#039;&amp;#039;o&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt;:&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;while&amp;#039;&amp;#039;&amp;#039; (&lt;br /&gt;
             there is an operator &amp;#039;&amp;#039;o&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; at the top of the operator stack which is not a left parenthesis, &lt;br /&gt;
             &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; (&amp;#039;&amp;#039;o&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; has greater [[Order of operations|precedence]] than &amp;#039;&amp;#039;o&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; (&amp;#039;&amp;#039;o&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; and &amp;#039;&amp;#039;o&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; have the same precedence &amp;#039;&amp;#039;&amp;#039;and&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;o&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; is left-associative))&lt;br /&gt;
         ):&lt;br /&gt;
             pop &amp;#039;&amp;#039;o&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; from the operator stack into the output queue&lt;br /&gt;
         push &amp;#039;&amp;#039;o&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; onto the operator stack&lt;br /&gt;
     - a &amp;#039;&amp;#039;&amp;quot;,&amp;quot;&amp;#039;&amp;#039;:&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;while&amp;#039;&amp;#039;&amp;#039; the operator at the top of the operator stack is not a left parenthesis:&lt;br /&gt;
              pop the operator from the operator stack into the output queue&lt;br /&gt;
     - a &amp;#039;&amp;#039;left parenthesis&amp;#039;&amp;#039; (i.e. &amp;quot;(&amp;quot;):&lt;br /&gt;
         push it onto the operator stack&lt;br /&gt;
     - a &amp;#039;&amp;#039;right parenthesis&amp;#039;&amp;#039; (i.e. &amp;quot;)&amp;quot;):&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;while&amp;#039;&amp;#039;&amp;#039; the operator at the top of the operator stack is not a left parenthesis:&lt;br /&gt;
             {&amp;#039;&amp;#039;&amp;#039;assert&amp;#039;&amp;#039;&amp;#039; the operator stack is not empty}&lt;br /&gt;
             {{font color|blue|/* If the stack runs out without finding a left parenthesis, then there are mismatched parentheses. */}}&lt;br /&gt;
             pop the operator from the operator stack into the output queue&lt;br /&gt;
         {&amp;#039;&amp;#039;&amp;#039;assert&amp;#039;&amp;#039;&amp;#039; there is a left parenthesis at the top of the operator stack}&lt;br /&gt;
         pop the left parenthesis from the operator stack and discard it&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; there is a function token at the top of the operator stack, &amp;#039;&amp;#039;&amp;#039;then&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
             pop the function from the operator stack into the output queue&lt;br /&gt;
 {{font color|blue|/* After the while loop, pop the remaining items from the operator stack into the output queue. */}}&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;while&amp;#039;&amp;#039;&amp;#039; there are tokens on the operator stack:&lt;br /&gt;
     {{font color|blue|/* If the operator token on the top of the stack is a parenthesis, then there are mismatched parentheses. */}}&lt;br /&gt;
     {&amp;#039;&amp;#039;&amp;#039;assert&amp;#039;&amp;#039;&amp;#039; the operator on top of the stack is not a (left) parenthesis}&lt;br /&gt;
     pop the operator from the operator stack onto the output queue&lt;br /&gt;
&lt;br /&gt;
To analyze the running time complexity of this algorithm, one has only to note that each token will be read once, each number, function, or operator will be printed once, and each function, operator, or parenthesis will be pushed onto the stack and popped off the stack once—therefore, there are at most a constant number of operations executed per token, and the running time is thus O(&amp;#039;&amp;#039;n&amp;#039;&amp;#039;) — linear in the size of the input.&lt;br /&gt;
&lt;br /&gt;
The shunting yard algorithm can also be applied to produce prefix notation (also known as [[Polish notation]]). To do this one would simply start from the end of a string of tokens to be parsed and work backwards, reverse the output queue (therefore making the output queue an output stack), and flip the left and right parenthesis behavior (remembering that the now-left parenthesis behavior should pop until it finds a now-right parenthesis), while making sure to change the [[Operator associativity|associativity]] condition to right.&lt;br /&gt;
&lt;br /&gt;
==Detailed examples==&lt;br /&gt;
Input: {{nowrap|3 + 4 × 2 ÷ ( 1 − 5 ) ^ 2 ^ 3}}&lt;br /&gt;
&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Operator !! Precedence !! Associativity&lt;br /&gt;
|- || align=&amp;quot;center&amp;quot;&lt;br /&gt;
| ^ || 4 || Right &lt;br /&gt;
|- || align=&amp;quot;center&amp;quot;&lt;br /&gt;
| × || 3 || Left&lt;br /&gt;
|- || align=&amp;quot;center&amp;quot;&lt;br /&gt;
| ÷ || 3 || Left&lt;br /&gt;
|- || align=&amp;quot;center&amp;quot;&lt;br /&gt;
| + || 2 || Left&lt;br /&gt;
|- || align=&amp;quot;center&amp;quot;&lt;br /&gt;
| − || 2 || Left&lt;br /&gt;
|}&lt;br /&gt;
The symbol ^ represents the [[exponentiation|power operator]].&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Token !! Action !! Output&amp;lt;br&amp;gt;(in [[Reverse Polish Notation|RPN]]) !! Operator&amp;lt;br&amp;gt;stack !! Notes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || Add token to output || 3 || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | + || Push token to stack || 3 || align=&amp;quot;right&amp;quot; | + ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || Add token to output || 3 4 || align=&amp;quot;right&amp;quot; | + ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | × || Push token to stack || 3 4 || align=&amp;quot;right&amp;quot; | × + || × has higher precedence than +&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || Add token to output || 3 4 2 || align=&amp;quot;right&amp;quot; | × + ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; rowspan=&amp;quot;2&amp;quot; | ÷ || Pop stack to output || 3 4 2 × || align=&amp;quot;right&amp;quot; | + || ÷ and × have same precedence&lt;br /&gt;
|-&lt;br /&gt;
| Push token to stack || 3 4 2 × || align=&amp;quot;right&amp;quot; | ÷ + || ÷ has higher precedence than +&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ( || Push token to stack || 3 4 2 × || align=&amp;quot;right&amp;quot; | ( ÷ + ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || Add token to output || 3 4 2 × 1 || align=&amp;quot;right&amp;quot; | ( ÷ + ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | − || Push token to stack || 3 4 2 × 1 || align=&amp;quot;right&amp;quot; | − ( ÷ + ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || Add token to output || 3 4 2 × 1 5 || align=&amp;quot;right&amp;quot; | − ( ÷ + ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; rowspan=&amp;quot;2&amp;quot; | ) || Pop stack to output || 3 4 2 × 1 5 − || align=&amp;quot;right&amp;quot; | ( ÷ + || Repeated until &amp;quot;(&amp;quot; found&lt;br /&gt;
|-&lt;br /&gt;
| Pop stack || 3 4 2 × 1 5 − || align=&amp;quot;right&amp;quot; | ÷ + || Discard matching parenthesis&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ^ || Push token to stack || 3 4 2 × 1 5 − || align=&amp;quot;right&amp;quot; | ^ ÷ + || ^ has higher precedence than ÷&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || Add token to output || 3 4 2 × 1 5 − 2 || align=&amp;quot;right&amp;quot; | ^ ÷ + ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ^ || Push token to stack || 3 4 2 × 1 5 − 2 || align=&amp;quot;right&amp;quot; | ^ ^ ÷ + || ^ is evaluated right-to-left&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || Add token to output || 3 4 2 × 1 5 − 2 3 || align=&amp;quot;right&amp;quot; | ^ ^ ÷ + ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;#039;&amp;#039;end&amp;#039;&amp;#039; || Pop entire stack to output || 3 4 2 × 1 5 − 2 3 ^ ^ ÷ + || ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Input: {{nowrap|sin ( max ( 2, 3 ) ÷ 3 × {{pi}} )}}&amp;lt;!-- While the result is right, the steps taken are wrong.  If the equation was, for instance, sin(max(-2, 3)÷3*π), the result in RPN would be 2 3 (-) max 3 ÷ π * sin.  (Assuming (-) is the negation function).  Generally, any time you put in a function without a left parenthesis inside a multivariable function, ignoring the comma will result in a wrong answer. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Token !! Action !! Output&amp;lt;br&amp;gt;(in [[Reverse Polish Notation|RPN]]) !! Operator&amp;lt;br&amp;gt;stack !! Notes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | sin || Push token to stack ||  || align=&amp;quot;right&amp;quot; | sin ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ( || Push token to stack ||  || align=&amp;quot;right&amp;quot; | ( sin ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | max || Push token to stack ||  || align=&amp;quot;right&amp;quot; | max ( sin ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ( || Push token to stack ||  || align=&amp;quot;right&amp;quot; | ( max ( sin ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || Add token to output || 2 || align=&amp;quot;right&amp;quot; | ( max ( sin ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | , || Ignore || 2 || align=&amp;quot;right&amp;quot; | ( max ( sin || The operator at the top of the stack is a left parenthesis&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || Add token to output || 2 3 || align=&amp;quot;right&amp;quot; | ( max ( sin || &lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; rowspan=&amp;quot;3&amp;#039; | ) || Pop stack to output || 2 3 || align=&amp;quot;right&amp;quot; | ( max ( sin || Repeated until &amp;quot;(&amp;quot; is at the top of the stack&lt;br /&gt;
|-&lt;br /&gt;
| Pop stack || 2 3 || align=&amp;quot;right&amp;quot; | max ( sin ||Discarding matching parentheses&lt;br /&gt;
|-&lt;br /&gt;
| Pop stack to output || 2 3 max || align=&amp;quot;right&amp;quot; | ( sin || Function at top of the stack&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ÷ || Push token to stack || 2 3 max || align=&amp;quot;right&amp;quot; | ÷ ( sin ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || Add token to output || 2 3 max 3 || align=&amp;quot;right&amp;quot; | ÷ ( sin ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; rowspan=&amp;quot;2&amp;quot; | × || Pop stack to output || 2 3 max 3 ÷ || align=&amp;quot;right&amp;quot; | ( sin ||&lt;br /&gt;
|-&lt;br /&gt;
| Push token to stack || 2 3 max 3 ÷ || align=&amp;quot;right&amp;quot; | × ( sin || &lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | {{pi}} || Add token to output || 2 3 max 3 ÷ {{pi}} || align=&amp;quot;right&amp;quot; | × ( sin ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; rowspan=&amp;quot;3&amp;quot; | ) || Pop stack to output || 2 3 max 3 ÷ {{pi}} × || align=&amp;quot;right&amp;quot; | ( sin ||Repeated until &amp;quot;(&amp;quot; is at the top of the stack&lt;br /&gt;
|-&lt;br /&gt;
| Pop stack || 2 3 max 3 ÷ {{pi}} × || align=&amp;quot;right&amp;quot; | sin ||Discarding matching parentheses&lt;br /&gt;
|-&lt;br /&gt;
| Pop stack to output|| 2 3 max 3 ÷ {{pi}} × sin|| ||Function at top of the stack&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;#039;&amp;#039;end&amp;#039;&amp;#039; || Pop entire stack to output || 2 3 max 3 ÷ {{pi}} × sin || ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Operator-precedence parser]]&lt;br /&gt;
*[[Stack-sortable permutation]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
*[http://www.cs.utexas.edu/~EWD/MCReps/MR35.PDF Dijkstra&amp;#039;s original description of the Shunting yard algorithm]&lt;br /&gt;
*[https://literateprograms.org/shunting_yard_algorithm__c_.html Literate Programs implementation in C]&lt;br /&gt;
*[https://github.com/Skarlett/shunting-yard-rs/blob/93bf03b37da611c1d642b6e221597ae095189901/src/main.rs#L220-L300 Demonstration of Shunting yard algorithm in Rust]&lt;br /&gt;
*[http://www.chris-j.co.uk/parsing.php Java Applet demonstrating the Shunting yard algorithm]&lt;br /&gt;
*[http://www.codeding.com/?article=11 Silverlight widget demonstrating the Shunting yard algorithm and evaluation of arithmetic expressions]&lt;br /&gt;
*[http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm Parsing Expressions by Recursive Descent] Theodore Norvell © 1999–2001. Access date September 14, 2006.&lt;br /&gt;
*[https://nl.mathworks.com/matlabcentral/fileexchange/68458-evaluation Matlab code, evaluation of arithmetic expressions using the shunting yard algorithm]&lt;br /&gt;
&lt;br /&gt;
{{Parsers}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Parsing algorithms]]&lt;br /&gt;
[[Category:Dutch inventions]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Scrooge Mcduc</name></author>
	</entry>
</feed>