Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 3: Dealing with Objects II.

Slides:



Advertisements
Similar presentations
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 5.
Advertisements

Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 7: References and Assignment.
University of Palestine software engineering department Introduction to data structures Introduction to java application instructor: Tasneem Darwish.
Chapter 1: Introduction
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 2: Dealing with Objects I.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 2: Dealing with Objects I.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Outline Java program structure Basic program elements
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Slide 1 Chapter 2-b Syntax, Semantics. Slide 2 Syntax, Semantics - Definition The syntax of a programming language is the form of its expressions, statements.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
Slide 1 Chapter 3 Attribute Grammars. Slide 2 Attribute Grammars Certain language structures cannot be described using EBNF. Attribute grammars are extensions.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 9: Abstraction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Chapter 1 Introduction.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs.
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.
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
CSCI-383 Object-Oriented Programming & Design Lecture 13.
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
LANGUAGE DESCRIPTION: SYNTACTIC STRUCTURE
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XML.
C H A P T E R TWO Syntax and Semantic.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Introduction to programming in the Java programming language.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
CPS 506 Comparative Programming Languages Syntax Specification.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
ISBN Chapter 3 Describing Syntax and Semantics.
ELEE 4303 Digital II Introduction to Verilog. ELEE 4303 Digital II Learning Objectives Get familiar with background of HDLs Basic concepts of Verilog.
Chapter 3 Context-Free Grammars Dr. Frank Lee. 3.1 CFG Definition The next phase of compilation after lexical analysis is syntax analysis. This phase.
Programming Languages and Design Lecture 2 Syntax Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Copyright 1999 by Larry Fuhrer. Pascal Programming Branching, Loops, Predefined Functions.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Overview of Previous Lesson(s) Over View 3 Model of a Compiler Front End.
Copyright © Curt Hill Other Trees Applications of the Tree Structure.
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.
XML Extensible Markup Language
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Describing Syntax and Semantics
System Software Unit-1 (Language Processors) A TOY Compiler
A Simple Syntax-Directed Translator
C# and the .NET Framework
Chapter 10 Programming Fundamentals with JavaScript
CSE401 Introduction to Compiler Construction
Chapter 1: Computer Systems
Focus of the Course Object-Oriented Software Development
Chapter 10: Compilers and Language Translation
CS313T Advanced Programming language
Presentation transcript:

Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 3: Dealing with Objects II

2 Programming languages The programming language is the notation that defines the syntax and semantics of programs Our programming language is Eiffel There are many programming languages, some “general”, some “specialized” Programming languages are artificial notations, designed for a specific purpose (programming).

3 Object technology Source: Simula 67 language, Oslo, mid-sixties Spread very slowly in seventies Smalltalk (Xerox PARC, 1970s) made O-O hip by combining it with visual technologies First OOPSLA in 1986 revealed O-O to the masses Spread quickly in 1990s through  O-O languages: Objective C, C++, Eiffel, Java, C#...  O-O tools, O-O databases, O-O analysis... Largely accepted today Non O-O approaches are also called “procedural”.

4 About Eiffel First version 1985, constantly refined and improved since Focus: software quality, especially reliability, extendibility, reusability. Emphasizes simplicity Based on concepts of “Design by Contract” Used for mission-critical projects in industry Several implementations, including EiffelStudio from Eiffel Software (the one we use), available open-source International standard: ECMA and ISO (International Standards Organization), 2006

5 Some Eiffel-based projects Axa Rosenberg Investment management: from $2 billion to >$100 billion 2 million lines Chicago Board of Trade Price reporting system Eiffel + CORBA + Solaris + Windows + … Xontech (for Boeing) Large-scale simulations of missile defense Swedish social security: accident reporting & management etc. The Chicago Board of Trade (Eiffel) Price Reporting System

6 So, why use Eiffel?  Simple, clean O-O model  Enables you to focus on concepts, not language  Little language “baggage”  Development environment (EiffelStudio)  Portability: Windows / Linux / VMS & others  Realism: not an “academic” language Prepares you to learn other O-O languages if you need to, e.g. C++, Java, C# Course series (3 rd year and up): “Languages in Depth”. Currently Java, C# and Eiffel.

7 Instructions Basic operations are called instructions Our first example had five instructions: Paris  display Louvre  spotlight Line8  highlight Route1  animate Console  show (Route1  origin)

8 ; ; ; ; You may write them one after the other without semicolons: Paris  display Louvre  spotlight Line8  highlight Route1  animate Console  show (Route1  origin) You may use semicolons to separate them: Paris  display Louvre  spotlight Line8  highlight Route1  animate Console  show (Route1  origin) Successive instructions

9 Style rule If you ever feel it clearer to have more than one instruction on a line (e.g. in a paper report) use semicolons: f (x ) ; g (y) Write one instruction per line Omit semicolons

10 An expression is a program element denoting possible run-time values Examples: Console  show (Route1  origin ) Also, standard mathematical expressions: a + b An expression Expressions An expression

11 In program texts:  An instruction denotes a basic operation to be performed during the program’s execution.  An expression denotes a value used by an instruction for its execution. Definitions

12 Syntax and semantics An expression, e.g. Route1  origin is not a value but denotes future run-time values An instruction, e.g. Paris  display denotes an operation to be executed at run time

