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
3
votes
2 answers

How do unary operators get parsed using RPN?

Given the infix expression -190 + 20, what would the correct result look like as RPN? -190 + 20 == -190 20 + ? or.. -190 + 20 == 190 - 20 + ? Are the rules for unary operators (negative) the same as other operators, but just a right associative…
GN.
  • 8,672
  • 10
  • 61
  • 126
3
votes
1 answer

How can I correctly combine multiple boolean postfix expressions?

I've put together some code to convert between postfix and infix and back again. Now I'm trying to take separate postfix expressions and combine them. My expressions are only using boolean operators (NOT, XOR, AND, OR). Note that the numbers in…
hobwell
  • 538
  • 1
  • 8
  • 26
3
votes
3 answers

C++ stack for multiple data types (RPN vector calculator)

I have designed a quick and basic vector arithmetic library in C++. I call the program from the command line when I need a rapid cross product, or angle between vectors. I don't use Matlab or Octave or related, because the startup time is larger…
Escualo
  • 40,844
  • 23
  • 87
  • 135
3
votes
2 answers

Apply distributive law on AST (or RPN) => disjunctive normal form

I have expressions like the following: {1000} AND ({1001} OR {1002} OR {1003}) Allowed operators are OR and AND, expressions can be nested using parenthesis. I already managed to tokenize this string and to convert it to an abstract syntax tree…
2
votes
4 answers

Stanford CS193p Assignment 2 - Entering variables into RPN calculator

I am currently teaching myself iPhone programming and working on solving assignment 2 [PDF] of this year Stanford CS193p course. There's something I don't understand about Required Task 1. One is supposed to add variable support to RPN calculator…
user1044147
  • 108
  • 1
  • 6
2
votes
1 answer

Parsing expressions with an undefined number of arguments

I'm trying to parse a string in a self-made language into a sort of tree, e.g.: # a * b1 b2 -> c * d1 d2 -> e # f1 f2 * g should result in: # a * b1 b2 -> c * d1 d2 -> e # f1 f2 * g #, * and -> are symbols. a, b1, etc. are…
user76035
  • 1,526
  • 1
  • 10
  • 12
2
votes
1 answer

Building a function with x,y parameters using Reverse Polish notation

I'm trying to build a python function from a input given in Reverse Polish notation. My function is supposed to be able to take in x and y values as parameters and return the value of the function for the respective x and y. My input is for…
Simon
  • 101
  • 1
  • 6
2
votes
2 answers

How to use IF-ELSE in RPN(Reverse Polish Notation)?

i have done a RPN class to calculate strings which end-user input like "1.0+3/2-tan(45)/(1+1)+sin(30)*abs(-1)+Abs(-10)" Then, I want to parsing conditional statements and multi-parameters function such as "if(1>2,3/3,2*1)","max(1,2,3,4)" So, my…
AeroYoung
  • 31
  • 5
2
votes
1 answer

Explanation how should work the RPN calculator in the case of one argument and operand (divide or multiply)

I'm trying to understand how the RPN calculator should work in the case of the one argument and one operand, for example. divide or multiply. I know how it should work in simple cases, eg. > 1 1 > 3 3 > + result: 4 explanation: 1 + 3 = 4 It's…
Velidan
  • 5,526
  • 10
  • 48
  • 86
2
votes
0 answers

Showing predicted boxex in an RPN (Tensorflow Faster-RCNN)

I’m stuck in training a model for the recognition of characters on images. What I’m currently doing is trying to recognize letters in a relatively small image (700x50) by using the pre-defined faster-rcnn from the TensorFlow object detection…
2
votes
1 answer

C++ Reverse Polish Notation read from a file

I have a file that contains text in RPN, each line is different. Let's take first line for example: 12 2 3 4 * 10 5 / + * + I need to count a total of each line. To do so, I need to use stack. It works like this: If there's a number -> add it to…
Ania
  • 450
  • 4
  • 14
2
votes
1 answer

RPN short circuit evaluation

I am now in the midst of making a simple bytecode interpreter that uses RPN for expression notation and really postfix notation for anything, but now I've come to the question which is: can short circuit evaluation actually be used on postfix…
2
votes
1 answer

A Complete RPN Expr-Eval Program Inside a Tweet? -- "YES WE CAN!", Using LISP

The Program (115 Chars) (defun rpn(e)(let((s()))(dolist(x e)(if(numberp x)(push x s)(push(eval(reverse(list(pop s)(pop s)x)))s)))(car s))) A simple test: CL-USER> (rpn '(1 2 3 * + 4 2 / +)) And it returns 9 Anyone has some good ideas about writing…
Kenny Yuan
  • 21
  • 1
2
votes
3 answers

Converting a char (aka: '+') to an operator

I've set myself the challenge of a RPN calculator. I have a list with the numbers used (in order) and another list with the operators used (in order, as chars). How can I create a function that will take the [0] from list1, take [0] from list2, then…
user3355678
  • 23
  • 1
  • 3
2
votes
1 answer

complicated expressions in Shunting-yard algorithm causing calculator error

I have implemented the shunting-yard algorithm as can be seen here: #!/usr/bin/env python import sys import string import operator import signal class InvalidStackError(Exception): pass class BadParenError(Exception): pass def hook_ctrl_c(signal,…
DTSCode
  • 1,062
  • 9
  • 24
1
2
3
13 14