Skip to content

Simple deterministic pushdown automata simulator assignment for CS Degree @ Central University of Venezuela

Notifications You must be signed in to change notification settings

Daviddp96/pushdown-automata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

pushdown-automata

This program simulates a given Pushdown Automaton (PDA), showing the behavior of the stack at each step and the result of evaluating that string on the PDA.

How to use

The first line of the input is an integer C, indicating the number of test cases to use on the PDA.

Then we need a pair (N, T) of integers, indicating the number of states and the number of transitions that make up the PDA respectively.

Subsequently, we input T lines representing the transitions of the PDA, in the form O F L E D indicating a transition from state O to state F by reading L in the input string, unstacking E from the stack, and stacking D, all separated by a space.

Finally, C input strings will be received to be evaluated by the PDA.

Constraints

● The initial state is always the state 0.

● There is only one final state, and this is always the last state (N-1).

● The beginning of the stack will be represented by the character Z.

● The lambda character (λ) will be given by the symbol '~'.

How it works

Let's simulate a PDA, with 2 test cases 4 states and 6 transitions:

image

The input from the table above simulates a PDA like the following:

image

And the test cases for this PDA are "abb" and "" (empty string).

The program will take each string to test and evaluate it in the PDA, by showing each time something is pushed or popped from the stack. If the string takes the PDA to the final state, then the program will output ACCEPTED, if not, it will output REJECTED.

image

Example Input

2

4 6

0 1 a Z ZAA

0 3 ~ Z Z

1 1 a A AAA

1 2 b A ~

2 2 b A ~

2 3 ~ Z Z

abb

Example Output

Case 1:

Z

ZAA

ZA

Z

Z

ACCEPTED

Case 2:

Z

Z

ACCEPTED

About

Simple deterministic pushdown automata simulator assignment for CS Degree @ Central University of Venezuela

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages