Giter Club home page Giter Club logo

pushdown-automata's Introduction

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

pushdown-automata's People

Contributors

daviddp96 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.