Advanced Topic 49 of 50 Languages & Compilers
Operational and Denotational Semantics
Formal ways of defining program meaning.
How it works
Formal semantics gives precise mathematical meaning to programming languages. Operational semantics describes how programs execute, by defining an abstract machine or inference rules for evaluation steps, either small-step, one reduction at a time, or big-step, evaluating to a final result. Denotational semantics maps each program construct to a mathematical object, such as a function between domains, composing meanings of parts. Axiomatic semantics, like Hoare logic, describes programs by preconditions and postconditions.
Step-by-step walkthrough
- Operational semantics defines meaning by how a program steps from state to state.
- Like an abstract machine rule: running x = 1 changes the state.
- Denotational semantics maps a program to a mathematical object, a function.
- Equivalent programs have the same denotation.
- Both give a precise basis for proofs about languages.
Where it is used
Language specifications, compiler correctness proofs, type-soundness proofs, program verification tools and research on new language features use formal semantics.
Common pitfall
Formal semantics for real languages is large and intricate, so mechanized versions are done only for core subsets. Different styles suit different goals: operational for implementation and proofs of progress and preservation, denotational for equational reasoning. Handling features like concurrency and undefined behavior is hard. Learn by defining a tiny language and its evaluation rules.
Where it fits in the course
Operational and Denotational Semantics is topic 49 of 50 in Languages & Compilers, rated Advanced. It follows Domain-Specific Languages. The next topic is Language Interoperability.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Languages & Compilers quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Languages & Compilers quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Operational and Denotational Semantics?
Where do people use Operational and Denotational Semantics?
What is the most common mistake with Operational and Denotational Semantics?
What should I learn before this topic?
How can I practice it?
Is Operational and Denotational Semantics hard to learn?
How long does it take to learn Operational and Denotational Semantics?
Which topics are related to Operational and Denotational Semantics?
What should I study after Operational and Denotational Semantics?
Related topics
- Domain-Specific Languages (Languages & Compilers)
- Language Interoperability (Languages & Compilers)
- Garbage Collection Algorithms (Languages & Compilers)
- Linear and Affine Types (Languages & Compilers)