I'm working on a truth table generator for one of my assignments in Discrete math.. I have to implement the shunting-yard algorithm, and I'm completely lost doing so. My problem, is implementing the shunting-yard algorithm. First I'll show what resources I've looked at, then my problem, then my code that I've started.
What I really need.. I know it's asking for a lot. But is a dumbed down version of the shunting-yard algorithm. I get lost in parts in the wikipedia example when notation is used such as o1 o2. What I really need is someone to explain step by step how to apply this. I'm not understanding how the RPN notation works either.. But that I can read up on now.
- An implementation of the shutting-yard:
http://www.technical-recipes.com/2011/a-mathematical-expression-parser-in-java/#more-1658 - Wikipedia shutting yard algorithm:
http://en.wikipedia.org/wiki/Shunting-yard_algorithm - Someones problem on stackoverflow
Problems with a shunting yard algorithm - Basic implementation
Generating truth tables in Java
Here's an example input:
A -> B
(C)
:. F
I'm supposed to generate an input that shows:
A-B-C-A->B-F
T-T-T--T---T
T-F-T--F---F
F-T-T--T---T
F-F-T--T---F
T-T-F--T---F
T-F-F--F---F
F-T-F--T---F
F-F-F--T---F
import java.util.Stack;
import java.util.ArrayList;
public class ShuttingYard{
private static final char THEREFORE = '>';
private static final char AND = '&';
private static final char OR = '|';
public static String inputToReversePolishNotation(String input)
{
char[] tokens = input.toCharArray();
ArrayList<String> output = new ArrayList<String>();
Stack<String> oppStack = new Stack<String>();
for(int i = 0; i < tokens.length; i++)
{
}
return null;
}
public static boolean isLogicOperator(char input)
{
switch(input)
{
case THEREFORE:
return true;
case AND:
return true;
case OR:
return true;
default:
return false;
}
}
}