Download presentation
Presentation is loading. Please wait.
1
Welcome to CS 445 Compiler and Translator Design Clinton Jeffery jeffery@uidaho.edu JEB 230
2
What’s a Compiler Translates human equations to machine code Originally done by a human Compared with colloquial English: to pull together the sequence of machine instructions needed to perform a given computing task
3
Why Study Compilers? Experience with large-scale applications development. A shining triumph of CS theory A basic element of language R&D Ideas and tools useful in many applications
4
Tools We Use C and “make” Lex and Yacc Gdb E-mail Web CVE
5
Kinds of Compilers Native code Virtual machine JIT Preprocessor, macro processor Interpreter
6
Phases of a Compiler Lexical analysis Syntax Analysis Semantic Analysis Intermediate Code Generation Optimization Final Code Generation Linking
7
Example Compile:position = initial + rate * 60 Intermediate:t1 = inttoreal(60) t2 = id 3 * t1 t3 = id 2 + t2 id 1 = t3 Final:MOVF id 3, R2 MULF #60.0, R2 MOVF id 2, R1 ADDF R2, R1 MOVF R1, id 1
8
Overview of Lexical Analysis Reminder: read Sections 3-5 of Lexical Analysis with Flex; Dragon book will also be useful here “Lexical” means: pertaining to the words or vocabulary of a language Maps individual symbols into such “words”, which we call “tokens”
9
Meanings of the word “token” A single word from the source code An integer code for the category a word belongs to A set of lexical attributes that are computed from a single word of input An instance of a class (given by category)
10
Traits of Scanners They convert (1+) chars to tokens Detect boundaries between tokens Identify/categorize kinds of tokens Discard comments and whitespace Remember line/col #’s for error reporting Report lexical errors Run as fast as possible
11
Categorizing From a language specification (written doc, usually semi-formal) Identify all word categories For each category, a set of characters and combination/sequence rules (natural languages use dictionaries and surrounding context) Often uses a popular formal notation with which you probably are familiar.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.