- Information
- AI Chat
Compiler design - unit1
useful for complier designing
Course
Computer Applications (IRDA37)
83 Documents
Students shared 83 documents in this course
University
Annamalai University
Academic year: 2022/2023
Uploaded by:
0followers
1Uploads
0upvotes
Preview text
Compiler Design – Unit I
COMPILERS
• A compiler is a program takes a program written in a source language
and translates it into an equivalent program in a target language.
source program COMPILER target program
error messages
( Normally a program written in
a high-level programming language)
( Normally the equivalent program in
machine code – relocatable object file)
Why Study Compilers?
• General background information for good software engineer
– Increases understanding of language semantics
– Seeing the machine code generated for language constructs
helps understand performance issues for languages
– Teaches good language design
– New devices may need device-specific languages
– New business fields may need domain-specific languages
Operations of Compiler
• Breaks down the source programme into chunks and applies
grammatical structure to each one.
• Enables you to create the symbol table and the target programme you’re
after from the intermediate representation.
• Helps in compiling source code and detecting the errors.
• Organise and save all codes and variables.
• Read the full programme, analyse it, and translate it to a semantically
similar language.
• Depending on the type of machine, converting source code to object
code.
History of Compilers
• Ken Thmpson’s aim was to develop a compiler for FORTRAN, he
ended up creating one for a new high-level language called B.
• C Language – descendant of B language.
• C++.
• First Java Compiler Created by Sun Microsystems was written in C.
• Now, Java Compiler is written in Java While JRE is written in C.
Preprocessor
• A preprocessor produce input to compilers. They may perform the
following functions.
• 1. Macro processing: A preprocessor may allow a user to define macros
that are short hands for longer constructs
• #define max (a, b) a>b? A: b
• z = max(x, y);
• Becomes z = x>y? X:y;
Preprocessor
• 2. File inclusion: A preprocessor may include header files into the
program text.
• 3. Rational preprocessor: these preprocessors augment older languages
with more modern flow-of-control and data structuring facilities.
• 4. Language Extensions: These preprocessor attempt to add capabilities
to the language by certain amounts to build-in macro.
Assemblers - two types
• 1. One-Pass Assembler
• These assemblers perform the whole conversion of assembly code to
machine code in one go.
• 2. Multi-Pass/Two-Pass Assembler
• These assemblers first process the assembly code and store values in
the opcode table and symbol table.
• And then in the second step, they generate the machine code using these
tables.
Linker
• Linker is a computer program that links and merges various object files
together in order to make an executable file.
• All these files might have been compiled by separate assemblers.
• The major task of a linker is
– to search and locate referenced module/routines in a program and
– to determine the memory location where these codes will be loaded,
– making the program instruction to have absolute references.
Loader types
• Absolute Loaders
• A loader that places absolute code into main memory beginning with
the initial address assigned by the assembler.
• Relocating Loaders
• It can load reloadable object files, thus loading the same program
starting at any location.
• Direct Linking Loaders
• It can link programs that were assembled separately, and load them as a
single module.
• Bootstrap Loaders
• When a computer is first turned on or restarted - OS
Phases of Compiler Design
Lexical Analyzer
• Lexical Analyzer reads the source program character by character
and returns the tokens of the source program.
• A token describes a pattern of characters having same meaning in the
source program. (such as identifiers, operators, keywords, numbers,
delimeters and so on)
Ex: newval := oldval + 12 => tokens: newval identifier
:= assignment operator
oldval identifier
+ add operator
12 a number
• Puts information about identifiers into the symbol table.
Syntax Analyzer
• A Syntax Analyzer creates the syntactic structure (generally a parse
tree) of the given program.
• A syntax analyzer is also called as a parser.
• A parse tree describes a syntactic structure. Eg: newval := oldval + 12
assgstmt
identifier := expression
newval expression + expression
identifier number
oldval 12
• In a parse tree, all
terminals are at leaves.
• All inner nodes are non-
terminals in a context free
grammar.
Was this document helpful?
Compiler design - unit1
Course: Computer Applications (IRDA37)
83 Documents
Students shared 83 documents in this course
University: Annamalai University
Was this document helpful?
1
Compiler Design – Unit I
Too long to read on your phone? Save to read later on your computer
Discover more from:
- Discover more from: