Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
College aantekeningen

Class notes CSE 3040 (CS3040)

Beoordeling
-
Verkocht
-
Pagina's
67
Geüpload op
02-05-2025
Geschreven in
2023/2024

The document titled "Class Notes for Compiler Design (Course Code: CSE 3040)" serves as a comprehensive academic resource compiled specifically for undergraduate students pursuing the course CSE 3040 – Compiler Design. This collection of notes is tailored to align with the syllabus prescribed by most computer science engineering programs and aims to provide a structured, in-depth understanding of the fundamental and advanced concepts of compiler construction. The notes cover the entire compilation process, beginning with an overview of compilers, their role in translating high-level programming languages to machine code, and the distinction between interpreters and compilers. The document progresses systematically through the major phases of a compiler: lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and target code generation. Detailed explanations are provided for each phase, including the implementation of lexical analyzers using finite automata, parsing techniques such as LL and LR parsing, and methods for symbol table management and error detection. The notes also explore intermediate representations, including syntax trees and three-address code, and delve into optimization strategies for improving the efficiency of the generated code. Where appropriate, the material is supplemented with diagrams, flowcharts, algorithmic representations, and sample problems to enhance conceptual clarity. These notes are especially helpful for exam preparation, assignments, and lab exercises, offering a blend of theoretical insights and practical approaches. By following this document, students will gain a solid foundation in the design and implementation of compilers, an essential area in the field of systems programming and software engineering.

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
III YEAR – VI SEMESTER
21CS1602-COMPILER DESIGN

UNIT I - INTRODUCTION TO COMPILERS 9
Structure of a compiler – Lexical Analysis – Role of Lexical Analyzer – Input Buffering –
Specification of Tokens – Recognition of Tokens – Lex – Finite Automata – Regular
Expressions to Automata – Minimizing DFA.

INTRODUCTION TO COMPILERS
TRANSLATORS-COMPILATION AND INTERPRETATION
TRANSLATOR
A translator is a program that takes as input a program written in one
language and produces as output a program in another language. Beside
program translation, the translator performs another very important role,
the error-detection. Any violation of d HLL(High Level Language)
specification would be detected and reported to the programmers.
Important Role of Translator are:
 Translating the HLL program input into an equivalent ml program.
 Providing diagnostic messages wherever the programmer violates
specification of the HLL.
A translator or language processor is a program that translates an
input program written in a programming language into an equivalent
program in another language.
Source Code Translator Target Code
Execution in Translator


Types of Translators:
a. Interpreter
b. Assembler
c. Compiler

1.1.1.a INTERPRETER
An interpreter is a program that appears to execute a source program
as if it were machine language. It is one of the translators that translate
high level language to low level language.
Source Program Program Output
Interpreter
Data
Execution in Interpreter

, During execution, it checks line by line for errors. Languages such as
BASIC, SNOBOL, LISP can be translated using interpreters. JAVA also uses
interpreter. The process of interpretation can be carried out in following
phases.
1. Lexical analysis
2. Syntax analysis
3. Semantic analysis
4. Direct Execution
Example: BASIC , Lower Version of Pascal, SNOBOL, LISP & JAVA
Advantages:
 Modification of user program can be easily made and implemented as
execution proceeds.
 Type of object that denotes various may change dynamically.
 Debugging a program and finding errors is simplified task for a
program used for interpretation.
 The interpreter for the language makes it machine independent.
Disadvantages:
 The execution of the program is slower.
 Memory consumption is more.
1.1.1.b. ASSEMBLER
Programmers found it difficult to write or read programs in machine
language. They begin to use a mnemonic (symbols) for each machine
instruction, which they would subsequently translate into machine
language. Such a mnemonic machine language is now called an assembly
language. Programs known as assembler were written to automate the
translation of assembly language in to machine language. The input to an
assembler program is called source program, the output is a machine
language translation (object program).
It translates assembly level language to machine code.
Assembly Language Assembler Machine Code

Fig1.1.3: Execution in Assembler
Example: Microprocessor 8085, 8086.
Advantages:
 Debugging and verifying
 Making compilers->Understanding assembly coding techniques is
necessary for making compilers, debuggers and other development
tools.
 Optimizing code for size
 Optimizing code for speed.
Disadvantages:
 Development time. Writing code in assembly language takes much
longer than writing in a high-level language.
 Reliability and security. It is easy to make errors in assembly code.
 Debugging and verifying. Assembly code is more difficult to debug and
verify because there are more possibilities for errors than in high-level
code.

,  Portability. Assembly code is platform-specific. Porting to a different
platform is difficult
1.1.1.c. COMPILER
Compiler is a translator program that translates a program written in
(HLL) the source program and translate it into an equivalent program in
(MLL) the target program. As an important role of a compiler is error
showing to the programmer.
Source Code Compiler Target Code
Error Message
Fig1.1.4: Execution in Compiler
Executing a program written in HLL programming language is
basically of two parts. The source program must first be compiled translated
into a object program. Then the results object program is loaded into a
memory executed.

Source Code Compiler Object Code

Object Program Object Program Object Program
Input Output


Fig1.1.5: Execution Process of Source Program
in Compiler

Example: C, C++, COBOL, higher version of Pascal.
List of Compilers :

 Ada compilers
 ALGOL compilers
 BASIC compilers
 C# compilers
 C compilers
 C++ compilers
 COBOL compilers
 D compilers
 Common Lisp compilers
 Fortran compilers
 Java compilers
 Pascal compilers
 PL/I compilers
 Python

, Difference between Compiler and
Interpreter
Sl.No Compiler Interpreter
1 Compiler works on the Interpreter program works
complete program at once. It line-by-line. It takes one
takes the entire program as statement at a time as input.
input.
2 Compiler generates Interpreter does not generate
intermediate code, called the intermediate object code or
object code or machine code. machine code .
3 Compiler executes conditional Interpreter executes
control statements (like if-else conditional control statements
and switch-case) and logical at a much slower speed.
constructs faster than
interpreter.
4 Compiled programs take more Interpreter does not generate
memory because the entire intermediate object code. As a
object code has to reside in result, interpreted programs
memory. are more memory efficient.
5 Compile once and run 5 Interpreted programs are
anytime. Compiled program interpreted line-by-line every
does not need to be compiled time they are run.
every time.
6 Compiler does not allow a Interpreter runs the program
program to run until it is from first line and stops
completely error-free. execution only if it encounters
an error.
7 Compiled languages are more Interpreted languages are less
efficient but difficult to debug. efficient but easier to debug.
This makes such languages
an ideal choice for new
students
8 Example: C, C++, COBOL Example: BASIC, Visual
Basic, Python, Ruby, PHP,
Perl, MATLAB, Lisp

Language processors (COUSINS OF THE COMPLIER or Language
Processing System) :
1. Preprocessors :
It produces input to Compiler. They may perform the following
functions.
Macro Processing:
A preprocessor may allow a user to define macros that are
shorthand’s for longer constructs.
File inclusion:
A preprocessor may include header files into the program text. For
example, the C preprocessor causes the contents of the file <global.h> to replace
the statement #include<global.h> when it processes a file containing this
statement.

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
2 mei 2025
Aantal pagina's
67
Geschreven in
2023/2024
Type
College aantekeningen
Docent(en)
Rahini sudha
Bevat
Alle colleges

Onderwerpen

$8.49
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
manikandans1

Maak kennis met de verkoper

Seller avatar
manikandans1 Panimalar Engineering College
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
1 jaar
Aantal volgers
0
Documenten
1
Laatst verkocht
-

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen