Upload
alec-travis
View
36
Download
3
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
CSC 415: Translators and CompilersSpring 2009
Chapters 8, 9 & Wrap-UpInterpretation & Design Principles
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
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
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
Chart 5
Programming Language Lifecycle:Concepts
Values Types Storage Bindings Abstractions Encapsulation Polymorphism Exceptions Concurrency
Concepts
Advanced Concepts
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
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
Chart 8
Programming Language Lifecycle
Design
Specification
Prototype
Compilers
Manuals,textbooks
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)
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
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
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