120 likes | 248 Views
This document explores critical concepts in interpreters and compiler design, including interactive interpretations of machine and command languages, recursive interpretation, and the TAM interpreter case study. It delves into the programming language life cycle, focusing on design principles and error reporting during compile-time and run-time. Key topics covered include semantic analysis, type checking, compiler structures like lexical analyzers and symbol tables, as well as optimization techniques and abstract representations. Discover principles of simplicity, regularity, and abstraction essential for effective language design.
E N D
CSC 415: Translators and CompilersSpring 2009 Chapters 8, 9 & Wrap-Up Interpretation & Design Principles
Chapter 8: Interpretation • Interactive Interpretation • Interactive Interpretations of Machine Code • Interactive Interpretation of Command Languages • Interactive Interpretation of Simple Programming Languages • Recursive Interpretation • Case Study: The TAM Interpreter
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
Semantic Analyzer Identification Type checking Structure of a Compiler Lexical Analyzer Source code Symbol Table tokens Semantic Analyzer Parser parse tree Intermediate Code Generation intermediate representation Optimization intermediate representation Assembly Code Generation Assembly code
Programming Language Lifecycle:Concepts • Values • Types • Storage • Bindings • Abstractions • Encapsulation • Polymorphism • Exceptions • Concurrency Concepts Advanced Concepts
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
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
Design Specification Prototype Compilers Manuals, textbooks Programming Language Lifecycle
Specification • Precise specification for language’s syntax and semantics must be written • Informal or formal or hybrid Informal Formal BNF, EBNF Syntax English phrases Axiomatic method (based on mathematical logic) English phrases Semantics
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
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
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