Docsity

Compilers, Interpreters and Program Analyzers - Lecture Slides | CS 4240, Assignments of Computer Science

Partial preview of the text

Download Compilers, Interpreters and Program Analyzers - Lecture Slides | CS 4240 and more Assignments Computer Science in PDF only on Docsity!

cs4240 Compilers, Interpreters

and Program Analyzers

http://www.cc.gatech.edu/classes/AY2005/cs4240_fall

•^

Ada Gavrilovska - ada@cc, 226C

•^

TA: Guru Prasadh Venkatarmani – guru@cc

•^

textbook:^ – Modern Compiler Implementation in ML

by Andrew W. Appel ML for the Working Programmer, 2nd Edition by Lawrence. C. Paulson

•^

grading:^ – Midterm (25%), Final (30%)^ – Projects (45%), late policy – 10%/day for 3 days (calendar day)

Class syllabus

• Part I of Appel Textbook • Select topics from Part II • Series of Programming Assignments

– each assignment different phases of a compiler – final result compiler for the – assignments roughly match Chapters in Part I

Phases of a Compiler and Interfaces between them

Environs

Lex

Parse

ParsingActions

Source Program

Tokens

Reductions

Tables SemanticAnalysis Abstract Syntax

Translate Translate^ Frame^ FrameLayout

Canon-icalize IR Trees

InstructionSelection IR Trees

Assem

ControlFlow Assem Analysis

DataFlowAnalysis

RegisterAlloc

CodeEmission

Assembler

Flow Graph

Interface Graph

Linker

Register Assignment

Assembly Language

Relocatable Object Code

Machine Language

-^

abstractions– context-free grammar (for parsing)

-^

context-free grammar:

a grammar in which the left-hand side

of each production consists of a single nonterminal symbol.

  • regular expressions (for lexical analysis) -^

regular expression:

an algebraic expression that denotes a

regular language – recognizable by a finite automaton,

e.g.

a

simple item such as a variable name or a number in aprogramming language.

-^

during compilation – intermediate representationsof the program which often take form of a treewith multiple nodes– can be described with grammars– tree representations more easy to manipulate than

source code

a := 5 + 3; b := (print(a, a – 1), 10 * a); print( b )

each node has as manychildren as the correspondinggrammar production hasright-hand-side symbols

type

id=string

datatype

binop

Plus

Minus

Times

Div

datatype

stm

CompoundStm

of

stm

stm

|^

AssignStm

of

id

exp

|^

PrintStm

of

exp

list

and

exp

IdExp

of

id

|^

NumExp

of

Int

|^

OpExp

of

exp

binop

exp

|^

Eseq

of

stm

exp

Grammar

type

Stm

stm

Exp

exp

ExpList

exp list

id

id

num

int

Vocabulary

lexical: 1.

refers to information associated with words or symbols in a dictionary or symbol table.

refers to information that can be determined by static examination

of a program,

i.e.

, at compile time, without running the program.

lexical analysis:

parsing and conversion to internal form of the simplest elements of a

language, usually specified by a regular grammar, such as variable names,numbers, etc. parser:

a program that determines how a given statement in a language could be derived from the grammar of the language, producing a parse tree or otherinformation about the statement as output. parser generator:

a program that constructs a parser from a specification of the

grammar of a language and actions that are to be taken when phrases of thelanguage are recognized. parse tree:

a data structure that shows how a statement in a language is derived from

the context-free grammar of the language; it may be annotated with additionalinformation,

e.g.

for compilation purposes.

parsing:

the process of reading a source language, determining its structure, and producing intermediate code for it. semantics:

the meaning of a statement in a language.

cf.

syntax.