15
April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages Programming Languages (ICE 1341) (ICE 1341) Lecture #12 Lecture #12 April 2, 2004 In-Young Ko iko .AT. i cu . ac.kr Information and Communications University (ICU)

April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

Embed Size (px)

Citation preview

Page 1: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Programming LanguagesProgramming Languages(ICE 1341)(ICE 1341)

Lecture #12Lecture #12 April 2, 2004

In-Young Koiko .AT. icu.ac.kr

Information and Communications University (ICU)

Page 2: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 2 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

AnnouncementsAnnouncements

The The project #1project #1 is due by midnight today is due by midnight today Please submit your project report to F607Please submit your project report to F607

The The midterm exammidterm exam will be on: will be on:

April 9April 9thth, 1:00PM-3:00PM, L401, 1:00PM-3:00PM, L401 It’s It’s closed-bookclosed-book and and closed-noteclosed-note The exam will cover: The exam will cover: Chapter 1, Chapter 3 Chapter 1, Chapter 3

(except 3.5.3), Chapter 5, Chapter 6 (except 3.5.3), Chapter 5, Chapter 6 (except 6.9.9), Chapter 7(except 6.9.9), Chapter 7

Page 3: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 3 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Review of the Previous LectureReview of the Previous Lecture

Arithmetic ExpressionsArithmetic Expressions Operator Evaluation RulesOperator Evaluation Rules Side EffectsSide Effects Overloaded OperatorsOverloaded Operators Short-Circuit EvaluationShort-Circuit Evaluation

Assignment StatementsAssignment Statements Mixed-mode AssignmentMixed-mode Assignment

Page 4: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 4 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Control StructuresControl Structures

Control Structure: a Control Structure: a control statementcontrol statement and the and the statements whose execution it controlsstatements whose execution it controls Selection StatementsSelection Statements Iterative StatementsIterative Statements Unconditional BranchingUnconditional Branching Guarded CommandsGuarded Commands

Levels of Control FlowLevels of Control Flow Within expressionsWithin expressions Among program statementsAmong program statements Among program unitsAmong program units

Page 5: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 5 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Selection StatementsSelection Statements

SSelection election SStatementtatement: a: a means of choosing between means of choosing between two or more paths of executiontwo or more paths of execution

Two general categoriesTwo general categories: : Two-way selectorsTwo-way selectors, , Multiple-Multiple-way selectorsway selectors

Design IssuesDesign Issues of Two-way Selectors of Two-way Selectors What is the form and type of the control expression?What is the form and type of the control expression? How are the How are the thenthen and and elseelse clauses specified? clauses specified? How should the meaning of nested selectors be specified?How should the meaning of nested selectors be specified?

if (sum == 0)if (sum == 0)if (count == 0)if (count == 0) result = 0;result = 0;

elseelseresult = 1;result = 1;

IF (SUM .NE. 0) GOTO 10IF (SUM .NE. 0) GOTO 10 IF (COUNT .NE. 0) GOTO 20IF (COUNT .NE. 0) GOTO 20 RESULT = 0RESULT = 0 GOTO 20GOTO 2010 RESULT = 110 RESULT = 120 CONTINUE20 CONTINUE

Page 6: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 6 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Nested SelectorsNested Selectors

ALGOL 60ALGOL 60 –– disallow disallow direct nestingdirect nesting

if ... thenif ... then beginbegin if ...if ...tthen ...hen ... endend else ...else ...

JavaJava –– elseelse goes goes with the with the nearestnearest ififif ... if ...

if ... if ... else ...else ...

FORTRAN 90FORTRAN 90 and and AdaAda – closing special words– closing special words

if ... thenif ... then if ... then ...if ... then ... end ifend if else ...else ... end ifend if

Page 7: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 7 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Review of Chapters for Review of Chapters for the Midterm Examthe Midterm Exam

Page 8: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 8 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Review of Chapter 1Review of Chapter 1

Programming DomainsProgramming Domains Programming ParadigmsProgramming Paradigms Language Evaluation CriteriaLanguage Evaluation Criteria

ReadabilityReadability Factors Factors WritabilityWritability Factors Factors ReliabilityReliability Factors Factors

Imperative LanguagesImperative Languages Overview of Language ProcessorsOverview of Language Processors

Page 9: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 9 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Review of Chapter 3 - SyntaxReview of Chapter 3 - Syntax

Syntax vs. SemanticsSyntax vs. Semantics Language RecognizersLanguage Recognizers vs. vs. Language GeneratorsLanguage Generators Formal ways to define language syntaxFormal ways to define language syntax

