150 likes | 351 Views
A Rewriting Logic Approach To Operational Semantics. By Grigore Ro şu , Jos é Meseguer, Traian Florin Şerbănuţă. Motivation. B ecause we like rewriting All operational semantics rules have a “rewriting flavor” … yet, they are completely distinct logics
E N D
A Rewriting Logic Approach To Operational Semantics By Grigore Roşu,José Meseguer, Traian Florin Şerbănuţă
Motivation • Because we like rewriting • All operational semantics rules have a “rewriting flavor” • … yet, they are completely distinct logics • An executable unified logical framework can help in either teaching or research
Previous work • [Meseguer, 1990]: embedding Cham • [Marti-Oliet, Meseguer,1993]: representing Natural semantics and SOS • [Meseguer, Braga, 2004]: MSOS –> modular rewriting semantics • Our paper synthesizes these results
New contributions • Relation with reduction semantics • Faithful representation • Correspondence between transition systems • Representing Abstract Machines • First-order, continuations-like definitions • Here presented as a faithful encoding of Reduction Semantics, but can go beyond that
Rewriting Logic • Extends Equational Logic with transitions • Models: transitions systems between equivalence classes of states • Equations used to canonicalize state • Rules are used for computational steps C C R R’
C C’ R R’ Reduction Semantics
Reduction semantic in Rewriting Logic • Context syntax rules -> a “parser” function • Split a term in a context-redex pair C[R] • Reduction rules stay unchanged • Apply on C[R] a Context Reduction rule • Put redex back in the context • Using a morphism-like function
Continuation based semantics • Transform the program into a list of tasks • Flattening the program to post-order representation • Advantages: • No need to search for the redex • Disadvantages: • More syntax is needed for flattening
Our approach • First-order representation of continuations • Equations flatten the program • If B then E1else E2 = Bif(E1,E2) • Rules specify execution steps • true if(K1,K2) K1 • Provides a way to compactly specify and execute abstract machines for any PL
Implementing RLS specifications • They are executable rewrite theories in Maude (for testing and analysis purposes) • The associated rewrite system is executable in any generic rewrite system • Mechanically generate interpreters for PL with limited support for matching: • Haskell, Ocaml, Prolog
Experiments • Defined Imp, a simple imperative language • Mechanically derived interpreters in Haskell and Ocaml • Compared with existing interpreters defined in Scheme: EOPL (bigstep&continuations) and PLT Redex (Red Semantics) Running time for verifying Collatz’ conjecture up to 300 (times are in seconds) • Ocaml interpreter is comparable in speed to Linux BC (13.8 sec)
Teaching experience • Used in teaching programming languages design and verification at UIUC for 3 years • Students like executable formal definitions • Continuation-based is easy to understand, modular, flexible and fun to teach • Students are able to (partially) define Scheme or Prolog as a class project
Future Work • Make the interpreter generation automatic • Build end-to-end framework for continuation-based definitions • Research other definitional styles in their relation to RLS • Any suggestions?