Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics.

Similar presentations


Presentation on theme: "Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics."— Presentation transcript:

1 Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics

2 Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Semantics There is no single widely acceptable notation or formalism for describing dynamic semantics Operational Semantics –Describe the meaning of a program by executing its statements on a machine, either simulated or actual. –The change in the state of the machine (memory, registers, etc.) defines the meaning of the statement

3 Copyright © 2006 Addison-Wesley. All rights reserved.1-3 Operational Semantics To use operational semantics for a high-level language, a virtual machine is needed A hardware pure interpreter would be too expensive A software pure interpreter also has problems –The detailed characteristics of the particular computer, to run the pure interpreter, would make actions difficult to understand –Such a semantic definition would be machine- dependent

4 Copyright © 2006 Addison-Wesley. All rights reserved.1-4 Operational Semantics Using the operational method to completely describe the semantics of a programming language L requires the construction of two components: –A translator is needed to translates statements in L to a chosen low-level language. –A virtual machine for that low-level language. The state of the virtual machine because of executing the translated code defines the meaning of the statements. In effect, this approach describes the meaning of high-level language statements in terms of statements in a simpler, low-level language

5 Copyright © 2006 Addison-Wesley. All rights reserved.1-5 Eaxmple The basic process of operational semantics is commonly used in textbooks and programming languages manuals For example, The semantics for the C for statement can be described in terms of very simple statements C StatementsOperational Semantics For (expr1; expr2; expr3) { ….. } exp1; Loop: if expr2 == 0 goto out ….. exp3; goto loop out: …..

6 Copyright © 2006 Addison-Wesley. All rights reserved.1-6 Example A human reader of such a description is the virtual computer and is assumed to be able to correctly execute the operational semantics instructions. So our built virtual machine should be able to execute the code resulted from the translation of the high-level language code.

7 Copyright © 2006 Addison-Wesley. All rights reserved.1-7 Evaluation of Operational Semantics Evaluation of operational semantics: –The first and most significant use of formal operational semantics was to describe the semantics of PL/I. –That particular abstract machine and the translation rules for PL/I were together named Vienna Definition Language (VDL). –An effective means of describing semantics for language implementers as long as it is kept simple and informal. –The VDL description for PL/I was very complex. –The operational semantics depends on programming languages of lower-level, not mathematics. –Other methods that are based on logic and mathematics are Axiomatic and Denotational semantics respectively.


Download ppt "Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics."

Similar presentations


Ads by Google