title: Implemeting Shunting yard with Logic
body: <p>So I am trying to implement a shunting yard to work with Logic, I thought it was going to be easy, until I ran into the problem of setting a precedence for the material conditional(->) and bi-conditional(&lt;->) statements since they need to be represented as String and not char. I need to be able to read a file with a statement such as <code>(A|B) -&gt; !C</code>(which means:(A OR B) implies NOT C) and translate it into postfix notation. I keep getting a NullPointerException on line 115 and I am actually not sure why, can I only set a case using char values? Or do I need to find another method of setting precedence for symbols. Here is my code</p>
  
  <pre><code>import java.io.IOException;
  import java.io.FileReader;
  import java.io.BufferedReader;
  import java.util.Scanner;
  import java.io.File;
  import java.util.ArrayList;
  import java.io.Reader;
  
  public class ShuntingYard
  {
  
  public static ArrayList&lt;String&gt; symbols = new ArrayList&lt;String&gt;();
  public static ArrayList&lt;String&gt; letters = new ArrayList&lt;String&gt;();
  public static String path = "";
  public static void main(String args[])
  {
      ShuntingYard sy = new ShuntingYard();
  
      //Scans in File.
      Scanner scan = new Scanner(System.in);
      String prompt = "Please specify the file path.\n Use the form: D:\\DiscreteMath\\inputFile.txt";
      System.out.println(prompt);
      path = scan.next();
      File file = new File(path);
      String infix = "";
  
      try{
  
          scan = new Scanner(file);
          infix = scan.nextLine();
  
      }
      catch(IOException e)
      {
          System.err.println(" No file");
      }
      // calls postfix function
      String postfix = sy.postfix(infix);
      System.out.println("\nPostfix expression : " + postfix);
      String al = "A,B,C,D,E,";
  
  }
  public enum Precedence 
  {
      //configure precedence of symbols and operands.
      lparen(0), rparen(1), not(2), and(3), or(4), mc(5), bc(6), eos(7), operand(8);
  
      private int index;
      Precedence(int index)
      {
          this.index = index;
      }
      public int getIndex()
      {
          return index;
      }
  }
  private static final int[] isp = {0,19,12,12,13,13,0};
  private static final int[] icp = {20,19,12,12,13,13,0};
  private static final String[] operators = {"{","}","!","&amp;","|","-&gt;","&lt;-&gt;"," "};
  
  //initializes stack
  private Precedence[] stack;
  
  private int top;
  
  private Precedence pop()
  {
      return stack[top--];
  }
  private void push(Precedence ele)
  {
      stack[++top] = ele;
  }
  //Sets Precedence of symbols.
  public Precedence getToken(String symbol)
  {
      switch(symbol)
      {
          case "(" : return Precedence.lparen;
          case ")" : return Precedence.rparen;
          case "!" : return Precedence.not;
          case "&amp;" : return Precedence.and;
          case "|" : return Precedence.or;
          case "-&gt;" : return Precedence.mc;
          case "&lt;-&gt;" : return Precedence.bc;
          case " " : return Precedence.eos;
          default : return Precedence.operand;
      }
  }
  //Changes infix to postfix notation then returns a string value.
  public String postfix(String infix)
  {
      String postfix = ""; 
      top = 0;
      stack = new Precedence[infix.length()];
      Precedence token;
      for(int i = 0; i&lt;infix.length(); i++)
      {
          token = getToken(Character.toString(infix.charAt(i)));
  
          if(token == Precedence.operand)
          {
              postfix = postfix + infix.charAt(i);
          }
          else if(token == Precedence.rparen)
          {
              while(stack[top] != Precedence.lparen)
              {
                  postfix = postfix + operators[pop().getIndex()];
              }
              pop();
          }
          else
          {
              while(isp[stack[top].getIndex()] &gt;= icp[token.getIndex()])
              {
                  postfix = postfix + operators[pop().getIndex()];
              }
              push(token);
          }
      }
      while((token = pop()) != Precedence.eos)
      {
          postfix = postfix + operators[token.getIndex()];
      }
      return postfix;
  }
  </code></pre>
  
  <p>}</p>