Download No Slide Title - University of Connecticut

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CSE298
CSE300
IOA
PRESENTATION
May 01, 1999
CSE.-IOA-1
CSE298
CSE300
IOA2JAVA 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
CSE298
CSE300
Input/Output Automata
Process
init(v1)
P1
Channel
decide(v1)
send(m(1,2))
C(1,2)
receive(m(1,2))
receive(m(2,1))
C(2,1)
send(m(2,1))
init(v2)
P2
decide(v2)
CSE.-IOA-3
CSE298
CSE300
Structure of an IOA

Main components of an I/O Automaton(A):
 sig(A), a signature
 states(A), a set of states
 start states
 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

optional tasks
CSE.-IOA-4
CSE298
CSE300
Objectives

Create a tool to convert the general structure of an
IOA to Java code
 IOA can be used for algorithm correctness
proofs
 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
 Code will run on one machine



CSE.-IOA-5
CSE298
CSE300
Assumptions

Action names, parameters, and state variables are
unique

Deal only basic data types
 boolean
 double
 int

Preconditions and effects written as Java Code
 May change state variables so long as same
names are used
 Code copied directly to Java class
CSE.-IOA-6
CSE298
CSE300
Assumptions


Internal and output actions have no parameters
 Parameters values selected by IOA code in
preconditions based on state
 A large enough subset of IOA is not yet
implemented to do this
Changes to IOA code in parser
 All keywords have the first letter capitalized ie.
Automaton, Transition, etc.
 Some symbols were changed to accommodate
the keyboard ie. E - There exist.
 Java types were used instead of IOA types- this
eliminated the need for a symbol table.
 Type checking done by the Java Compiler.
CSE.-IOA-7
CSE298
CSE300
Java Compiler Compiler

Compiler Tool for Java Language.
 The Java equivalent of Lex and Yacc
 Parses grammar to produce Java code

JavaCC uses an input file written in a standard
BNF grammar.
 Example of simple BNF grammar

<exp> :: = <simp exp> <rel op> <simp exp>

<rel op> :: =
< | >= | <= | = | >
CSE.-IOA-8
CSE298
CSE300
Compiler Procedure

Get the tokens
 The first part of the JCC specification defines
the tokens for the language.

Parse the Language
 The second part defines the transitions that
make up the language.

Generate the code
 The compiler output is generated by the
insertion of Java code in the transitions.
CSE.-IOA-9
CSE298
CSE300
IOA Tokens


IOA Token definitions.

< AUTOMATON: “Automaton” >

< TRANSITION: “Transition” >

< INPUT: “Input” >

< OUTPUT: “Output” >
Resulting Java code is too complicated to put here,
looks like assembly language.
CSE.-IOA-10
CSE298
CSE300
IOA grammar to JavaCC grammar

IOA grammar specification translates directly into
JCC grammar because of similarity in structures.

states ::= ‘states’ state,+ (‘so’ ‘that’ predicate)?






void states() :
{}
{
<STATES> state()(“,” state())*
(<SO> <THAT> predicate())?
}
CSE.-IOA-11
CSE298
CSE300
Translation of Grammar Cont’d

JavaCC grammar with Java code inserted to create
the IOA compiler.

states ::= ‘states’ state,+ (‘so’ ‘that’ predicate)?









