W08_15_Compilers - 15 Compilers, Linkers, Loaders CSC 230...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
15 Compilers, Linkers, Loaders CSC 230 Department of Computer Science University of Victoria
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Structure of a Compiler ± a processor understands only its own machine language ± a compiler is typically a large piece of software to translate from a HLL to machine code target ode source ode intermediate ode FRONT END BACK END code code code High Level Language Machine Code (ISA for processor) NOT assembly language (but can look similar) 2
Background image of page 2
FRONT BACK target code source code intermediate code END END The front end is dependent on Front and Back Ends ± the high level language ± the grammar he front end should not need to know any properties of the The front end should not need to know any properties of the target architecture (though exceptional cases often occur) he back end dependent on the target architecture The back end is dependent on the target architecture. ± It knows the IR (intermediate representation) ± t knows the target’s machine code It knows the target s machine code ± It does not know the original HLL and grammar 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Goals ± Correctness Î machine code must implement the semantics of the statements EXACTLY ± Efficiency ² time ² space ² the translation is a one-to-many mapping Use as example: while(save[i] == k) i += 1; 4
Background image of page 4
The Structure of a Compiler Organized as several translation steps, typically: 1. Lexical Analysis (scanning) 2. Syntactic Analysis (parsing) 3. Semantic Analysis (checking & attaching meaning) 4. Optimization 5. Code Generation For the first 3 phases, there is a good analogy to how humans comprehend a language target source intermediate FRONT END BACK END code code code 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
PART 1: Lexical Analysis - Scanning eads in individual characters and creates a string of Î reads in individual characters and creates a string of tokens Examples of tokens are reserved words, names, operators, and punctuation symbols. while(save[i] == k) i += 1; In the example, the token sequence is: while ”, ( “, save ”, [ ”, i ”, ] ”, == ”, k ”, ) ”, “ ”, = ”, “ ”. i , + , 1 . while ” is recognized as a keyword in C, save ”, “ i ”, and “ j ” are recognized as names (identifiers) 1 ” is recognized as an integer constant (a number). ± Simple character scanning to decompose the input (the igh- vel language) into basic elements high level language) into basic elements ± output is a stream of tokens. ..... Î which is input to the parser
Background image of page 6
Lexical Analysis - Features canning by a exical Analyzer ust be efficient ± We can list all possible tokens as an infinite set of ± Scanning by a Lexical Analyzer must be efficient because of the volume of input strings ² this set of strings defines a language ² each string is a possible sentence in the language ± The lexical analyzer recognizes this language ± By design, the lexical language belongs to a class of languages known as the ‘regular languages’ because: ² there is a well-understood and useful theory ² they are easy to understand ² their recognizers have efficient implementations ±
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2012 for the course CSC 230 taught by Professor Jasond.corless during the Summer '11 term at University of Victoria.

Page1 / 44

W08_15_Compilers - 15 Compilers, Linkers, Loaders CSC 230...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online