CH 4 - Language semantics

Slides:



Advertisements
Similar presentations
Semantics Static semantics Dynamic semantics attribute grammars
Advertisements

PZ08A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ08A - Prime programs Programming Language Design and.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
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
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 12: Semantic Analysis COMP 144 Programming Language Concepts Spring 2002 Felix.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
PZ02A - Language translation
PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03CX - Language semantics Programming Language Design.
Slide 1 Chapter 3 Attribute Grammars. Slide 2 Attribute Grammars Certain language structures cannot be described using EBNF. Attribute grammars are extensions.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
Describing Syntax and Semantics
PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03A - Pushdown automata Programming Language Design.
1 Lecture 11: Semantic Analysis (Section ) CSCI 431 Programming Languages Fall 2002 A modification of slides developed by Felix Hernandez-Campos.
PZ01A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ01A -- Introduction Programming Language Design and.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
CS 2104 Prog. Lang. Concepts Dr. Abhik Roychoudhury School of Computing Introduction.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
CS 363 Comparative Programming Languages Semantics.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
ISBN Chapter 3 Describing Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
1 Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
LESSON 04.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03A - Pushdown automata Programming Language Design.
PZ03BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03BX - Recursive descent parsing Programming Language.
PZ03BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03BX –Recursive descent parsing Programming Language.
Overview of Previous Lesson(s) Over View 3 Model of a Compiler Front End.
PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03CX - Language semantics Programming Language Design.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Describing Syntax and Semantics
README FILE Programming Languages Design and Implementation
Describing Syntax and Semantics
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Abstract Syntax Trees Lecture 14 Mon, Feb 28, 2005.
Formal Language Theory
Compiler Lecture 1 CS510.
PZ03A - Pushdown automata
CSE 3302 Programming Languages
Syntax Questions 6. Define a left recursive grammar rule.
PZ08A - Prime programs Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section PZ08A.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
PZ04A - Scalar and composite data
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Recursive descent parsing
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Language semantics Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Chapter 10: Compilers and Language Translation
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Lecture 16 Boolean Expressions and Control Flow
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Recursive descent parsing
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Visual Programming Languages ICS 539 Icon System Visual Languages & Visual Programming, Chapter 1, Editor Chang, 1990 ICS Department KFUPM Sept. 1,
PZ03BX - Recursive descent parsing
Presentation transcript:

CH 4 - Language semantics Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 4.1-4.1.2, 4.2-4.2.1 PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Formal Models for Language Properties Formal Grammars – Context-free and Regular Grammars, BNF Provide formal representation of languages Language Semantics – Attribute Grammars and Denotational Semantics, Virtual machine models, and more Allow representation of exact meaning of program elements Program Verification – Formal logic applied to pre- and post-conditions Provides tools and techniques for verifying that a program meets a specification PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Semantics overview Language design has centered on context free grammars (LR(k) grammars). Parsing is not an interesting research question any more. Problem now is how to decide what a program means (semantics). Various approaches have been tried to develop semantic contents of programs. PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Semantic approaches Grammatical models: add extensions to the BNF grammar that defined the language. Given a parse tree for a program,additional information could be extracted from that tree. [e.g., attribute grammars, later] Operational models: define how programs in the language are executed on a virtual computer. Compare that to the actual execution on a real computer. [Vienna Definition Language of the 1970s] Applicative models: construct a definition of the function that each program in the language computes. This definition is built up hierarchically through definition of the function computed by each individual program construct.[Denotational semantics] Axiomatic models: construct a formal logical proof theory to show that a program meets its specifications [to be described later]. Specification model: describe the relationship among the various functions implementing a program PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

An introduction to attribute grammars We will give a brief introduction to attribute grammars to show how these operate. Associate a function with each node in the parse tree of a program giving the semantic content of that node. An inherited attribute is a function that relates nonterminal values in a tree with nonterminal values higher up in the tree (i.e., the functional value for the nonterminals on the right of any rule are a function of the left-hand side nonterminal). A synthesized attribute is a function that relates the left-hand side nonterminal to values of the right-hand side nonterminals. These attributes pass information up the tree (i.e., were synthesized from the information below in the tree). PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Attributes for “value” of an expression Production Attribute E  E+T value(E1) = value(E2)+value(T) E  T value(E) = value(T) T  T*P value(T1) = value(T2)* value(P) T  P value(T) = value(P) P  I value(P) = value(I) P  (E) value(P) = value(E) E1 is first E in production and E2 is second E in production Technique often useful for passing data type information within a parse tree. PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Example attributed tree PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Use of attribute grammars First need to develop parse tree. Attribute grammars assume you already have the derivation; it is not a parsing algorithm. Functions for attributes can be arbitrary. Process to build attributes is mostly manual. If only have synthesized attributes, and if parsing is LR(k), then attribute grammars can be used automatically along with parsing to generate intermediate code. This is how YACC works. Values are computed for each nonterminal. As the parse tree is built, information from one nonterminal is passed to another nonterminal higher in the tree. When parse is completed, all attribute values have already been computed. PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000