CSE 298 CSE 300 IOA PRESENTATION May 01

  • Slides: 31
Download presentation
CSE 298 CSE 300 IOA PRESENTATION May 01, 1999 CSE. -IOA-1

CSE 298 CSE 300 IOA PRESENTATION May 01, 1999 CSE. -IOA-1

CSE 298 CSE 300 IOA 2 JAVA Tool Joe Balthazar Jim Byrne Christine Kenney

CSE 298 CSE 300 IOA 2 JAVA Tool Joe Balthazar Jim Byrne Christine Kenney Ainsley Nathaniel Computer Science & Engineering Department The University of Connecticut 191 Auditorium Road, Box U-155 Storrs, CT 06269 -3155 CSE. -IOA-2

CSE 298 CSE 300 Input/Output Automata Process init(v 1) P 1 Channel decide(v 1)

CSE 298 CSE 300 Input/Output Automata Process init(v 1) P 1 Channel decide(v 1) send(m(1, 2)) C(1, 2) receive(m(1, 2)) receive(m(2, 1)) C(2, 1) send(m(2, 1)) init(v 2) P 2 decide(v 2) CSE. -IOA-3

CSE 298 CSE 300 Structure of an IOA m Main components of an I/O

CSE 298 CSE 300 Structure of an IOA m Main components of an I/O Automaton(A): q sig(A), a signature q states(A), a set of states q start states q trans(A), a state-transition relation that follows a precondition-effect style Ø input actions - no preconditions and hence, are permanently enabled Ø internal and output actions - have preconditions and effects q optional tasks CSE. -IOA-4

CSE 298 CSE 300 Objectives m Create a tool to convert the general structure

CSE 298 CSE 300 Objectives m Create a tool to convert the general structure of an IOA to Java code q IOA can be used for algorithm correctness proofs q Recognize only a subset of the language Ø Automaton name, states and data types Ø Input, internal, and output actions Ø Preconditions and effects Parses majority of language Convert a single IOA to a single Java class Produce necessary additional Java code to create a executable program with IOA functionality q Code will run on one machine q m m CSE. -IOA-5

CSE 298 CSE 300 Assumptions m Action names, parameters, and state variables are unique

CSE 298 CSE 300 Assumptions m Action names, parameters, and state variables are unique m Deal only basic data types q boolean q double q int m Preconditions and effects written as Java Code q May change state variables so long as same names are used q Code copied directly to Java class CSE. -IOA-6

CSE 298 CSE 300 Assumptions m m Internal and output actions have no parameters

CSE 298 CSE 300 Assumptions m m Internal and output actions have no parameters q Parameters values selected by IOA code in preconditions based on state q A large enough subset of IOA is not yet implemented to do this Changes to IOA code in parser q All keywords have the first letter capitalized ie. Automaton, Transition, etc. q Some symbols were changed to accommodate the keyboard ie. E - There exist. q Java types were used instead of IOA types- this eliminated the need for a symbol table. q Type checking done by the Java Compiler. CSE. -IOA-7

CSE 298 CSE 300 Java Compiler m Compiler Tool for Java Language. q The

CSE 298 CSE 300 Java Compiler m Compiler Tool for Java Language. q The Java equivalent of Lex and Yacc q Parses grammar to produce Java code m Java. CC uses an input file written in a standard BNF grammar. q Example of simple BNF grammar q <exp> : : = <simp exp> <rel op> <simp exp> q <rel op> : : = < | >= | <= | > CSE. -IOA-8

CSE 298 CSE 300 Compiler Procedure m Get the tokens q The first part

CSE 298 CSE 300 Compiler Procedure m Get the tokens q The first part of the JCC specification defines the tokens for the language. m Parse the Language q The second part defines the transitions that make up the language. m Generate the code q The compiler output is generated by the insertion of Java code in the transitions. CSE. -IOA-9

CSE 298 CSE 300 IOA Tokens m m IOA Token definitions. q < AUTOMATON:

CSE 298 CSE 300 IOA Tokens m m IOA Token definitions. q < AUTOMATON: “Automaton” > q < TRANSITION: “Transition” > q < INPUT: “Input” > q < OUTPUT: “Output” > Resulting Java code is too complicated to put here, looks like assembly language. CSE. -IOA-10

CSE 298 CSE 300 IOA grammar to Java. CC grammar m IOA grammar specification

CSE 298 CSE 300 IOA grammar to Java. CC grammar m IOA grammar specification translates directly into JCC grammar because of similarity in structures. q states : : = ‘states’ state, + (‘so’ ‘that’ predicate)? Ø void states() : Ø {} Ø{ Ø <STATES> state()(“, ” state())* Ø (<SO> <THAT> predicate())? Ø} CSE. -IOA-11

CSE 298 CSE 300 Translation of Grammar Cont’d m Java. CC grammar with Java

