Coder Social home page Coder Social logo

cristianabrante / pushdownautomaton Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 5.0 618 KB

Implementation of a pushdown automaton (PDA) in Java for learning purposes

License: MIT License

Java 100.00%
automata automata-theory automata-simulator pushdown-automaton context-free-grammar turing-machine

pushdownautomaton's Introduction

Pushdown Automaton Simulator

This is a simple simulator of a pushdown automaton, built in java programming language.

This is a project for the subject Computational Complexity of the Computer Engeneering degree at La Laguna University.

Introduction

An automaton is formal machine, whose function is to determine if a string is contained in a certain type of formal language.

Formally, an automaton is built of states and transitions. Each state represents where is the automaton in the processing of the input string.

In the study of abstract machines, which is a subject of discrete maths and computer science, it exists a wel-known classification of automatons and formal languages that could recognize each automaton. This classification is called Chomsky Hierarchy.

Grammar Language Automaton
Type-0 Recursively enumerable Turing machine
Type-1 Context sensitive Linear-bounded non-deterministic Turing machine
Type-2 Context free Pushdown automaton
Type-3 Regular language Finite state machine

drawing

drawing

As we can see it exist a classification depending on the expressivity power of each automaton. Therefore, each language and automaton has its own properties and definitions. In this programme we are simulating a Pushdown Automaton, which is used to recognize strings belonging to context free languages.

Definition of a pushdown automaton

As we say before, pushdown automaton is a special kind of automaton that employs a stack for working.

Informal description

The pushdown automaton is very similar to a finite state machine, but with an important difference: the use of an stack.

The processing of the string of a pushdown automaton goes like this:

  1. Reads the current symbol of the input string or tape.
  2. Depending on the read symbol, the top symbol of the stack and the current state where the automaton is placed it takes a decision of which state is going to go.
  3. This process is executing until all the string has been explored or where the stack is empty.

It is important to say that this automaton is nondeterministic, so many transitions should be explored for the same combination of states and symbols.

Formal description

Formally the pushdown automaton is defined as a 7-tuple of elements:

consist on this elements: automaton tuple

  • Q : finite set of states of the automaton.
  • Sigma : alphabet of the input tape, which is a finite set of symbols.
  • tau : alphabet of the stack, which is a finite set of symbols.
  • q0 : initial state of the automaton.
  • Z : initial symbol of the alphabet.
  • F : finite set of accepting states.
  • delta : Transition function of the automaton.

Transition function

Usage

For executing the program you should do

    java -jar PushdownAutomaton.jar [log] AutomatonDefinition.txt TapeDefinition.txt

Where parameters mean:

  • log : If this option is included is going to show a trace mode.
  • AutomatonDefinition.txt : Definition of the automaton of acceptance states.
  • tapeDefinition.txt : Optional definition of the tape.

Tape

The tape (input string) should have the symbols separated by spaces.

Example use

This is an example of an execution:

Q = {p, q, r}
Σ = {a, b}
τ = {A, S}
s = p
z = S
F = {r}
δ :
(p, a, S) → (p, [A])
(p, b, A) → (q, [ε])
(p, a, A) → (p, [A, A])
(q, b, A) → (q, [ε])

Enter the tape input >
a a b b
-----------------------------------------------------------------------------
| used transition           | state | word (ω)  | stack           | transitions
-----------------------------------------------------------------------------
| -                         | p     | a a b b $ | [S]             | (p, a, S) → (p, [A])
| (p, a, S) → (p, [A])      | p     | a b b $   | [A]             | (p, a, A) → (p, [A, A])
| (p, a, A) → (p, [A, A])   | p     | b b $     | [A, A]          | (p, b, A) → (q, [ε])
| (p, b, A) → (q, [ε])      | q     | b $       | [A]             | (q, b, A) → (q, [ε])
| (p, a, S) → (p, [A])      | q     | $         | []              | ω ∈ L

String a a b b $ belongs to the language generated by the automaton.

Author

pushdownautomaton's People

Contributors

cristianabrante avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.