shunting-yard

Is there a simple way I can tokenize a string without a full-blown lexer?

I'm looking to implement the Shunting-yard Algorithm, but I need some help figuring out what the best way to split up a string into its tokens is. If you notice, the first step of the algorithm is "read a token." This isn't exactly a non-trivial thing to do. Tokens can consist of numbers, operators and parens. If you are doing some...

How can I modify my Shunting-Yard Algorithm so it accepts unary operators?

I've been working on implementing the Shunting-Yard Algorithm in JavaScript for class. Here is my work so far: var userInput = prompt("Enter in a mathematical expression:"); var postFix = InfixToPostfix(userInput); var result = EvaluateExpression(postFix); document.write("Infix: " + userInput + "<br/>"); document.write("Postfix (RPN):...

Efficiency of stack-based expression evaluation for math parsing

Hello everybody. I have to write, for academic purposes, an application that plots user-input expressions like: f(x) = 1 - exp(3^(5*ln(cosx)) + x) The approach I've chosen to write the parser is to convert the expression in RPN with the Shunting-Yard algorithm, treating primitive functions like "cos" as unary operators. This means the f...

Dijkstra’s algorithm and functions

Hi guys, the question is: suppose I have an input function like sin(2-cos(3*A/B)^2.5)+0.756*(C*D+3-B) specified with a BNF, I will parse input using recursive descent algorithm, and then how can I use or change Dijkstra’s algorithm to handle this given function? I need to execute it with sin | cos | sqrt | ln, where Dijkstra’s algorithm ...

Shunting-yard: missing argument to operator

I'm implementing the shunting-yard algorithm. I'm having trouble detecting when there are missing arguments to operators. The wikipedia entry is very bad on this topic, and their code also crashes for the example below. For instance 3 - (5 + ) is incorrect because the + is missing an argument. Just before the algorithm reaches the ), t...

Postfix to infix with unary/binary operators

I am trying to make a converter from postfix to infix notation and need some help. There is already a question about infix-to-postfix conversion, which gives an example I am failing to convert back. (Note: a minus sign is missing there!) The following is the output of my converter, where the 1st "column" is postfix input, the 2nd is my ...

Which of the following postfix notations correctly represents infix sum 1+2+3+4?

I am testing an infix-to-postfix-to-infix converter and found some kind of uncertainty. For example, a simple infix sum 1 + 2 + 3 + 4 can be converted to postfix one 1 2 + 3 + 4 + assuming that operators with equal precedence are not accumulated. If they are then I get 1 2 3 4 + + + On the other hand, all the following postfix e...

Shunting Yard implementation in PHP needed, interpret and parse a string perform a mathematical comparison and return a boolean result

Hi, I'm looking for something that can interpret a string in php and perform simple math calculation, and then return a boolean result as to whether the expression is true or false. For example: Sue types in "3*{mysalary}/9=10000" PHP splits this up into two expressions - explode('=',string); PHP takes my list of database fields, and...