TMJAVA.docx - public class TManbncn cfw A constant for the...

This preview shows page 1 - 3 out of 3 pages.

public class TManbncn { /* * A constant for the tape blank. */ private static final char B = 0; private static final char[][] delta = { {1,'a',2,'X','R'}, // delta(q1,a) = (q2,X,R) {1,B,7,B,'R'}, // etc. {2,'a',2,'a','R'}, {2,'Y',2,'Y','R'}, {2,'b',3,'Y','R'}, {3,'b',3,'b','R'}, {3,'Z',3,'Z','R'}, {3,'c',4,'Z','L'}, {4,'a',4,'a','L'}, {4,'b',4,'b','L'}, {4,'Z',4,'Z','L'}, {4,'Y',4,'Y','L'}, {4,'X',5,'X','R'}, {5,'a',2,'X','R'}, {5,'Y',6,'Y','R'}, {6,'Y',6,'Y','R'}, {6,'Z',6,'Z','R'}, {6,B,7,B,'R'} }; /* * A String containing the char for each accepting * state, in any order. */ private static final String accepting = "\7"; /* * The initial state. */ private static final char initial = 1; /* * The TM's current tape and head position. We always * maintain 0 <= head < tape.length(), adding blanks
Image of page 1
* to the front or rear of the tape as necessary. */ private String tape; private int head; /* * The current state. */ private char state; public boolean accepts(String s) { state = initial; head = 0; tape = s; // establish 0 <= head < tape.length() if (head==tape.length()) tape += B;
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • Fall '15
  • Narendragoel
  • ASCII, tape, @param, @return

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern