Beruflich Dokumente
Kultur Dokumente
Kokirhi Futatsugi,
of OBJ21
1 Introduction
tcquirtlmrnt.s
that actual modules must satisfy before they
can be meaningfully substituted. This can prevent many
subt,lc bugs. An unusual feature of ORJ2 is the commands
that it provides for modifying and combining program
modules; thus, (a form of) program transformation is
ptovidcd wit,hin t,he language itself. A key principle here is
the systemat,ic use of module expressions
for describing
and cresting
compIcx combinations of modules; see Section
2.5. This provides a level above that of conventional
programming
Isngun.ges,
in which previously written code
is dc>sctibrd by theories, and also is manipulated by module
cxprc*ssions
to product new code.
1.X Modules
1.2 Subsorts
and Generics
Government
(Ada
0-89791-l47-4/85/001/0052
some
(tccovety),
pntt.inlly
inheritance
(in
vcty
operations,
Aowevct,
s0rt.s
contain
(or
thus
OBJ2
are
also permits
contained
the
defined
sense
operations,
and
of object-oriented
1.3 Implementation
and
elegant
code
for
standard
ADTs
like
Techniques
Joint
Permission
to copy without fee all or part of this material is granted
provided
that the copies are not made or distributed
for direct
commercial
advantage,
the ACM copyright
notice and the title of the
publication
and its date appear, and notice is given that copying
is by
permission
of the Association
for Computing
Machinery.
ho copy
otherwise,
or to republish, requires a fee and/or specific permission.
O1984 ACM
and
that
multiple
programming);
l-1-4 Umtwmo,
Sakura, Niihari,
performed
white on leave at SRI.
sorts
ADTs.
handling
wtitx
Laboratory,
work
own
defined
in part by
Elrctrotechnical
lbaraki 305. Japan;
t,hcir
user
USP~S to dcclste
introduce
supporting
5
Hereafter
we gencralty use the word .sort
instead of .lype,
Wing to avoid confusion among Ihe many different
ways that type
has been used (major exceptions
are use or the word typechecking
and of the phrase sbst:act
data type?. abbreviated
ADT).
$00.75
52
2.1 Objects:
and Flexibility
obj BITS is
erhding
NAT .
sorts Bit Bite
ops 0 1 : -> Bit .
.
op nil : -> Bite
_,_
:
Bit
Bits
-> Bite .
OP
op length: Bite -> Nat .
var B : Bit .
vat S : Bite .
eq: length nil = 0 .
eq : length B . S = inc length
and Semantics
olws
basic c*llhly is the object,
which is a module
(possibly psr:~mrt~+cd) c,ncnpsulating cxccutabfe code;
ohjrcts gcnrralfy introdtlcc
new sorts of data and new
opc!rat.ions upon that (131.3.An object. hns three main parts:
(t ) a header, conta.ining its name, parameters, interface
rrquircmcnts, and importctl motl~~lclist.; (2) a signature,
declaring its new sorts, subsort rc*lnt.ionships, and
operations; and (3) a body, containing its code, consisting
of equations and sort constraints (t.hrsc are descrihcd in
Section 3.1). The following BITS object introduces two
new sorts Bit and Bite (for Bit lists) with scme relevant
opcrat.ions; these fists have a S-expression-like syntax with .
and nil. Ot3J2keywords and keysymbols are in italics.
Syntax
S .
endo
and Generice
The only t.op level OBJ2 entities are modules (which are
either objects or theories) and views (which relate theories
to modules, see Section 2.4); objects contain executable
code, while theories contain noncxccutabfe assertions.
Thus, executable code and nonexecutable assertions are
both modularized, and are c!osely integrated with each
other. Moreover, the mathematical semantics of theories
and objects is elegantly unified since both are data
theories in the sense of [lS]; there is not space for details
here, but the essential intuition is that the notion of theory
generalizes to permit regarding certain subtheories as
objects (i.e., they have initial interpretations) while others
may have any interpretation.
53
2.3
Parameterleed
th POSET is
BOOL .
protecting
2.2 Hierarchy
sort Elt
of Modules
op
c
: Elt Elt -> Baa1 .
var;EF.'
E" : Elt .
eq : E < E = false
.
ceq : E < E" = true
if(EcEmdE
<Egg)
endth
Ih TRIV is
aoft Elt
endth
54
jbo
2.6 Module
Expressions
55
L) .
jbo
3.1 Partial
Operationa
and Sort
Constraints
SYMROLTARLEia
ID .
INT .
:= STACKpmLE/ID, INT] +
(sort Int to Lot, serf Table to Layer)].
eztending
ezfending
dfn Env
LIST/% :: TRIV] ie
sorts NeLiet List .
subsorts
Elt < Nstist < List .
op nil
: -, List *
op
: NoList NeList -> NeList [assoc]
op--:
Liet Liet -> List [t18soc id: nil]
op 62
: NeLiet -> Elt .
op tail
: NeList -> Lirt
.
zrar L : NeList .
zInr E : Elt .
e9 : hradQ L) = E .
e9: tailCELl
=L
.
obj
jbo
jbo
3 Subeorta
since a
Assuming that the order-sorted equations in E are ChurchDossrr, it, turns out that new cquat.ions may have to be
ntldcd to E* in order to gctt an equivalent set of ChurchRossrr standard c~quations [2G]. Thus OBJ2 performs a
spcrializrd Knufh-Ucndix completion 10 on the equations
E*. ISvrn whcbnan operation hns hern declared associative
(or .zssoriat.ivc-ronlmutativo) for both a subsort s and a
supcrsort s, we can shill do rewriting modulo associativity
(or asso~iativily-comt~1~~tn.t.ivit.y)with the completed E+
using a st.andnrd associative (or associative-commutative)
rnat,ching algorithm 1261. Ilowevcr, the correctness of this
last. reduction is rather subtle, since the associativity
axioms at t,he two levels in&act with morphism equations
to grnrrnte additional equations having an associative
flavour.
us NeStack :
pu8hCE.S) i/ length(S)
< bound .
eq : lsngth(empty)
= 0 .
eq : length(push(E,S))
= inc length(S)
cq : top purh(E, S> = E .
eq : pop pueh(E, S) = S .
jbo
3.3 Error
Handling
and Recovery
10
57
Principles
Interpreter
Generator
command specification
;open keys
,*cl080 keys
;body part
;rubcommand procraring
;exit function
fa
;;;dubconunand specification
for top lrvrl
(th-obj -view&
;fn name for subcommand
0
;init
in for rubcommand
(prompt)
;prompt aprc
(* ((th theory)
;opm key8 for th coamand
(endt sndth ht) ;closr key8 for th command
The real OB2 syntax is more complex, since communication with
the reduction engine, file system, editor (Emacs),and Mac&p
evaluator also occur at the top level.
58
(vielw%rx) 1)
0)
; OIit
;fioal
view
in for
in for
command
Command
rubcommand
View
rubcommand
co-d
command
command
command
[assoc comm/
[assoc comm 11
a
-> Int .
[aesoc comm]
[asaoc comm l]
.
A - A - A - A1
A (*error*
A - A
(-AA)
(-AA))
(*error*
A - A A - A - A) with
A (- A A))
(- A A) A)
and Module
4.4 Rewrite
with parses
- A>)
A) A)
parses
Expression
Rule Engine
Evaluator
60
(I X) + Y .
61
Present
and Future
62
NATO
Summer
School,
6th International
Conference
on Software
6 References
1981 Marktoberdorj
Reidel, 1982.
Description
of Programming
Concepts, MIT,
1877.
63
239-266.
34. Huet, G. and Oppen, D. Equations and Rewrite
Rules: A Survey. In Formal Language Theory:
Perspectives and Open Problems, R. Book., Ed.,Academic
Press, 1980.
7th Conference
on Au tomated Deduction,
64
GortsCmd?
<>SortKsy>...-3
OBJ2
BNF
This appendix does not use italics for keywords, nor tloc~sit
give syot,ax for cvnluation, file m;~nipul:r.t.ion, etc.
Syntactic
Conventions
nonterminal
symbole
alternative
separator
exp.. .
one or more expll
one or more exps separated by .;
:&;
zero or one exp. except that {{.)3
indicates
either period or <cr>
choice of exactly one of el,...,en
631 ,...,sn3
exp in one line; i.e.,
no <cr>
{-wt..3
parentheses for syntactic
grouping
(sxp)
of expressions
.(. .).
parentheses ae terminal symbols
--- text <cr> comment
<Name>
I
Theory
and Object
<<.33
7 Appendix:
::= {sort,eorts,so)
Commands
<VariableeCmd>
::=
{var,vare>
<VarName>...
: <Sort> {{.I>
<SortConetrCmd>
::= as <Sort> :
<SortExp> if cCondition>
<SortExp> ::= <SimpleTerm>
--- <SimpleTerm> is an expression composed Only
--- of one operator symbol and variable8
(e.g..
--- push Elm to Stack, add Elm to Set, etc.)
<Condition> ::= <Term>
<ModExp> .
<ProtectingCmd> ::= {protecting,pr)
cModExp> .
<ExtendingCmd> ::= {rxtsnding,rx)
<UeingCmd> ::= GW.ng,us) <ModExp> .
65
aakecmd> : := bke,mk3
-------
cObjNams> la
ir squvolent to
obj CObjNames ir wing
<ModExp> . rndo
View Commands
<ViewName> of cObjName>
<ViewCmd> ::= <vr,vier3
a8 <ThName> ie CVierPartCmd>...
~endv,endvier,endvr,wv3
<VierPartCmd> ::= <SortPairCmd> I <VariablerCmd>
I <OpExpCmd>
<Sort> to <Sort>
<SortPairCmd> ::= <ro,eort3
<OpExPairCmd> ::= ~op,operator,operation3
{<<Sort>33 : <opExp> to
<<<Sort>33 : <Term> .
copFxp> : ;= <SimpleTerm>
Module
Expressions
QdodExp, : := <ModName>
I <ModName> [ <ModExp>, . . . ]
I <ModExp> <Rename>
I (04odExp> +) . . . <ModExp>
<Rename> ::= * . ( (<RenamePartCmd><{. 33) . . . 1
--- Ml + M2 * (op f to g)
--- should be parsed as
--- Ml + 042 * cop f to g))
CRenamePartCmd> ::= <SortPsirCmd> I <OpPairCmd>
<SortRenameCmd> ::= {so,rort3
<Sort> to <SortKey>
<OpRenameC!md>::= Cop,operator,opsration~
<Operator> to (~<OpF~rm>)~
<Operator> : := (<OpForm>) l
I l (.. (.<OpForm>) :
<(<Arity>33
-> <CoArity>8)
---------
66