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

Slides:



Advertisements
Similar presentations
Semantics Static semantics Dynamic semantics attribute grammars
Advertisements

ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
CS 330 Programming Languages 09 / 19 / 2006 Instructor: Michael Eckmann.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
CS 355 – Programming Languages
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Describing Syntax and Semantics
Concepts of Programming Languages 1 Describing Syntax and Semantics Brahim Hnich Högskola I Gävle
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics.
Slide 1 Chapter 3 Attribute Grammars. Slide 2 Attribute Grammars Certain language structures cannot be described using EBNF. Attribute grammars are extensions.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Compilers and Syntax.
Describing Syntax and Semantics
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Denotational Semantics ICS.
ISBN Chapter 3 Describing Syntax and Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Describing Syntax and Semantics
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 3 Syntax - the form or structure of the expressions, statements, and program units Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Chapter Describing Syntax and Semantics. Chapter 3 Topics 1-2 Introduction The General Problem of Describing Syntax Formal Methods of Describing.
ISBN Chapter 3 Describing Syntax and Semantics.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Course: ICS313 Fundamentals of Programming Languages. Instructor: Abdul Wahid Wali Lecturer, College of Computer Science and Engineering.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
Describing Syntax and Semantics
CS 363 Comparative Programming Languages Semantics.
Muhammad Idrees Lecturer University of Lahore 1. Outline Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute.
ISBN Chapter 3 Describing Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Chapter 3 Describing Syntax and Semantics. Copyright © 2012 Addison-Wesley. All rights reserved. 1-2 Chapter 3 Topics Introduction The General Problem.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
CCSB 314 Programming Language Department of Software Engineering College of IT Universiti Tenaga Nasional Chapter 3 Describing Syntax and Semantics.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
Chapter 3 © 2002 by Addison Wesley Longman, Inc Introduction - Who must use language definitions? 1. Other language designers 2. Implementors 3.
Describing Syntax and Semantics Session 2 Course : T Programming Language Concept Year : February 2011.
Chapter 3 Describing Syntax and Semantics. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 3 Topics Introduction The General Problem.
ISBN Chapter 3 Describing Syntax and Semantics.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Syntax.
Advanced programming language theory. week 2. Attribute grammars and semantics.
Describing Syntax and Semantics
Describing Syntax and Semantics
Describing Syntax and Semantics
Syntax Questions 6. Define a left recursive grammar rule.
Describing Syntax and Semantics
Describing Syntax and Semantics
Describing Syntax and Semantics
Semantics In Text: Chapter 3.
CSCI 3370: Principles of Programming Languages Syntax (cont.)
Chapter 3: Describing Syntax and Semantics Sangho Ha
Describing Syntax and Semantics
Describing Syntax and Semantics
Describing Syntax and Semantics
Describing Syntax and Semantics
Describing Syntax and Semantics
Describing Syntax and Semantics
Describing Syntax and Semantics
Chapter 3 (b) Semantics.
- Who must use language definitions?
Presentation transcript:

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 x there is a set A(x) of attribute values Each rule has a set of functions that 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