12
CSC 415: Translators and Compilers Spring 2009 Chapters 8, 9 & Wrap- Up Interpretation & Design Principles

CSC 415: Translators and Compilers Spring 2009

Embed Size (px)

DESCRIPTION

CSC 415: Translators and Compilers Spring 2009. Chapters 8, 9 & Wrap-Up Interpretation & Design Principles. Chapter 8: Interpretation. Interactive Interpretation Interactive Interpretations of Machine Code Interactive Interpretation of Command Languages - PowerPoint PPT Presentation

Citation preview

Page 1: CSC 415:  Translators and Compilers Spring 2009

CSC 415: Translators and CompilersSpring 2009

Chapters 8, 9 & Wrap-UpInterpretation & Design Principles

Page 2: CSC 415:  Translators and Compilers Spring 2009

Chart 2

Chapter 8: Interpretation

Interactive Interpretation– Interactive Interpretations of Machine Code– Interactive Interpretation of Command

Languages– Interactive Interpretation of Simple

Programming LanguagesRecursive InterpretationCase Study: The TAM Interpreter

Page 3: CSC 415:  Translators and Compilers Spring 2009

Chart 3

Chapter 9: Conclusion

The Programming Language Life Cycle– Design– Specification– Prototype– Compilers

Error Reporting– Compile-time Error Reporting– Run-time Error Reporting

Efficiency– Compile-time Efficiency– Run-time Efficiency

Page 4: CSC 415:  Translators and Compilers Spring 2009

Chart 4

Structure of a Compiler

Lexical Analyzer

Parser

Intermediate Code Generation

Optimization

Assembly Code Generation

Symbol Table

Source code

Assembly code

tokens

parse tree

intermediate representation

intermediate representation

Semantic Analyzer

Semantic Analyzer

Identification

Type checking

Page 5: CSC 415:  Translators and Compilers Spring 2009

Chart 5

Programming Language Lifecycle:Concepts

Values Types Storage Bindings Abstractions Encapsulation Polymorphism Exceptions Concurrency

Concepts

Advanced Concepts

Page 6: CSC 415:  Translators and Compilers Spring 2009

Chart 6

Programming Language Lifecycle:Simplicity & Regularity

Strive for simplicity and regularity– Simplicity: support only the concepts essential

to the applications for which language is intended

– Regularity: should combine those concepts in a systematic way, avoiding restrictions that might surprise programmers or make their task more difficult

Page 7: CSC 415:  Translators and Compilers Spring 2009

Chart 7

Design Principles

Type completeness: no operation should be arbitrarily restricted in the types of its operands

– Operations like assignment and parameter passing should, ideally, be applied to all types

Abstraction: for phrase that specifies some kind of computation, should be a way to abstract that phrase and parameterize it

– Should be possible to abstract any expression and make it a function

Correspondence: for each form of declaration there should be corresponding parameter mechanism

– Take a block with a constant definition and transform it into as procedure (or function) with a constant parameter

Page 8: CSC 415:  Translators and Compilers Spring 2009

Chart 8

Programming Language Lifecycle

Design

Specification

Prototype

Compilers

Manuals,textbooks

Page 9: CSC 415:  Translators and Compilers Spring 2009

Chart 9

Specification

Precise specification for language’s syntax and semantics must be written

– Informal or formal or hybrid

Syntax

Semantics

Informal Formal

English phrases

English phrases

BNF, EBNF

Axiomatic method (based on mathematical logic)

Page 10: CSC 415:  Translators and Compilers Spring 2009

Chart 10

Prototypes

Cheap, low quality implementation Highlights features of language that are hard to

implement Try out language

– Interpreter might be a ghood prototype– Interpretive compiler

From source to abstract machine code

Page 11: CSC 415:  Translators and Compilers Spring 2009

Chart 11

Compile-Time Error Reporting

Rejecting ill-formed programs Report location of each error with some

explanation Distinguish between the major categories of

compile-time errors:– Syntactic error: missing or unexpected characters or

tokens Indicate what characters or tokens were expected

– Scope error: a violation of the language’s scope rules Indicate which identifier was used twice, or used with

declaration– Type error: a violation of the language’s type rule

Indicate which type rule was violated and/or what type was expected

Page 12: CSC 415:  Translators and Compilers Spring 2009

Chart 12

Run-Time Error Reporting

Common run-time errors– Arithmetic overflow– Division by zero– Out-of-range array indexing

Can be detected only at run-time, because they depend on values computed at run-time