CSE 298 CSE 300 Translation of Grammar Cont’d m Java. CC grammar with Java code inserted to create the IOA compiler. q states : : = ‘states’ state, + (‘so’ ‘that’ predicate)? Ø Ø Ø Ø Ø void states() : {} { {String l. Tok. Str; } <STATES> l. Tok. Str = state() {pw. Output. println(l. Tok. Str); } (", " l. Tok. Str = state() {pw. Output. println(l. Tok. Str); })* ( <SO> <THAT> predicate())? } CSE. -IOA-12

CSE 298 CSE 300 Java file which implements the Parser m The IOA compiler

CSE 298 CSE 300 Java file which implements the Parser m The IOA compiler takes an automaton definition as input and produces an equivalent automaton, written in Java, as output. Ø static final public void states() throws Parse. Exception { Ø String l. Tok. Str; Ø jj_consume_token(STATES); Ø l. Tok. Str = state(); Ø System. out. println(l. Tok. Str); Ø label_12: Ø while (true) { Ø if (jj_2_38(2)) { ; Ø CSE. -IOA-13

CSE 298 CSE 300 Differences in Grammars m JCC does not permit left recursion

CSE 298 CSE 300 Differences in Grammars m JCC does not permit left recursion and hence two transitions have to be modified. q For example, A C | AB is a transition with left-recursion. q The equivalent transition A CB+ does not contain left recursion and can be used in a Java. CC grammar file. Ø subterm : : = subterm (op. Sym subterm)+ Ø | (quantifier | op. Sym)* op. Sym secondary Ø | (quantifier | op. Sym)* quantifier primary Ø | secondary op. Sym* CSE. -IOA-14

CSE 298 CSE 300 Left Recursion Removed Ø String subterms() : Ø {} Ø

CSE 298 CSE 300 Left Recursion Removed Ø String subterms() : Ø {} Ø { Ø subterm() (op. Sym() subterm())* Ø } Ø Ø Ø Ø String subterm() : {} { ( ((quantifier() | op. Sym())* secondary()) | ((quantifier() | op. Sym())* quantifier() primary()) | ( secondary() (op. Sym())*) ) } CSE. -IOA-15

CSE 298 CSE 300 The Fibonacci. Skew IOA m m What does it do?

CSE 298 CSE 300 The Fibonacci. Skew IOA m m What does it do? q Produces the Fibonacci sequence q The sequence can be skewed by a certain value from time to time States q ready indicate state of sequence generation q skew value q print. Flag indicates print state q first, second, current holding last three sequence values CSE. -IOA-16

CSE 298 CSE 300 The Fibonacci. Skew IOA m Actions in the IOA q

CSE 298 CSE 300 The Fibonacci. Skew IOA m Actions in the IOA q Input action to start or end the sequence q Input action to skew the sequence q Internal action that calculates the next value in the sequence q Output action that prints the next value CSE. -IOA-17

CSE 298 CSE 300 The Fibonacci. Skew IOA calculate set. Ready skew Fibonacci. Skew

CSE 298 CSE 300 The Fibonacci. Skew IOA calculate set. Ready skew Fibonacci. Skew print Input Action Internal Action Output Action CSE. -IOA-18

CSE 298 CSE 300 IOA States to Private Data m IOA States automaton Fibonacci.

CSE 298 CSE 300 IOA States to Private Data m IOA States automaton Fibonacci. Skew states ready: boolean : = false; skew: int : = 0; print. Flag: boolean : = false; first: int : = 1; sec: int : = 0; current: int : = 0; m Private Data in Java Class class Fibonacci. Skew { // Private Data private boolean ready = false; private int skew = 0; private boolean print. Flag = false; private int first = 1; private int sec = 0; private int current = 0; // Public Methods }; CSE. -IOA-19

CSE 298 CSE 300 Input Action to Public Method m IOA Input Action input

CSE 298 CSE 300 Input Action to Public Method m IOA Input Action input set. Ready(flag: boolean) eff $ if (ready!=flag) { ready = flag; first = 1; sec = 0; current = 0; } $ m Public Method in Java Class public void set. Ready(boolean flag) { if (ready!=flag) { ready = flag; first = 1; sec = 0; current = 0; } } CSE. -IOA-20

CSE 298 CSE 300 Input Action to Public Method m IOA Input Action input

CSE 298 CSE 300 Input Action to Public Method m IOA Input Action input skew(k: int) eff $ if (ready==true) skew = k; else System. out. println(“Cannot skew: No sequence is being generated”); $ m Public Method in Java Class public void skew(int k) { if (ready==true) skew = k; else System. out. println(“Cannot skew: No sequence is being generated”); } CSE. -IOA-21

Internal and Ouput Actions to Public Methods CSE 298 CSE 300 m IOA Internal

Internal and Ouput Actions to Public Methods CSE 298 CSE 300 m IOA Internal Action internal calculate() pre $ return (ready); $ eff $ current = first + second + skew; skew = 0; first = sec; sec = current; print. Flag = true; $ m Public Methods in Java Class public boolean Precalculate() { return (ready); } public void calculate() { current = first + second + skew; . . . } CSE. -IOA-22

Internal and Ouput Actions to Public Methods CSE 298 CSE 300 m IOA Output

Internal and Ouput Actions to Public Methods CSE 298 CSE 300 m IOA Output Action output print() pre $ return (print. Flag); $ eff $ System. out. println(“The current value in sequence is “ + current); print. Flag = false; $ m Public Methods in Java Class public boolean Preprint() { return (print. Flag); } public void print() { System. out. println(“The current value in sequence is “ + current); print. Flag = false; } CSE. -IOA-23

CSE 298 CSE 300 IOA Input Parameters m param. Fibonacci. Skew. java q Created

CSE 298 CSE 300 IOA Input Parameters m param. Fibonacci. Skew. java q Created by Parameter. java q Simulates input parameter values for input actions coming in from environment m IOA Input Action parameter input set. Ready(flag: boolean) m Public Java method for each parameter public boolean returnflag() { input = get. Input(“flag”); return retboolean(input); } CSE. -IOA-24

CSE 298 CSE 300 Helper Methods m Methods for converting String to type value

CSE 298 CSE 300 Helper Methods m Methods for converting String to type value private boolean retboolean(String s) { return Boolean. value. Of(s). boolean. Value(); } m Method to get any parameter value from user public String get. Input(String message) { String response = “”; System. out. println(“Enter “ + message); try { Buffered. Reader br. Inp. read. Line(); response = br. Inp. read. Line(); } catch(Exception e){ e. print. Stack. Trace(); } return response; } CSE. -IOA-25

CSE 298 CSE 300 IOA Scheduler m Fibonacci. Skew. Scheduler. java q Created by

CSE 298 CSE 300 IOA Scheduler m Fibonacci. Skew. Scheduler. java q Created by Scheduler. java q Contains main program which calls a round robin scheduler to cycle through actions public static void Round. Robin() { boolean Not. Quit; Fibonacci. Skew ioa. Fibonacci. Skew = new Fibonacci. Skew(); param. Fibonacci. Skew input. Fibonacci. Skew = new param. Fibonacci. Skew(); while(Not. Quit) { // Check each action Not. Quit = askuser(“cycle again”); } } CSE. -IOA-26

CSE 298 CSE 300 Round Robin Scheduler while(Not. Quit) { if(askuser(“set. Ready”)) { ioa.

CSE 298 CSE 300 Round Robin Scheduler while(Not. Quit) { if(askuser(“set. Ready”)) { ioa. Fibonacci. Skew. set. Ready( input. Fibonacci. Skew. Returnflag()); } if(askuser(“skew”)) { ioa. Fibonacci. Skew. skew( input. Fibonacci. Skew. Returnk()); } if(ioa. Fibonacci. Skew. Pre. Calculate()) { ioa. Fibonacci. Skew. calculate(); } if(ioa. Fibonacci. Skew. Preprint()) { ioa. Fibonacci. Skew. print(); } Not. Quit = askuser(“cycle again”); } Input Internal Output CSE. -IOA-27

CSE 298 CSE 300 Future Research m Solving Composition of Automata q Public Composed

CSE 298 CSE 300 Future Research m Solving Composition of Automata q Public Composed IOA Class Approach Ø All classes are in a package Ø Each independent IOA class is private Ø The composed IOA class is public q IOA Class Library Approach Ø All IOAs have their own class in a library Ø Create a new composed IOA importing 2 or more IOA classes from the library Ø Put back composed classes in library and reuse q Combination of Both Ø Package last composition of classes from library q Adapt parser to handle assumes clause CSE. -IOA-28

CSE 298 CSE 300 Future Research m m m Generation of pre-conditions and effects

CSE 298 CSE 300 Future Research m m m Generation of pre-conditions and effects in Java Determining parameters for internal and output actions q Common mechanism for selecting values from state Consider distributed systems modeled by IOA q Interaction in Java q Use of Java distributed technologies CSE. -IOA-29

CSE 298 CSE 300 References m m m MIT-Theory of Distributed Systems Group q

CSE 298 CSE 300 References m m m MIT-Theory of Distributed Systems Group q I/O Automata Model, Language and Tool Set. http: //theory. lcs. mit. edu/tds/~vaziri/ioa. html q S. J. Garland, N. A. Lynch, and M. Vaziri, “IOA: A Language for Specifying, Programming, and Validating Distributed Systems Draft”, December 1997. O. M. Cheiner and A. A. Shvartsman, “Implementing An Eventually-Serializable Data Service as a Distributed System Building Block”, July 1998. Java Compiler - The Java Parser Generator - http: //www. suntest. com/Java. CC/ CSE. -IOA-30

CSE 298 CSE 300 Flow IOA. jj grammar file javacc IOA. java associated Java

CSE 298 CSE 300 Flow IOA. jj grammar file javacc IOA. java associated Java files ioaname. ioa javac Method. Info. java Scheduler. java Parameter. java *. class java Executable IOA ioaname. java ioaname. Scheduler. java paramioaname. java ioaname. Scheduler java *. class javac CSE. -IOA-31