Context-free GrammarContext-free Grammar Chomsky HierarchyChomsky Hierarchy BNF (Backus Naur Form), EBNFBNF (Backus Naur Form), EBNF DerivationsDerivations Parse TreesParse Trees

Ambiguity in GrammarsAmbiguity in Grammars Operator PrecedenceOperator Precedence Associativity of OperatorsAssociativity of Operators

Attribute GrammarsAttribute Grammars

Page 10: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 10 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Review of Chapter 3 - SemanticsReview of Chapter 3 - Semantics

Operational SemanticsOperational Semantics: states of a : states of a machinemachine

Axiomatic Semantics: Axiomatic Semantics: preconditionspreconditions, , postconditionspostconditions, , weakest preconditionsweakest preconditions Axiom of AssignmentAxiom of Assignment Rules of ConsequenceRules of Consequence Rules of CompositionRules of Composition Rules of SelectionRules of Selection Rules of IterationRules of Iteration

Page 11: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 11 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Review of Chapter 5 –Review of Chapter 5 –Names and BindingsNames and Bindings

Design Issues for NamesDesign Issues for Names SSextuple of extuple of AAttributesttributes for Names for Names:: ((namename, ,

addressaddress, , valuevalue, , typetype, , lifetimelifetime, and , and scopescope)) Binding TimesBinding Times Type Bindings: Type Bindings: Static Type Bindings, Dynamic Static Type Bindings, Dynamic

Type Bindings, Type InferenceType Bindings, Type Inference Binding Lifetimes: Static, Binding Lifetimes: Static, Stack-Dynamic, Stack-Dynamic,

Explicity Heap-Dynamic, Implicit Heap-DynamicExplicity Heap-Dynamic, Implicit Heap-Dynamic Type Compatibility: Type Compatibility: Name Type Compatibility, Name Type Compatibility,

Structure Type Compatibility, Derived Types, Structure Type Compatibility, Derived Types, Subtypes, Anonymous TypesSubtypes, Anonymous Types

Page 12: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 12 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Review of Chapter 5 –Review of Chapter 5 –Scope RulesScope Rules

Variable VisibilityVariable Visibility Nested Static ScopesNested Static Scopes

Program BlocksProgram Blocks Problems in Static ScopingProblems in Static Scoping

Dynamic ScopesDynamic Scopes Scope and LifetimeScope and Lifetime Reference EnvironmentsReference Environments: a set of : a set of visiblevisible names names Named Constants: Named Constants: static (manifest) or dynamic static (manifest) or dynamic

constantsconstants Variable InitializationVariable Initialization

Page 13: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 13 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Review of Web-based LanguagesReview of Web-based Languages

WWW Concepts: WWW Concepts: Universal Readership, Universal Readership, Hypertext, Client-Server Model, Searching, Hypertext, Client-Server Model, Searching, Format NegotiationFormat Negotiation

Extended Markup Language (XML)Extended Markup Language (XML) Basic language componentsBasic language components XML Processors: XML Parsers, Document Type XML Processors: XML Parsers, Document Type

Declaration (DTD), XML Schema (XSD), eXtensible Declaration (DTD), XML Schema (XSD), eXtensible Stylesheet Language (XSL)Stylesheet Language (XSL)

Document Object Model (DOM)Document Object Model (DOM)

Page 14: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 14 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Review of Chapter 6Review of Chapter 6

Associative ArraysAssociative Arrays Record TypesRecord Types Union Types: Union Types: Free Unions, Discriminated Free Unions, Discriminated

UnionsUnions Pointer TypesPointer Types

Dangling PointersDangling Pointers Lost Heap-Dynamic Variables (Garbage, Memory Lost Heap-Dynamic Variables (Garbage, Memory

Leaks)Leaks) Reference Types (Aliasing)Reference Types (Aliasing)

Page 15: April 2, 2004 1 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko Programming Languages (ICE 1341) Lecture #12 Programming Languages (ICE 1341)

April 2, 2004 15 ICE 1341 – Programming Languages (Lecture #12) In-Young Ko

Review of Chapter 7Review of Chapter 7

Arithmetic Expressions: Arithmetic Expressions: Unary Operators, Binary Unary Operators, Binary Operators, Ternary OperatorsOperators, Ternary Operators

Operator Evaluation RulesOperator Evaluation Rules Operator Precedence RulesOperator Precedence Rules Operator Associativity RulesOperator Associativity Rules

Operand Evaluation OderOperand Evaluation Oder Side EffectsSide Effects

Overloaded OperatorsOverloaded Operators Type Conversions: Type Conversions: Narrowing, Widening, Coercion, Narrowing, Widening, Coercion,

Type CaseingType Caseing Short-Circuit EvaluationShort-Circuit Evaluation Types of Assignment StatementsTypes of Assignment Statements