Making Maude Definitions more Interactive Andrei Arusoaie 1 a 1 , 2 - - PowerPoint PPT Presentation

making maude definitions more interactive
SMART_READER_LITE
LIVE PREVIEW

Making Maude Definitions more Interactive Andrei Arusoaie 1 a 1 , 2 - - PowerPoint PPT Presentation

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Making Maude Definitions more Interactive Andrei Arusoaie 1 a 1 , 2 Traian Florin S erb anut Chucky Ellison 2 su 2 Grigore Ro 1 University Alexandru


slide-1
SLIDE 1

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work

Making Maude Definitions more Interactive

Andrei Arusoaie1 Traian Florin S ¸erb˘ anut ¸˘ a1,2 Chucky Ellison2 Grigore Ro¸ su2

1University Alexandru Ioan Cuza of Ia¸

si

2University of Illinois at Urbana-Champaign

March 28, 2012

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 1/20

slide-2
SLIDE 2

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work

Introduction Motivation Adding I/O to Maude Scenario Our solution Maude I/O Interface Architecture How it works in K Conclusions and Future Work

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 2/20

slide-3
SLIDE 3

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Motivation

Plan

Introduction Motivation Adding I/O to Maude Scenario Our solution Maude I/O Interface Architecture How it works in K Conclusions and Future Work

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 3/20

slide-4
SLIDE 4

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Motivation

Motivation

Defining programming languages in the K framework

In the K-Framework you can . . .

◮ . . . give operational semantics to a programming language. ◮ . . . run your semantics over programs defined in your language.

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 4/20

slide-5
SLIDE 5

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Motivation

Motivation

Defining programming languages in the K framework

In the K-Framework you can . . .

◮ . . . give operational semantics to a programming language. ◮ . . . run your semantics over programs defined in your language.

  • However. . .

◮ . . . Most programming languages are interactive ◮ . . . Requiring support for I/O in the framework.

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 4/20

slide-6
SLIDE 6

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Motivation

Current status of I/O in Maude

◮ read-eval-print loop from LOOP-MODE standard module

. . . may not be maintained in future versions, because the support for communication with external objects makes it possible to develop more general and flexible solutions for dealing with input/output in future releases. [Maude Manual]

◮ External objects?

◮ Currently, only socket communication is supported Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 5/20

slide-7
SLIDE 7

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Motivation

In this paper

◮ Achieve interactive I/O executions within Maude ◮ Using the socket external object to emulate an I/O external

  • bject.

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 6/20

slide-8
SLIDE 8

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

Plan

Introduction Motivation Adding I/O to Maude Scenario Our solution Maude I/O Interface Architecture How it works in K Conclusions and Future Work

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 7/20

slide-9
SLIDE 9

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

Scenario - Simple Expression Language

mod EXP−SYNTAX is including INT . including STRING . sort Exp . subsort Int < Exp .

  • p _+_ : Exp Exp →Exp [ditto] .
  • p _∗_ : Exp Exp →Exp [ditto ] .

endm

  • p _ifnz_ : Exp Exp → Exp [strat(2 0)] .
  • p nzloop : Exp → Exp [strat (0)] .
  • p input : String → Exp .
  • p print : String Exp → Exp .

nzloop(print("3∗x=",3 ∗ input("x= (0 to stop)? ")))

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 8/20

slide-10
SLIDE 10

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

Scenario - Simple Expression Language

mod EXP−SYNTAX is including INT . including STRING . sort Exp . subsort Int < Exp .

  • p _+_ : Exp Exp →Exp [ditto] .
  • p _∗_ : Exp Exp →Exp [ditto ] .

endm

  • p _ifnz_ : Exp Exp → Exp [strat(2 0)] .
  • p nzloop : Exp → Exp [strat (0)] .
  • p input : String → Exp .
  • p print : String Exp → Exp .

nzloop(print("3∗x=",3 ∗ input("x= (0 to stop)? ")))

mod EXP−BASIC−SEMANTICS is including EXP−SYNTAX . eq nzloop(E:Exp) = nzloop(E:Exp) ifnz E:Exp . eq E:Exp ifnz 0 = 0 . eq E:Exp ifnz NzI:NzInt = E:Exp . endm

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 8/20

slide-11
SLIDE 11

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

Scenario - Simple Expression Language

mod EXP−SYNTAX is including INT . including STRING . sort Exp . subsort Int < Exp .

  • p _+_ : Exp Exp →Exp [ditto] .
  • p _∗_ : Exp Exp →Exp [ditto ] .

endm

  • p _ifnz_ : Exp Exp → Exp [strat(2 0)] .
  • p nzloop : Exp → Exp [strat (0)] .
  • p input : String → Exp .
  • p print : String Exp → Exp .

nzloop(print("3∗x=",3 ∗ input("x= (0 to stop)? ")))

mod EXP−BASIC−SEMANTICS is including EXP−SYNTAX . eq nzloop(E:Exp) = nzloop(E:Exp) ifnz E:Exp . eq E:Exp ifnz 0 = 0 . eq E:Exp ifnz NzI:NzInt = E:Exp . endm

Problem: How to give semantics to input/print?

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 8/20

slide-12
SLIDE 12

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

Our solution

J a v a I / O S e r v e r

SOCKET

Maude + I/O Java Maude wrapper

◮ Maude’s SOCKET external objects allow interaction ◮ We use this interaction to provide:

◮ a general client/server infrastructure to deal with I/O ◮ a “friendly” Maude interface to access this infrastructure Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 9/20

slide-13
SLIDE 13

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

Executing Scenario

