Forms of Semantic Speci Cation

Forms of Semantic Speci Cation

THE LOGIC IN COMPUTER SCIENCE COLUMN by Yuri GUREVICH Electrical Engineering and Computer Science Department University of Michigan Ann Arb or MI USA Forms of Semantic Sp ecication Carl A Gunter UniversityofPennsylvania The way to sp ecify a programming language has b een a topic of heated debate for some decades and at present there is no consensus on how this is b est done Real languages are almost always sp ecied informally nevertheless precision is often enough lacking that more formal approaches could b enet b oth programmers and language implementors My purp ose in this column is to lo ok at a few of these formal approaches in hop e of establishing some distinctions or at least stirring some discussion Perhaps the crudest form of semantics for a programming language could b e given by providing a compiler for the language on a sp ecic physical machine If the machine archi tecture is easy to understand then this could b e viewed as a way of explaining the meaning of a program in terms of a translation into a simple mo del This view has the advantage that every higherlevel programming language of any use has a compiler for at least one machine and this sp ecication is entirely formal Moreover the sp ecication makes it known to the programmer how eciency is b est achieved when writing programs in the language and compiling on that machine On the other hand there are several problems with this technique and I do not knowofany programming language that is really sp ecied in this way although Im told that such sp ecications do exist First of all the purp ose of a higherlevel programming language is usually to provide some mediation b etween the waya programmer would liketoprovide instructions and the way a machine needs to have them If the programmer is forced to think of the meanings of his programs in terms of how they will b e compiled then most of the advantage of having a higherlevel language is lost Second a description of how to compile the language on architecture X may not b e convenient for understanding the b est way to compile it for architecture Y The temptation would b e to simulate X on Y but this may not b e ecient and an attempt to implementitby some more direct means must cop e with the question of what are the invariants that must b e preserved Table ALGOL semantics for assignments Examples s p n n s n n A BC v q S S v k arctan s zeta V QY Z Semantics Assignment statements serve for assigning the value of an expression to one or several variables or pro cedure identiers Assignment to a pro cedure identier may only o ccur within the b o dy of a pro cedure dening the value of a function designator cf section The pro cess will in the general case b e understo o d to take place in three steps as follows Any subscript expressions o ccurring in the left part variables are evaluated in sequence from left to right The expression of the statementisevaluated The value of the expression is assigned to all the left part variables with any subscript expressions having values as evaluated in step For this the X compiler alone will provide no clue One approach to resolving this problem is to give a compiler for the language to an abstract machine rather than a physically existent piece of hardware If this abstract machine is cleverly chosen then it may b e p ossible to simulate it on a wide range of concrete actual machines in an acceptably ecient manner This will aid the p ortability of the language and if the abstract machine is easy to understand it will free implementers from the need to deal with a p ossibly more complex compilation for a machine they do not need to know ab out Moreover a programmer could safely think in terms of the abstract machine and still write ecient programs Now the notion of an abstract machine could corresp ond to just ab out anything but the nature of this ob jective suggests that an abstract machine must b e fairly similar to the architectures on whichitistobeimplemented In short an abstract machine is a least common denominator for the class of machines over whichitis an abstraction The problem with abstract machines therefore is that they may b e abstract enough for some but still to o lowlevel for others Every programmer who uses a higherlevel language must understand its semantics at some level of abstraction A compiler for an abstract machine is likely to b e hard to understand in detail even for the clearest language and simplest abstract machine Hence programmers ordinarily understand the semantics Table Syntax for a simple imp erative programming language I identier N numeral B true j false j B and B j B or B j not B j EE j E E E N j I j E E j E E j E E jE C skip j C C j I E j if B then C else C j while B do C od of a language through examples intuitions ab out the underlying machine mo del and some kind of informal semantic description By way of illustration an excerpt from one such sp ecication app ears in Figure The example is taken from page of the Algol revised rep ort Nau and describ es the semantics of the assignment statements in that language The example is not chosen to p ointoutany particular strength or failing of such informal semantic descriptions but merely to give a go o d example of one In the b est circumstances an exp erienced programmers intuition ab out the meanings of the phrases lls in any omissions in the description and it can b e viewed as a simple succinct and readable account of the meanings of language constructs Atworst however the description can b e fatally ambiguous or misleading and programming errors or compiler implementation errors could result Research in the semantics of programming languages has sought to nd alternatives to lowlevel abstract machines and informal unrigorous semantic descriptions One of the earliest ideas for another approachwas that of a metacircular evaluator in which the meaning of a language construct of language L is explained in terms of an interpreter written in language L itself Such a program can b e illuminating but it cannot explain all of the details ab out the semantics of the language and must therefore serve as an auxiliary form of semantic description Another somewhat idealistic approach to the semantics of a programming language is to see it as a vo cabulary for describing elements of a mathematical mo del For example a program mightbeviewed as a term in an algebra with an appropriate signature and mo delled by a standard choice of algebra having that signature Ideas such as this date back to the late s but b efore discussing it in more detail I would liketolookata more recent form of sp ecication The syntax for a simple language app ears in Table The semantics of the language could no doubt b e describ ed quite clearly using computerese but it is not much harder to givea formal semantics for this language Our semantics will b e dened in terms of an abstract representation of a machine memory as an assignmentofinteger values to identiers of the language mem identier Z Assume that semantic functions for arithmetic expressions and b o olean expressions are al ready known B mem ftrue falseg E mem Z It can b e assumedfor the sake of uniformitythat these semantic functions were also dened by a means similar to that b eing used here for commands The meaning C ofa command C will b e dened as a partial function from mem input to mem output We will dene the semantic function in terms of a concept of a machine conguration consisting of a p ossibly empty control part and a data part representing the current memory More preciselya conguration is either a pair C s consisting of a command C and a memory sor a memory s Rules for evaluating a program of the simple imp erative language are given in terms of a binary relation on congurations this is dened to b e the least relation that satises the rules in Table In the transition rules for assignment the evaluation of the command results in a new memory in whichthevalue asso ciated with the identier I is b ound to the value of the expression E in memory s The notation used there is dened as follows for a value n Z n if I J snI J sJ otherwise Now let b e the transitive closure of the relation that is is the least transitive relation that contains Lemma If s and s for a conguration then s s The meaning of a program C can now b e dened by s if C s s C s undened otherwise where the symbol is b eing used rather than to emphasize that C isa partial function whichmay b e undened on some memories s Table Transition semantics for a simple imp erative programming language skips s C s C s C C s C C s C s s C C s C s I E s sE sI if B then C else C s C s if B s true if B then C else C s C s if B s false while B do C ods s if B s false while B do C ods C while B do C ods if B s true This semantic description now gives rise to a set of equations b etween programs if we take C to b e equivalentto C when C C It is a virtue of this equivalence that it ignores imp ortant asp ects of a program such as its eciency It is this separation of concerns that makes it p ossible to develop a theory of program transformations we could not saywhen the replacement of one program by another is legitimate without saying what prop ertyisto b e preserved under such a replacement The form of semantics I have just describ ed is usually called a structural operational semantics or SOS It is sometimes also called a Plotkin style op erational semantics b ecause of an

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    16 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us