13 The syntax of a program is the structure and form of its text The semantics of a program is the set of properties of its potential executions Syntax and semantics Syntax is the way you write a program: characters grouped into words grouped into bigger structures Semantics is the effect you expect from this program

14 Syntax and semantics SyntaxSemantics InstructionCommand ExpressionQuery

15 Feature declaration Class names Comment Feature body Instructions Feature names Syntax structure of a class class PREVIEW inherit TOURISM feature explore -- Show city info. do Paris  display Louvre  spotlight end

16 Programming vs natural languages: similarities  Overall form of texts: succession of words  Distinction between syntax and semantics  Some words predefined, others user-defined

17 Programming vs natural languages: differences  Power of expression much higher with natural languages  Precision much higher in programming languages Programming languages are extensions of mathematical notation Comments are bits of natural language appearing in programs

18 Use words from natural language (e.g. English, German) for the names you define Style rule Examples:  Paris, Route1  Feature names: show, origin Eiffel keywords are English words: inherit, do, end... All single words except elseif

19 Feature declaration Class names Comment Feature body Instructions Feature names Syntax structure of a class class PREVIEW inherit TOURISM feature explore -- Show city info. do Paris  display Louvre  spotlight end

20 Specimens Specimen: a syntactic element; for example:  A class name, e.g. PREVIEW  An instruction, e.g. Paris  display  Any of the boxes on the previous page  The whole class text! Specimens may be nested (or embedded) Delimiters, such as keywords ( do, end,...), semicolons, periods  etc. are not specimens

21 Specimens and constructs A construct is a certain type of syntactic element Every syntactic element is a specimen of a certain construct For example:  display is a specimen of the construct Feature_name  The class text as a whole is a specimen of the construct Class

22 Feature declaration Class names Comment Feature body Instructions Feature names Syntax structure of a class class PREVIEW inherit TOURISM feature explore -- Show city info. do Paris  display Louvre  spotlight end

23 Other representation: abstract syntax tree Class declaration Feature declaration Feature body Inheritance Features of the class Class name Feature name Header comment Instruction (feature call) Instruction (feature call) Target Feature PREVIEW TOURISM explore -- Show city… Paris display Louvre spotlight Root Internal node (Nonterminal) Leaf (Terminal) Class name

24 Abstract syntax tree Shows the syntax structure Specimens only: no keywords or other delimiters (that’s why it’s abstract) Uses the notion of tree as in organizational charts of companies.

25 Trees that grow down...

26 Trees in computer science  Represent hierarchical or nested structures  Similar to e.g. organizational charts (previous page)  Pictured top-down or left-to-right

27 Tree properties Tree rules:  Every branch connects two nodes  Every node can have any number (including none) of outgoing branches  Every node has at most one incoming branch Types of node:  Root: node with no incoming branch  Leaf: node with no outgoing branches  Internal node: neither root nor leaf A tree has exactly one root (Otherwise it would be a forest)

28 Other representation: abstract syntax tree Class declaration Feature declaration Feature body Inheritance Features of the class Class name Feature name Header comment Instruction (feature call) Instruction (feature call) Target Feature PREVIEW TOURISM explore -- Show city… Paris display Louvre spotlight Root Internal node (Nonterminal) Leaf (Terminal) Class name

29 Abstract syntax tree  Root: represents overall specimen (outermost rectangle)  Internal nodes (nonterminals): represent substructures containing specimens themselves  Leaves (terminals): represent specimens with no further nesting  The syntax of a programming language is defined by a set of constructs and the structure of these constructs.

30 Feature declaration Class names Comment Feature body Instructions Feature names Syntax structure of a class class PREVIEW inherit TOURISM feature explore -- Show city info. do Paris  display Louvre  spotlight end

31 The lower level: lexical structure The basic elements of a program text are tokens:  Terminals Identifiers: names chosen by the programmer, e.g. Paris or display Constants: self-explanatory values, e.g 34  Keywords, e.g. class  Special symbols: colon, “  ” of feature calls Tokens define the lexical structure of the language

32 Three levels of description Semantic rules define the effect of programming satisfying the syntax rules Syntax rules define how to make up specimens out of tokens satisfying the lexical rules Lexical rules define how to make up tokens out of characters Rely on Semantic rules Rely on Syntactic rules Lexical rules

33 Identifiers An identifier starts with a letter, followed by zero or more characters, each of which may be: A letter. A digit (0 to 9). An underscore character “_”. Lexical rule for identifiers You may choose your own identifiers as you please, excluding keywords

34 Style rules  Always choose identifiers that clearly identify the intended role  For features, use full names, not abbreviations  For multi-word identifiers, use underscores: bus_station  Use all upper case for classes: PREVIEW

35 One more level Static semantics defines validity rule not captured by syntax For example: Console  show (Route1  origin ) but not: Console  show (show  origin ) (Compare, in English: I see the lake but not e.g. I lake the see) Rely on Semantic rules Syntactic rules Lexical rules Static semantics (validity rules)

36 What we have seen in this lecture  Programming language concepts  Eiffel basics  Syntax (including lexical level) vs semantics  Lexical and static analysis levels  Trees  Tree terminology: root, leaf, node…  Abstract Syntax Trees (AST)  Basic lexical elements  Basic style rules

37 What to do for next week Read chapters 1 to 5 of Touch of Class Make sure you know all the terminology introduced so far