Coder Social home page Coder Social logo

dfalang's Introduction

DFALang

An interpreter of a compact language for working with Deterministic Finite Automata.

Introduction

The language has a simple structure. It allows you to define Deterministic Finite Automata and ask to accept strings by them.

An automaton definition in this language looks like this:

A1 = DFA { \
  S = 4 \
  A = {'a', 'b', 'c'} \
  T = {(1, 'a', 2), (1, 'b', 3), (2, 'c', 4), (3, 'b', 1)} \
  F = {2, 4} \
}

Ask to accept a string with this automaton:

Accept "abc" with A1

or

Accept "abc" with DFA { \
  S = 4 \
  A = {'a', 'b', 'c'} \
  T = {(1, 'a', 2), (1, 'b', 3), (2,'c', 4), (3, 'b', 1)} \
  F = {2, 4} \
}

You can also ask to accept a string with several automata at the same time:

Accept "abc" with {A1, A2, A3}

Render (visualize) several automata with:

Print {A1, A2}

The language grammar.

Program        = {[NewLines] Module}.
Module         = (DefModule | AcceptModule) NewLines.
DefModule      = ID '=' Automaton.
Automaton      = 'DFA' '{' States Alphabet Transitions FinalStates '}'.
PrintModule    = 'Print' IDList
AcceptModule   = 'Accept' STRING 'with' (IDList | Automaton).
States         = 'States'|'S' '=' NUMBER.
Alphabet       = 'Alphabet'|'A' '=' LetterList.
Transitions    = 'Transitions'|'T' '=' TransitionList.
FinalStates    = 'FinalStates'|'F' '=' NumberList.
LetterList     = '{' LETTER {',' LETTER} '}'.
NumberList     = '{' NUMBER {',' NUMBER} '}'.
IDList         = ID | '{' ID {',' ID} '}'.
TransitionList = '{' Transition {',' Transition} '}'.
Transition     = '(' NUMBER ',' LETTER ',' NUMBER ')'.
NewLines       = NL {NL}.

Parse an input script file as:

python Interpreter.py --input_file tests/script1 --output_dir tests/output

dfalang's People

Contributors

anikar avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.