A Simulator for a non-deterministic Push-Down Automaton

This simulator can simulate a non-deterministic push-down automata and accept by either final state or empty stack. It takes either a PDA machine description file as input or a CFG description file  as input, the format of which are discussed below.

Contents :

Using the Simulator

As the simulator is built in Java, a Java runtime environment is needed to run the simulator. To run the simulator type "java main" at the command prompt under the directory in which the class files are stored.

At this point  you shall see the initial frame as shown in figure 1. At this point you have two options : you can either choose to load a PDA, or to load a context free grammar. If you click on the "Load PDA" button, you shall see a File chooser dialog ( figure 2), which shall ask you to choose a PDA description file (extension ".pda"). Or if you click on the "Load CFG" button, a File chooser dialog shall appear which shall ask you to choose a CFG description file (extension ".cfg"). It shall then load the CFG and build an equivalent PDA.

You select and open the appropriate file. The format for the file is described later. The simulator will load and display the states of the machine and the transitions between the states (see figure 3). A near-optimal heuristic is used to distribute the states in the drawing area. The start state is drawn in red and the final state(s) is/are drawn with two concentric circles. The stack is initialized with the start stack symbol. The title of the description file (typically describing the language is shown at the head of the frame).

Now, you enter an input string in the text box. If you do not enter anything, the input string shall be taken to be the empty string. Now you have an option to press the following two buttons :

The "Retrace" button allows you to view the deterministically, the path taken by the PDA to accept a string. At any point, the current state, current stack top and the current input head position are colored blue. (figure 5)

The "Reset" button resets the state of the PDA back to its starting state( including stack and input tape). Then you can input another string and simulate.

Format of the PDA Description File

The format for the PDA files is the following. There should be no blank lines:

Line 1: type of machine (PDA)
Line 2: name of the machine. For assignments use name(s) and question number
Line 3: FINAL STATE or EMPTY STACK.  Determines how the machine accepts string.
Line 4: all characters in the input alphabet, separated by spaces
Line 5: all characters in the stack alphabet, separated by spaces
Line 6: initial stack symbol.
Line 7: all the machine states.
Line 8: the initial state of the PDA machine
Line 9: all the final state(s) separated by spaces. The list could be empty.
Line 10: first of a list of transitions (see below)
Line 11: another transition
?
Line ?: last of the list of transitions
Last line: end. You must type the word "end" but it can be upper or lower case

The format of a transition is:

<state> <input tape symbol> <input stack symbol> <next-state> <output string of stack symbols>

where

Example :

PDA
Example 1: Hopcroft & Ullman's PDA for {ww^R : w in (a + b)*}
FINAL STATE // Final State or Empty Stack, this line is not case-sensitive
a b // Input Alphabet: alphabet is CASE-SENSITIVE
a b Z // Stack Alphabet: alphabet is CASE-SENSITIVE
Z // Stack Start Symbol
q0 q1 q2 // Machine states (strings): note: alphabet and states are CASE-SENSITIVE
q0 // Start State
q2 // Set of Final States--can be empty, in which case language is empty or machine accepts by Empty Stack.
q0 \ Z q2 Z // transitions: input state, tape symbol, stack symbol, output state, stack output
q0 a Z q0 aZ
q0 b Z q0 bZ
q0 a a q1 \
q0 a a q0 aa
q0 a b q0 ab
q0 b a q0 ba
q0 b b q0 bb
q0 b b q1 \
q1 b b q1 \
q1 a a q1 \
q1 \ Z q2 Z
end // required, this line is not case-sensitive



Format of CFG Description File

The format of the CFG description file is as follows. There should be no blank lines.

Line1: Title line
Line 2 : All character in the set of terminals separated by spaces.
Line 3 : All character in the set of non-terminals separated by spaces.
Line 4 : Starting non-terminal
Line 5 : first of a list of rules
Line 6 : another rule
........
Line ? : last of the list of rules.
Last Line : end . You must type "end" ( case insensitive).

Example :

CFG for {0^n#1^n | n>=0}
0 1 # // Non-terminals
A B // Terminals
A // Start symbol
A -> 0A1
A -> B
B -> #
end
 
 

Source Code

Javadoc Documentation

Click here for the javadoc documentation.
 
 

Some sample input files

Sample PDA description files :

Sample CFG description files :

Compiling and running the simulator

If you have downloaded the source files, uncompress the archive, and compile all the java source files using "javac *.java" .

To run the simulator type "java main" at the command prompt. To generate documentation type "javadoc *.java".
 
 

Feedback

This software is meant for free use, so feel free to download and use it. I would appreciate it if you would mail me if you use my software. Also, feel free to maill me about any bugs or any feedback you might have about my software.