Questions tagged [shunting-yard]

The Dijkstra Shunting-yard algorithm is a very general, linear time, stack-based algorithm for parsing mathematical expressions.

The Dijkstra Shunting-yard algorithm is a very general, linear time, stack-based algorithm for parsing mathematical expressions specified in infix notation. It can be used to produce output in Reverse Polish notation (RPN) or as an abstract syntax tree (AST). It was invented by the Dutch computer science Edsger Dijkstra, and published in 1960. He named it the "shunting yard" algorithm because its operation resembles that of a railroad shunting yard.

It is not used in most production compilers, as they already have more general parsing systems that include arithmetic expressions as a special case. It is very widely used as a teaching exercise, and it can be used in compilers for special languages where the programmer can add operators or redefine operator precedence, which are easily made variable in the algorithm, unlike the parsers generally used in production compilers.

Wikipedia page

124 questions
0
votes
0 answers

Dijkstra' s Shunting Yard algorithm in C++

As my homework I have to write a program that calculates an equation given as string. A part of the program is a function parsing an infix expression into postfix. Here is my code: void dijkstra(string& s) { int i,j=s.size(); stack < char >…
0
votes
1 answer

Having trouble adding Parenthesis handling in my Shunting yard implementation

I am implementing the shunting yard algorithm and I am having trouble handling parenthesis. It works fine with non grouped expressions though. Here's what I have without Parenthesis detection: public void makePost(String e) { String[] arr =…
RN_
  • 878
  • 2
  • 11
  • 30
0
votes
1 answer

Space out console text without tabs using Java

Hey I am currently writing an expression calculator in Java. I have now got it to work but can't figure out how to space out writing in the terminal what I want is two list next to each other. I would originally of used tabs but because the arrays…
user202051
  • 173
  • 2
  • 5
  • 17
0
votes
2 answers

What does this Shunting-Yard algorithm statement mean?

I am trying to develop a Shunting-Yard Algorithm based on pseudocode from the Wikipedia page. One of the operations states: If the token is a function argument separator (e.g., a comma) [...] Could someone please clarify what this means?
user3120023
  • 197
  • 3
  • 6
  • 16
0
votes
0 answers

Java cant move something from a stack to a queue

So I'm writing a function to perform the shunting yard algorithm on some numbers/operators. The issue is that I have a loop at the end that adds all the remaining operators to the output queue, but for some reason they are not being added. I have…
Birdfriender
  • 343
  • 1
  • 7
  • 24
0
votes
2 answers

Is this Shunting Yard's fault or my own?

Given the expression: 1/2/3/4*5 It reaches the end of the expression and attempts to multiply out the 4 and 5 first WHICH IS WRONG because it begins to pop off the stack. I'm not necessarily doing RPN but just evaluating on the spot. How can I…
Vaughan Hilts
  • 2,839
  • 1
  • 20
  • 39
0
votes
0 answers

Shunting Yard algorithm implementation

I've been trying to implement shunting yard algorithm. The code gets an input from the user and after it is evaluated by another function (which is done already), it will be converted to postfix notation and then passed to be computed. The code…
Gela
  • 79
  • 1
  • 13
0
votes
2 answers

Calculating non-integer exponents in iOS

I've been working on my math parser a bit, and I have come to realize that a bit of code I'm using is unable to handle an exponent that is non-interger. The bit of code I'm using seems to work just fine with an int, but not with a double. else if…
Joe Million
  • 147
  • 9
0
votes
1 answer

Convert infix to RPN (shunting yard)

Here is my code to convert infix to RPN using shunting yard. I know how the algorithm works well and I have no problem with that, but when I run this just nothing happens. When I debug it I get unknown error on stack initialization line. #include…
PedramH
  • 123
  • 1
  • 8
0
votes
1 answer

Modifying the Shunting Yard Algorithm (c++)

I have a shunting yard algorithm in proper working order, but I noticed a special quirk: 1 + ( 3 * ( 4 + 5 ) ) parses correctly to 1 3 4 5 + * +, but 1 + (3 * (4 + 5)) fails, and parses to 1 * + 5)) + I want to get it to parse the second problem…
0
votes
2 answers

Input string C++ double chevron

I'm currently trying to use a double chevron in a string for "<<" and ">>" to represent bit shifting. However, my program does not seem to recognize using double chevrons for any input. If I change it to any other string, it works…
Vernah
  • 81
  • 1
  • 4
  • 11
0
votes
5 answers

C++ compiler error concerning a supposedly undeclared function

I'm currently writing a basic program to evaluate mathematical expressions which I will then later use in genetic programming to determine the best solution to a system of expressions. My compiler keeps complaining but I'm almost sure that I've got…
LethalPapercut
  • 163
  • 1
  • 1
  • 6
-1
votes
2 answers

Why does my shunting yard implementation mix operator order?

I have been trying to implement the shunting yard algorithm, but the output of my parser is incorrect. let mut stack: Vec = vec![]; let mut op_stack: Vec = vec![]; for current in sub_tree { if current.tok_type ==…
Ashtyn
  • 29
  • 4
-1
votes
3 answers

Memory loss with = operator

Okay so I'm trying to implement a calculator on C++ that can process numbers of any size, for which I made a class named "bignum", so I'm not restrained by C++ default variables. The >> operator is supposed to read my input, parse what's read into…
-1
votes
2 answers

implementing variable identification in shunting yard algorithm

This is a follow up to This question. at this point I want the program to identify the variables by itself and then ask the user for variable values .so instead of looking like: Enter an Expression:…
Vicarious
  • 131
  • 18
1 2 3
8
9