Questions tagged [rpn]

For questions relating to the Reverse Polish Notation, which is a notation for mathematical expressions where the operands precede the operator.

In computing, RPN is ideally suited for a stack-based implementation, and in hardware it has a long history with HP hand-held calculators.

E.g. 1 2 + means apply the + operator to the operands 1 and 2.

198 questions
2
votes
1 answer

Antlr4 grammar left recursive error

I am having quite a problem with antlr4 right now. Whenever I try to feed antlr with this RPN grammar grammar UPN; //Parser expression : plus | minus | mult | div | NUMBER; plus : expression expression '+'; minus :…
skoelz
  • 23
  • 4
2
votes
2 answers

Haskell problems in a RPN caculator implementation

I'm trying to implement a RPN caculator in Haskell. It is an exercise from Learn You a Haskell. Here's my code: import Data.List solveRPN :: String -> Int solveRPN str = head $ foldl putStack [] (words str) where putStack accumulator…
Yun-Chih Chen
  • 543
  • 6
  • 18
2
votes
3 answers

Calculate answer from list

I have to make a calculator in java that is able to work with brackets, plus, minus, divide and multiply, so far I've got it so if the user were to enter: 14 * ( 2 - ( 3 / 2 ) ) then it returns an ArrayList as: [14.0, 2.0, 3.0, 2.0, /, -, *] which…
user3120023
  • 197
  • 3
  • 6
  • 16
2
votes
1 answer

In Erlang, how to return a string when you use recursion?

I really could'n formulate the question better, but here's my problem: I want to use this code to convert infix expression to postfix expression in Erlang, but it only writes to the console output. The problem is, I need a list or a string returned,…
A B
  • 23
  • 2
2
votes
2 answers

Refactoring feedback for Reverse Polish Notation (RPN) or Postfix Notation

One of the pre-work exercises for Dev Bootcamp is an RPN calculator. I made it work but would like refactoring feedback. Any and all help to make this code cleaner is greatly appreciated. class RPNCalculator def evaluate(rpn) a =…
ltrainpr
  • 3,115
  • 3
  • 29
  • 40
2
votes
1 answer

Creating a RPN Calculator

This is my second programming class so please bear with me. I have an assignment that requires me to create an RPN Calculator with functions. It's my first time learning about functions so I'm still confused. My question is: The operator (+, -, *,…
Marcella Ruiz
  • 323
  • 1
  • 3
  • 15
2
votes
1 answer

Regexp issue involving reverse polish calculator

I'm trying to use a regular expression to solve a reverse polish calculator problem, but I'm having issues with converting the mathematical expressions into conventional form. I wrote: puts '35 29 1 - 5 + *'.gsub(/(\d*) (\d*) (\W)/,…
1
vote
3 answers

Reverse polish notation C# don't work correctly

I write an rpn, with a struktogram. Newest Problem: It is'nt work correctly now. If input string is "5 + ((1 + 2) * 4) - 3" My output is: 5 1 2 + 4 * 3 - + I have to got this result: 5 1 2 + 4 * + 3 - Edited the source *That was the original…
blaces
  • 497
  • 3
  • 10
  • 24
1
vote
0 answers

why am I getting 'Illegal guard expression" error? Erlang

Here is my code of simple RPN calculator in Erlang -module('Kalkulator_ONP'). -author("user"). %% API -export([onp/1]). onp(Expression) -> onp(string:tokens(Expression, " "),[]). onp([], [Result]) -> Result; onp([NumberString|Rest], Stack)…
jon
  • 29
  • 5
1
vote
0 answers

RPN to infix with both numbers and pronumerals in Python

I am making a Python program where I get an RPN expression separated by spaces and convert it to infix. It should work like this: Input RPN: x 2 ^ 3 - 1 2 x * - * Output : -2x^3 + x^2 + 6x - 3 However, I cannot get it to work with both pronumerals…
1
vote
1 answer

Polish notation rules to add "in" and operator with logics

i have that expression ratecode in ('EURV','EURA','EURB','EURO','CHUPin*+-da~') && ( sourcecode ~in ('FMFC','FM') || block == 'yes') now that are rpn rules /// 2. Repeat until we reach end of infix expression /// I. Get token…
Carlos Cocom
  • 937
  • 1
  • 8
  • 23
1
vote
1 answer

RRDTOOL - RPN-Expression help, how to reference input in COMPUTE DS (add two DS values or the LAST DS value with a new number)?

I have a data feed that has a single value that increases over time until a forced wrap-around. I have the wrap-around under control. The value from the data feed I pass into a RRD GAUGE as ds1. I want to add a couple data sources to handle…
1
vote
0 answers

RPN stacking method not working with converted string arrays

I'm trying to make a program that processes a line of rpn expression through a stack method. The input is a string array that is converted from a string input. String[] collect = "8 6 + 2 /"; //the String line; //the inputed line collect =…
1
vote
1 answer

Does this test case break the shunting yard algorithm? "1*2-3/4+5*6-7*8+9/10"

I have tried numerous times to solve the following using the shunting yard algorithm: 1*2-3/4+5*6-7*8+9/10 Infix Notation: "1*2-3/4+5*6-7*8+9/10" Postfix Notation: [1,2,*,3,4,/,5,6,*,7,8,*,9,10,/,+,-,+,-] The correct answer is -24. Every time I…
Some Guy
  • 11
  • 1
1
vote
0 answers

Unsupported operand type(s) for +: 'NoneType' and 'NoneType' (Python)

I'm trying to implement stack operations: If I use a list in def rpn itself to store the values and use this list with append and pop it work but as soon as I implement the push and pop and use self.stack as storage it's throwing this: Traceback…
Pleb
  • 33
  • 7
1 2
3
13 14