SlideServe
Menu
Préférences
© SlideServe · v2026

3.2 Semantics

eyal avatar
14 diapositives · 359 Views · Jun 19, 2013

3.2 Semantics . Semantics. Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3. Attribute Grammars. CFG cannot describe all necessary information An attribute grammar is a CFG G = (S, N, T, P) with the following additions:

3.2 Semantics - slide 1
01 / 143.2 Semantics
1 / 17

Télécharger la présentation

3.2 Semantics
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. 3.2 Semantics

  2. Semantics • Attribute Grammars • The Meanings of Programs: Semantics • Sebesta Chapter 3

  3. Attribute Grammars • CFG cannot describe all necessary information • An attribute grammar is • a CFG G = (S, N, T, P) with the following additions: • For each grammar symbol xthere is a set A(x) of attribute values • Each rule has a set of functionsthat define certain attributes of the nonterminals in the rule • Each rule has a (possibly empty) set of predicates to check for attribute consistency

  4. Attribute Grammars (cont.) • Invented by Donald Knuth • Can carry complex syntactic and some semantic information along through parse trees • e.g. complex syntax rule (static semantics): a variable must be defined before it is used • Primary value of AGs: • static semantics specification • compiler design (static semantics checking)

  5. Describing Semantics • There is no single widely accepted notation or formalism for semantics • Different formalisms are used: • Operational Semantics • Axiomatic Semantics • Denotational Semantics

  6. Operational Semantics • Describes the meaning of a program by executing its statements on a machine, either simulated or actual. • The meaning of a statement is defined by the change in the state of the machine (memory, registers, etc.)

  7. Operational Semantics Limitations • A virtual machine is needed • A hardware pure interpreter • too expensive for a high-level language • A software pure interpreter • too difficult to understand the actions because of the detailed characteristics of the particular computer used • machine-dependent

  8. Operational Semantics • A better alternative: A complete computer simulation • The process: • Build a translator which translates source code to the machine code of an idealized computer • Build a simulator for the idealized computer • Evaluation of operational semantics: • Good if used informally (language manuals, etc.) • Extremely complex if used formally (e.g., VDL)

  9. Axiomatic Semantics • Based on formal logic - predicate calculus • Original purpose: formal program verification • Approach: • Define axioms or inference rules for each statement type in the language (to allow transformations of expressions to other expressions) • The expressions are called assertions

  10. Prolog • Prolog – logic programming language • Axiomatic semantics • Contains facts (assertions) • Contains inference rules • Inference process answers a query by generating new facts from known facts and rules • We will learn Prolog in this course to practice the logic programming paradigm

  11. Axiomatic Semantics Evaluation • Good for correctness proofs and for reasoning about programs • Too difficult to develop axioms and inference rules for all of the statements in a high-level language • Too difficult to understand the axioms and rules • It is not very useful for • language design • compiler/interpreter writers • programmers

  12. Denotational Semantics • Based on recursive function theory • The process: • 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 the values of the program's variables • The state changes are defined by mathematical functions • (operational semantics defines them in program code)

  13. Denotational Semantics Evaluation • The most abstract method of describing semantics • Can be used to prove the correctness of programs • Provides a rigorous way to think about programs • Can aid language design • Has been used in compiler generators • Too complex to be useful to programmers

  14. Summary • EBNF is an established formalism to define the syntax of PLs • There is no single commonly used way to define the semantics – all formalisms have disadvantages