UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Names and Bindings.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
ISBN Chapter 3 Describing Syntax and Semantics.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
Concepts of Programming Languages 1 Describing Syntax and Semantics Brahim Hnich Högskola I Gävle
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
The Concept of Variables
Copyright © 1995 by Addison-Wesley Publishing Co. 1 Names - Design issues: - Maximum length? - Are connector characters allowed? - Are names case sensitive?
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Fall 2004 Marco Valtorta
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.1 Spring 2010 Marco Valtorta
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
1 Syntax and Semantics The Purpose of Syntax Problem of Describing Syntax Formal Methods of Describing Syntax Derivations and Parse Trees Sebesta Chapter.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
Grammars CPSC 5135.
3-1 Chapter 3: Describing Syntax and Semantics Introduction Terminology Formal Methods of Describing Syntax Attribute Grammars – Static Semantics Describing.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
C H A P T E R TWO Syntax and Semantic.
Course: ICS313 Fundamentals of Programming Languages. Instructor: Abdul Wahid Wali Lecturer, College of Computer Science and Engineering.
Basic Semantics Associating meaning with language entities.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Muhammad Idrees Lecturer University of Lahore 1. Outline Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute.
CPS 506 Comparative Programming Languages Syntax Specification.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Language Translation A programming language processor is any system that manipulates programs expressed in a PL A source program in some source language.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
April 2, ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)
ISBN Chapter 3 Describing Syntax and Semantics.
 Fall Chart 2  Translators and Compilers  Textbook o Programming Language Processors in Java, Authors: David A. Watts & Deryck F. Brown, 2000,
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
C H A P T E R T W O Syntax and Semantic. 2 Introduction Who must use language definitions? Other language designers Implementors Programmers (the users.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Chapter 3 – Describing Syntax
Describing Syntax and Semantics
Names and Attributes Names are a key programming language feature
Type Checking, and Scopes
Chapter 3 – Describing Syntax
Midterm Review In Text: Chapters 1, 2, 3, 5, 15.
Final Review In Text: Chapters 1-3, 5-11,
Midterm Review In Text: Chapters 1-3, 5, 15.
CSE 3302 Programming Languages
Final Review In Text: Chapters 1-3, 5-10, 12,
Final Review In Text: Chapters 1-3, 5-10, 12,
Midterm Review In Text: Chapters 1, 2, 3, 5, 15.
Final Review In Text: Chapters 1-3, 5-10,
CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics
Midterm Review In Text: Chapters 1-3, 5-10, 15.
Final Review In Text: Chapters 1-3, 5-12,
Chapter 3 Describing Syntax and Semantics.
Midterm Review In Text: Chapters 1-3, 5-11, 15.
Types and Related Issues
Presentation transcript:

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005 Marco Valtorta

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Syntax and Semantics Syntax is the set of rules that specify the composition of programs from letters, digits and other characters. Semantics is the set of rules that specify what the result/outcome of a program is. Problems with English language description of Syntax and Semantics: –verbosity –ambiguity

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Syntax What is syntax? –syntax vs. lexical rules –Regular languages and context-free languages Backus Normal Form (a.k.a. Backus-Naur Form)BNF –A syntax metalanguage –Derivation vs. recognition –Syntax Diagram –Extended BNF (EBNF)

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering BNF History In Java: ::= if ( ) else

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Recursive Descent Parsing Parsing is the process of constructing a parse tree A recursive descent parser is a kind of leftmost parser with very limited lookahead Recursive descent parsers are built directly from (E)BNF rules Recursive descent parsers do not work with left- recursive grammars We provide a simple example for parsing terms made of factors

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering The Concept of Binding entities (e.g., variables, statements, subprograms, declarations...) have attributes (e.g., for variable: name, type, storage area) Binding is the specification of the exact nature of an attribute. When does binding occur? Binding time. –language definition time –language implementation time –compile time –run time Example: the Fortran type INTEGER is bound partly at language definition time, partly at language implementation time. static (established before run-time, cannot be changed) and dynamic binding

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Variables Name Scope Lifetime Value –l-value (memory location) and r-value (contents of a memory location) Type

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Variable Scope Variables have scope: the range of program instructions over which the variable is known, and therefore manipulable –scope binding can be static or dynamic –dynamic scoping is easy to implement, but more confusing for most programmers –most modern languages use static scoping

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Variable Type type is the range of values a variable can take, together with operations to create, access, and modify values variable type declarations –implicit in FORTRAN, explicit almost in any other language –dynamic binding between variables and types is unusual APL and SNOBOL4 have it

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Variable Value binding of variable and value is dynamic, except for symbolic constants Algol v. Pascal: manifest constants reference (pointer) access path (chain of pointers) –primary means of accessing anonymous variables shared objects

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Semantics (So-called) Static Semantics –Context-Sensitive Grammars Scope and Type –Attribute Grammars Operational Semantics Denotational Semantics Axiomatic Semantics

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Previewing Postscript In this course, most notes from the instructor are in Postscript format –Postscript previewers are installed on the departmental Unix machines »“gv is available on all solaris machines” (P. O’Keefe) –and on the College Windows machines »“GSView is located in all of the prototype machines. I copied the shortcuts in cse apps folder” (H. Naik) –a link to obtaining PostScript previewers is provided on the course web site. It points (indirectly) to

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Static Semantics Static semantics are used to check type and scope rules Semantics is a misnomer in this context We provide only an example –for checking the type rules of the variable and expression in the assignment statement of a simple language –using attribute grammars (which are a formalization of contextual grammars)

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Declarations, Expressions, Commands A command is executed to update variables and perform I/O An expression is evaluated to yield a value A declaration is elaborated (at compile time) to produce bindings. It may also have the side effect of allocating and initializing variables

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Axiomatic, Denotational, and Operational Semantics Axiomatic semantics formalizes language commands by describing how their execution causes a state change. The state is formalized by a first-order logic sentence. The change is formalized by an inference rule Denotational semantics associates each language command with a function from the state of the program before execution to the state after execution Operational semantics associates each language command to a sequence of commands in a simple abstract processor