$ cat io-test-cmd.maude erew nzloop(print("3∗x=",3 ∗ input("x= (0 to stop)? "))) . $ java -jar MaudeIO.jar --maudeFile io-test.maude

  • -commandFile io-test-cmd.maude

x= (0 to stop)?

  • 12

3∗x=-36 x= (0 to stop)? 3∗x=0 Maude> ========================================== erewrite in KRUNNER : nzloop(print("3∗x=", 3 ∗ input("x= (0 to stop)? "))) . rewrites: 6487 in 45ms cpu (53780ms real) (141396 rewrites/second) result Zero: Maude> Bye.

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 10/20

slide-14
SLIDE 14

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

Maude Client

#fReadToken #fPrintString #fEof #fOpen ...

IO-INTERFACE

<<uses>>

#tcpRequest ("readbyte#0#") “success” #readInt() #printString #eof ...

STANDARD-IO

#start #toSend #TCPPORT #containedRequest ...

TCP-CLIENT

#tcpRequest #errorTCPSyntax #checkResult #getTCPData ...

TCP-INTERFACE

“97” response: 315#success# #tcpRequest ("writebyte#0#97#")

<<uses>>

request: 315#writebyte#1#97# response: 315#success#97# request: 315#readbyte#0# SOCKET

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 11/20

slide-15
SLIDE 15

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

STANDARD-IO Interface

Basic console I/O operations

  • p #printString : String → IOResult .
  • p #readInt() : → IOResult .
  • p #eof() : → IOResult .
  • p #printChar : Char → IOResult .
  • p #readChar() : → IOResult .
  • p #readToken() : → IOResult .

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 12/20

slide-16
SLIDE 16

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

IO-INTERFACE

I/O operations

  • p #open : String → IOResult .
  • p #reopen : Nat String → IOResult .
  • p #close : Nat → IOResult .
  • p #fEof : Nat → IOResult .
  • p #flush : Nat → IOResult .
  • p #tell : Nat → IOResult .
  • p #seek : Nat Nat → IOResult .
  • p #fPeekByte : Nat →IOResult .
  • p #fReadByte : Nat →IOResult .
  • p #fPutByte : Nat Nat →IOResult .
  • p #fPrintChar : Nat Char → IOResult .
  • p #fReadChar : Nat →IOResult .
  • p #fReadToken : Nat →IOResult .
  • p #fReadInt : Nat → IOResult .
  • p #fPrintString : Nat String →

IOResult .

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 13/20

slide-17
SLIDE 17

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

An I/O semantics for EXP

mod EXP−SEMANTICS is including EXP−BASIC−SEMANTICS . including STANDARD−IO .

  • p _;_ : IOResult Exp → Exp [strat (1 0)] .
  • p read : → Exp .

eq input(S:String) = #printString(S:String); #readInt(); read . eq print(S:String ,I: Int) = #printString(S:String + string(I: Int ,10) + "\n"); I: Int . eq #success ; E:Exp = E:Exp . eq #int(I:Int) ; read = I . endm

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 14/20

slide-18
SLIDE 18

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work Scenario Our solution Maude I/O Interface Architecture

Java I/O Server

RequestManager ResourceManager

invalid request valid request Create task

Thread pool

... Task queue ... T T T Threads concurrent hashmap create

  • p

e n delete

concurrent hashmap interface

request request request response response response

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 15/20

slide-19
SLIDE 19

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work

Plan

Introduction Motivation Adding I/O to Maude Scenario Our solution Maude I/O Interface Architecture How it works in K Conclusions and Future Work

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 16/20

slide-20
SLIDE 20

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work

The K definition of EXP

EXP-SYNTAX

module EXP−SYNTAX syntax Exp ::= #Int | Exp "+" Exp [strict hook(#INT:_+Int_)] | Exp "∗" Exp [strict hook(#INT:_∗Int_)] | Exp "ifnz" Exp [strict(2)] | "nzloop" Exp [prec 0] | "input" "(" #String ")" | "print" "(" #String "," Exp ")" [strict(2)] end module

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 17/20

slide-21
SLIDE 21

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work

The K definition of EXP

EXP-SEMANTICS

module EXP imports EXP−SYNTAX configuration k $PGM:Exp /k in stream="stdin" .List /in

  • ut stream="stdout" .List /out

syntax KResult ::= #Int rule nzloop E:Exp = > (nzloop E) ifnz E rule _ ifnz 0 = > 0 rule E:Exp ifnz I:#NzInt = > E rule k print(Str:#String,I:#Int) = > I ···/k

  • ut··· .

= > ListItem(Str) ListItem(I) ListItem("\n") /out syntax Exp ::= "read" rule k input(Str:#String) = > read ···/k

  • ut··· .

= > ListItem(Str) /out rule k read = > I ···/k in ListItem(I:#Int) = > . ···/in end module

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 18/20

slide-22
SLIDE 22

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work

Plan

Introduction Motivation Adding I/O to Maude Scenario Our solution Maude I/O Interface Architecture How it works in K Conclusions and Future Work

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 19/20

slide-23
SLIDE 23

Introduction Adding I/O to Maude How it works in K Conclusions and Future Work

Conclusions and Future Work

◮ Run interactive programs ◮ Direct access from Maude to stdin, stdout, stderr, and

files

◮ A “friendly” interface ◮ Extensions: allow access to more URI-specified streams

Andrei Arusoaie, Traian Florin S ¸erb˘ anut ¸˘ a, Chucky Ellison, Grigore Ro¸ su Making Maude Definitions more Interactive 20/20