COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 1, 08/28/03 Prof. Roy Levow
Introduction Compiler is a program that translates –Source Language into –Traget Language – and is written in an Implementation Language
Compiler Organization Compiler is divided into 3 main stages –Front-end for Analysis –Semantic Representation & Processing –Back-end for Synthesis (see fig. 1.2 & 1.4)
Compiler vs Interpereter (1) Compiler produces “machine” code –Extensive processing of source code –Target machine specific target code –Fast execution (see fig. 1.3)
Compiler vs Interpereter (2) Interpreter executes source code –Generates intermediate representation –Software interpretation of code –Slower execution (see fig. 1.3)
Why Study Compilers 1.Analysis-Synthesis Paradigm 2.Application of Formalism 3.Use of Program Generating Tools 4.Techniques applicable to other programs 5.Useful algorithms 6.Develop programming skills
Abstract Syntax Tree Syntax Tree –Tree representation of syntax of program –Also called Parse Tree (see fig. 1.5)
Abstract Syntax Tree (2) Abstract Syntax Tree (AST) –Simplification that preserves key elements (see fig. 1.6) Annotated AST –Adds Attributes to nodes for Context handling (see fig. 1.7)
Demo Compiler Grammar for Sample Language Fully parenthesized experssions Operands one digit only Operators: + * (see fig. 1.9)
Structure of Demo Compiler Dual target (back end) –Machine language –Interpreter (see fig. 1.8) Main program calls –Parser (Front-end) –Process (Back-end) (see fig. 1.10)
Demo Lexical Analysis Classify input character as –Self, Digit, EOF Create Token struct (see fig. 1.11) get_next_token() –Skip white space –Classify character (see fig. 1.12)