void states() :
{}
{
{String lTokStr;}
<STATES> lTokStr = state()
{pwOutput.println(lTokStr);}
("," lTokStr = state()
{pwOutput.println(lTokStr);})*
( <SO> <THAT> predicate())?
}
CSE.-IOA-12
CSE298
CSE300
Java file which implements the Parser

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
ParseException {

String lTokStr;

jj_consume_token(STATES);

lTokStr = state();

System.out.println(lTokStr);

label_12:

while (true) {

if (jj_2_38(2)) { ;

CSE.-IOA-13
CSE298
CSE300
Differences in Grammars

JCC does not permit left recursion and hence two
transitions have to be modified.

For example, A  C | AB is a transition with left-recursion.

The equivalent transition A  CB+ does not contain left recursion
and can be used in a JavaCC grammar file.
 subterm ::= subterm (opSym subterm)+

| (quantifier | opSym)* opSym secondary

| (quantifier | opSym)* quantifier primary

| secondary opSym*
CSE.-IOA-14
CSE298
CSE300
Left Recursion Removed
 String subterms() :
 {}
 {
 subterm() (opSym() subterm())*
 }








String subterm() :
{}
{
( ((quantifier() | opSym())* secondary())
| ((quantifier() | opSym())* quantifier() primary())
| ( secondary() (opSym())*)
)
}
CSE.-IOA-15
CSE298
CSE300
The FibonacciSkew IOA


What does it do?
 Produces the Fibonacci sequence
 The sequence can be skewed by a certain value
from time to time
States
 ready indicate state of sequence generation
 skew value
 printFlag indicates print state
 first, second, current holding last three
sequence values
CSE.-IOA-16
CSE298
CSE300
The FibonacciSkew IOA

Actions in the IOA
 Input action to start or end the sequence
 Input action to skew the sequence
 Internal action that calculates the next value in
the sequence
 Output action that prints the next value
CSE.-IOA-17
CSE298
CSE300
The FibonacciSkew IOA
calculate
setReady
skew
FibonacciSkew
print
Input Action
Internal Action
Output Action
CSE.-IOA-18
CSE298
CSE300
IOA States to Private Data

IOA States
automaton FibonacciSkew
states
ready: boolean := false;
skew: int := 0;
printFlag: boolean := false;
first: int := 1;
sec: int := 0;
current: int := 0;

Private Data in Java Class
class FibonacciSkew {
// Private Data
private boolean ready = false;
private int skew = 0;
private boolean printFlag = false;
private int first = 1;
private int sec = 0;
private int current = 0;
// Public Methods
};
CSE.-IOA-19
CSE298
CSE300
Input Action to Public Method

IOA Input Action
input setReady(flag: boolean)
eff $
if (ready!=flag) {
ready = flag;
first = 1;
sec = 0;
current = 0;
}
$

Public Method in Java Class
public void setReady(boolean flag) {
if (ready!=flag) {
ready = flag;
first = 1;
sec = 0;
current = 0;
}
}
CSE.-IOA-20
CSE298
CSE300
Input Action to Public Method

IOA Input Action
input skew(k: int)
eff $
if (ready==true)
skew = k;
else
System.out.println(“Cannot skew: No sequence is
being generated”);
$

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
CSE298
CSE300

IOA Internal Action

Public Methods in Java Class
internal calculate()
pre $
return (ready);
$
eff $
current = first + second + skew;
skew = 0;
first = sec;
sec = current;
printFlag = true;
$
public boolean Precalculate() {
return (ready);
}
public void calculate() {
current = first + second + skew;
...
}
CSE.-IOA-22
Internal and Ouput Actions to Public
Methods
CSE298
CSE300

IOA Output Action
output print()
pre $
return (printFlag);
$
eff $
System.out.println(“The current value in sequence
is “ + current);
printFlag = false;
$

Public Methods in Java Class
public boolean Preprint() {
return (printFlag);
}
public void print() {
System.out.println(“The current value in sequence
is “ + current);
printFlag = false;
}
CSE.-IOA-23
CSE298
CSE300
IOA Input Parameters

paramFibonacciSkew.java
 Created by Parameter.java
 Simulates input parameter values for input
actions coming in from environment

IOA Input Action parameter
input setReady(flag: boolean)

Public Java method for each parameter
public boolean returnflag()
{
input = getInput(“flag”);
return retboolean(input);
}
CSE.-IOA-24
CSE298
CSE300
Helper Methods

Methods for converting String to type value
private boolean retboolean(String s)
{
return Boolean.valueOf(s).booleanValue();
}

Method to get any parameter value from user
public String getInput(String message)
{
String response = “”;
System.out.println(“Enter “ + message);
try {
BufferedReader brInp.readLine();
response = brInp.readLine();
}
catch(Exception e){
e.printStackTrace();
}
return response;
}
CSE.-IOA-25
CSE298
CSE300
IOA Scheduler

FibonacciSkewScheduler.java
 Created by Scheduler.java
 Contains main program which calls a round
robin scheduler to cycle through actions
public static void RoundRobin()
{
boolean NotQuit;
FibonacciSkew ioaFibonacciSkew = new FibonacciSkew();
paramFibonacciSkew inputFibonacciSkew =
new paramFibonacciSkew();
while(NotQuit)
{
// Check each action
NotQuit = askuser(“cycle again”);
}
}
CSE.-IOA-26
CSE298
CSE300
Round Robin Scheduler
while(NotQuit)
{
if(askuser(“setReady”))
{
ioaFibonacciSkew.setReady(
inputFibonacciSkew.Returnflag());
}
if(askuser(“skew”))
{
ioaFibonacciSkew.skew(
inputFibonacciSkew.Returnk());
}
if(ioaFibonacciSkew.PreCalculate())
{
ioaFibonacciSkew.calculate();
}
if(ioaFibonacciSkew.Preprint())
{
ioaFibonacciSkew.print();
}
NotQuit = askuser(“cycle again”);
}
Input
Internal
Output
CSE.-IOA-27
CSE298
CSE300
Future Research

Solving Composition of Automata
 Public Composed IOA Class Approach
 All classes are in a package
 Each independent IOA class is private
 The composed IOA class is public

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

Combination of Both
 Package last composition of classes from library

Adapt parser to handle assumes clause
CSE.-IOA-28
CSE298
CSE300
Future Research



Generation of pre-conditions and effects in Java
Determining parameters for internal and output
actions
 Common mechanism for selecting values from
state
Consider distributed systems modeled by IOA
 Interaction in Java
 Use of Java distributed technologies
CSE.-IOA-29
CSE298
CSE300
References



MIT-Theory of Distributed Systems Group
 I/O Automata Model, Language and Tool Set.
http://theory.lcs.mit.edu/tds/~vaziri/ioa.html
 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 Compiler - The Java Parser
Generator - http://www.suntest.com/JavaCC/
CSE.-IOA-30
CSE298
CSE300
Flow
IOA.jj
grammar
file
javacc
IOA.java
associated
Java files
ioaname.ioa
javac
MethodInfo.java
Scheduler.java
Parameter.java
*.class
java
Executable
IOA
ioaname.java
ioanameScheduler.java
paramioaname.java
ioanameScheduler
java
*.class
javac
CSE.-IOA-31