automata based-programming

13
Automata Based Programming Muhammad Hammad Ali Shahzad Theory of Automata 11.5.2015

Upload: shaheer-ahmed

Post on 07-Aug-2015

13 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Automata based-programming

Automata Based Programming

Muhammad HammadAli Shahzad

Theory of Automata

11.5.2015

Page 2: Automata based-programming

Introduction

• The idea comes from automata theory.

• Automata-programming doesn’t mean programming with the use of automata, but the entire programming paradigm and programming technology is aimed for designing system with complex behavior

• The approach is being developed since 1991.

• To put it simple, the approach proposes to describe the behavior of program using automata which are later converted into code.

Page 3: Automata based-programming

Automata-Based Programming As a Programming Paradigm

• We normally use two types of programming paradigm : Traditional(Imperitive) , Procedural

• Traditional Imperative program in C :

#include<stdio.h> int main(void) { c = getchar(); int c; } do { putchar(‘\n’); c = getchar(); while(c != EOF && c !=

‘\n’ ) while (c == ‘ ‘) { c =

getchar();c = getchar(); } while ( c != EOF);

while (c != EOF && c ! = ‘ ‘ c != ‘\n’) { return 0;putchar(c); }

Page 4: Automata based-programming

AUTOMATA BASED STYLE PROGRAMInt main(void) {

enum states { case inside: before,inside,after if (c == ‘ ‘) {

} state; state = after;int c; } else {state = before; putchar(c);

while(c = getchar() ! = EOF){ }if ( c == ‘\n’) {state = before; break;} else case after;

switch(state) { break;case before; }if (c != ‘ ‘) { return 0;

putchar(c); } state = inside;break;

}

Page 5: Automata based-programming

FSM(Model)

Page 6: Automata based-programming

ADVANTAGES• In automata based programming we propose that each

must not contain only user manual but the project documentation including relation diagrams and transition graphs for each manual.

• The manually designed automata is transformed into code manually or automatically which works right away and needs minimal debugging.

• As the logic is represented in the visual form instead of usual text form, making fixes is simpler and it is much easier to understand the logic for people other than the author.

• Besides that thinking in automata is necessary for event-driven programming as the only alternative to using parallel processes or threads.

Page 7: Automata based-programming

FSM as program

Event

Controller=

Finite State

Machines

Controlled object

Event

Event Controlled object

Controlled object

Page 8: Automata based-programming

Example. Traffic Lights

Red

Green

Yellow

Blinkinggreen

Red+

yellow

Page 9: Automata based-programming

Source code. Controlled objectpublic class TrafficLight implements ControlledObject {public void red(StateMachineContext context) {

System.out.println("Red"); }

public void green(StateMachineContext context) {System.out.println("Green");

}public void yellow(StateMachineContext context) {

System.out.println("Yellow"); }

public void greenblink(StateMachineContext context) {System.out.println("Green Blinking");

}

public void redyellow(StateMachineContext context) {System.out.println("red yellow");

}}

Page 10: Automata based-programming

FSM

Page 11: Automata based-programming

Source code. Controller switch (s) { case green: switch (event) { case next tick: if (counter_x4 < 20) { make transition to state “blinking green”;

return new StateMachineConfig("blinking green");

} if (counter_x4 >= 20) { make transition to final state; return new StateMachineConfig(" final state "); }

…}

Switch technology

Page 12: Automata based-programming

Conclusions

• Modeling system• Modeling=writing the code• Step-by-step• Easier to verify• Good for modeling reactive systems

Page 13: Automata based-programming

Refrences

• http://en.wikipedia.org/wiki/Finite-state_machine

• http://is.ifmo.ru/automata_en/_tech_aut_prog.pdf

• http://en.wikipedia.org/wiki/Automata-based_programming