Automata Based Programming
Muhammad Hammad
Ali Shahzad
Theory of Automata
11.5.2015
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.
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); }
AUTOMATA BASED STYLE PROGRAM
Int 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;
}
FSM(Model)
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.
FSM as program
Event
Controller
=
Finite
State
Machines
Controlled object
Event
Event Controlled object
Controlled object
Example. Traffic Lights
Red
Green
Yellow
Blinking
green
Red
+
yellow
Source code. Controlled object
public 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");
}
}
FSM
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
Conclusions
• Modeling system
• Modeling=writing the code
• Step-by-step
• Easier to verify
• Good for modeling reactive systems
Refrences
• http://en.wikipedia.org/wiki/Finite-state_machine
• http://is.ifmo.ru/automata_en/_tech_aut_prog.p
• http://en.wikipedia.org/wiki/Automata-
based_programming

Automata based-programming

  • 1.
    Automata Based Programming MuhammadHammad Ali Shahzad Theory of Automata 11.5.2015
  • 2.
    Introduction • The ideacomes 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.
  • 3.
    Automata-Based Programming Asa 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); }
  • 4.
    AUTOMATA BASED STYLEPROGRAM Int 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; }
  • 5.
  • 6.
    ADVANTAGES • In automatabased 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.
  • 7.
    FSM as program Event Controller = Finite State Machines Controlledobject Event Event Controlled object Controlled object
  • 8.
  • 9.
    Source code. Controlledobject public 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"); } }
  • 10.
  • 11.
    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
  • 12.
    Conclusions • Modeling system •Modeling=writing the code • Step-by-step • Easier to verify • Good for modeling reactive systems
  • 13.