Talk:Parsing/RPN to infix conversion: Difference between revisions

No edit summary
 
(4 intermediate revisions by 3 users not shown)
Line 36:
==Negation==
The table of operators needs to inculde an operator for negation. Should -4 8 ^ mean -(4 ^ 8) or (-4) ^ 8.
--[[User:Nigel Galloway|Nigel Galloway]] 12:52, 2 April 2012 (UTC)
 
:In RPN the negative number has no space between the minus sign and the first digit. Subtraction as an operator has spaces around the sign. --[[User:Paddy3118|Paddy3118]] 16:06, 7 May 2012 (UTC)
:I agree that that describes the prn side, but the problem is on the infix side. Infix notation assigns a higer priority to exponentiation than to unary negation. If I use the perl implementation:
<pre>
>rpn.pl
-4 2 ^
-4^2
</pre>
:Then I use the generated infix in perl:
<pre>
>perl
print -5 ** 2
^Z
-25
</pre>
:The correct infix is (-5)**2. The same is true for infix in Ruby and Python:
<pre>
irb(main):001:0> -4 ** 2
=> -16
Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> -4 ** 2
-16
</pre>--[[User:Nigel Galloway|Nigel Galloway]] 14:19, 11 May 2012 (UTC)
 
== Extraneous Requirements ==
 
The requirement "Show how the major datastructure of your algorithm changes with each new token parsed" is entirely extraneous to the core task, and, I think, its inclusion goes against the principle mission of Rosetta code. For reasons outlined in [[Rosetta Code:Village Pump/Extraneous Printing Requirements in Tasks]], I think we should make this requirement optional. If no one objects after several days, I will make this minor change.