/ src / main / Instruction.java
Instruction.java
 1  package main;
 2  
 3  /**
 4   * An Instruction instance acts as an element of the transition
 5   * function of a Turing Machine.
 6   *
 7   * Created by Pep on 4/20/2017.
 8   */
 9  public class Instruction {
10      int p;
11      char a;
12      char b;
13      Direction m;
14      int q;
15  
16      public enum Direction {L, R}
17  
18      /**
19       * Creates a new instruction of the form: p, a -> b, m, q
20       * @param p start state
21       * @param a start symbol
22       * @param b ending symbol (what "a" is changed to)
23       * @param m direction to move the read/write head
24       * @param q ending state
25       */
26      public Instruction(int p, char a, char b, Direction m, int q) {
27          this.p = p;
28          this.a = a;
29          this.b = b;
30          this.m = m;
31          this.q = q;
32      }
33  
34      /**
35       * @return a string of the form '(p, a, b, m, q)'
36       */
37      public String toString(){
38          String ret = "(" + p + ", " + a + ", " + b + ", ";
39          switch (m) {
40              case L: return ret + "L, " + q + ")";
41              case R: return ret + "R, " + q + ")";
42          }
43       }
44  }