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
-1
votes
1 answer

Parse Math Expression in PHP

I'm currently trying to parse math expression into expression tree. But I'm stuck on the stage where I need to implement functions and negates. I don't understand logic to do it using Shunting-Yard algorithm. What I currently want to do is to…
Paul R
  • 2,631
  • 3
  • 38
  • 72
-1
votes
1 answer

Shunting yard algorithm in Java not working?

Here is my code: public String ShuntingYard(String input) { Tokenizer tokens = new Tokenizer(input); output = new LinkedList(); stack = new MyStack(new LinkedList(), new LinkedList()); while…
Akaraka
  • 173
  • 1
  • 2
  • 13
-2
votes
1 answer

Instantiate variables in class

I am busy with a shunting-yard algorithm. If you have an expression like: x + y + sqrt 25 - 3 the class doesn't know what the variables name and value would be. So I have a function in the class, instantianteVariable(char name, int value), with the…
paper006
  • 19
  • 1
  • 5
-3
votes
1 answer

Shunting-yard algorithm with function support

i found this implementation of the Shunting-yard algorithm over the internet (Infix to Postfix with function support) infix_to_postfix(infix): postfix = [] infix.add(')') stack = [] stack.push('(') for each token in infix: if token is operand: …
Error_404
  • 109
  • 7
1 2 3
8
9