Docsity

Programming Languages Chapter 3: Semantics 2025~2026, Exams of Semantics of Programming Languages

Toggle sidebar
bg1
Programming Languages Chapter 3:
Semantics 2025~2026
Axiomatic Semantics
*Based on formal....
*Original purpose:......
*Axioms or inference rules are defined for....
*The logic expressions are.... - ANS • Based on formal logic (predicate calculus)
• Original purpose: formal program verification
• Axioms or inference rules are defined for each statement type in the language (to
allow transformations of logic expressions into more formal logic expressions)
• The logic expressions are called assertions
Axiomatic Semantics (continued)
*An assertion before a statement states the......
*An assertion following a....
*A weakest precondition is the least.... - ANS • An assertion before a statement (a
precondition ) states the relationships and constraints among variables that are true at
that point in execution
• An assertion following a statement is a postcondition
• A weakest precondition is the least restrictive precondition that will guarantee the
postcondition
Denotational Semantics - ANS • Based on recursive function theory
• The most abstract semantics description method
• Originally developed by Scott and Strachey (1970)
Denotational Semantics (continued)
pf3
pf4
pf5

Partial preview of the text

Download Programming Languages Chapter 3: Semantics 2025~2026 and more Exams Semantics of Programming Languages in PDF only on Docsity!

Programming Languages Chapter 3:

Semantics 2025~

Axiomatic Semantics *Based on formal.... *Original purpose:...... *Axioms or inference rules are defined for.... *The logic expressions are.... - ANS • Based on formal logic (predicate calculus)

  • Original purpose: formal program verification
  • Axioms or inference rules are defined for each statement type in the language (to allow transformations of logic expressions into more formal logic expressions)
    • The logic expressions are called assertions Axiomatic Semantics (continued) *An assertion before a statement states the...... *An assertion following a.... *A weakest precondition is the least.... - ANS • An assertion before a statement (a precondition ) states the relationships and constraints among variables that are true at that point in execution
  • An assertion following a statement is a postcondition
  • A weakest precondition is the least restrictive precondition that will guarantee the postcondition Denotational Semantics - ANS • Based on recursive function theory
  • The most abstract semantics description method
  • Originally developed by Scott and Strachey (1970) Denotational Semantics (continued)

*The process of building a denotational specification for a language -Define a mathematical.... -Define a function that maps instances of the..... *The meaning of language constructs are defined by...... - ANS • The process of building a denotational specification for a language:

  • Define a mathematical object for each language entity
  • Define a function that maps instances of the language entities onto instances of the corresponding mathematical objects
  • The meaning of language constructs are defined by only the values of the program's variables Evaluation of Axiomatic Semantic *Developing axioms or inference rules for..... *It is a good tool for correctness proofs, and an excellent framework for.... *Its usefulness in describing the meaning of a programming..... - ANS • Developing axioms or inference rules for all of the statements in a language is difficult
  • It is a good tool for correctness proofs, and an excellent framework for reasoning about programs, but it is not as useful for language users and compiler writers
  • Its usefulness in describing the meaning of a programming language is limited for language users or compiler writers Evaluation of Denotational Semantics -can be used to prove..... -provide a rigorous way to.... -can be an aid to.... -Has been used in..... -Because of its complexity... - ANS • Can be used to prove the correctness of programs
  • Provides a rigorous way to think about programs
  • Can be an aid to language design
  • The process:
    • Build a translator (translates source code to the machine code of an idealized computer)
  • Build a simulator for the idealized computer Operational Semantics (continued) *Uses of operational semantics -Language..... -Teaching.... *Evaluation -Good if used.... -Extremely complex if.... - ANS • Uses of operational semantics
  • Language manuals and textbooks
  • Teaching programming languages
    • Evaluation
    • Good if used informally (language manuals, etc.)
    • Extremely complex if used formally (e.g.,VDL Operational Semantics Example Look at slides in notes JonJon (slide 10) - ANS .... Semantics -Semantics is a precise definition of the meaning.... -3 approaches of defining semantics (what are they) - ANS Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. 3 approaches to defining semantics:
  1. Operational Semantics 2. Axiomatic Semantics 3. Denotational Semantics Semantics *Early Language Design -A syntactically correct program in a particular language could..... -The language's run-time..... -Different compilers translated a program.... - ANS • Early Language Design
  • A syntactically correct program in a particular language could behave differently when run with the same input on different platforms
  • The language's run-time behavior (semantics) was not defined precisely enough
  • Different compilers translated a program to non-equivalent machine language versions Semantics *There is no single widely acceptable notation or..... *Several needs for a methodology and notation for semantics -Programmers need to.... -Compilers writers must know...... -Correctness proofs.... -Compiler generators would..... -Designers could detect..... - ANS • There is no single widely acceptable notation or formalism for describing semantics
  • Several needs for a methodology and notation for semantics:
  • Programmers need to know what statements mean
  • Compiler writers must know exactly what language constructs do
  • Correctness proofs would be possible
  • Compiler generators would be possible
  • Designers could detect ambiguities and inconsistencie