0% found this document useful (0 votes)
10 views7 pages

Compiler Design Assignment 1

The document is an assignment for a Compiler Design course submitted by a student named Surinder Kumar. It covers topics such as Minimizing DFA, Error Handling, LALR Parser, the role of a Parser, and Syntax Directed Definitions (SDD), providing definitions, concepts, types, and examples for each topic. The assignment aims to enhance understanding of compiler design principles and techniques.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

Compiler Design Assignment 1

The document is an assignment for a Compiler Design course submitted by a student named Surinder Kumar. It covers topics such as Minimizing DFA, Error Handling, LALR Parser, the role of a Parser, and Syntax Directed Definitions (SDD), providing definitions, concepts, types, and examples for each topic. The assignment aims to enhance understanding of compiler design principles and techniques.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Aman Bhalla Institute of Engineering and Technology

Kotli Pathankot

Department of Computer Science & Engineering (CSE)

([Link]) 6TH SEMESTER

Assignment 1

Subject – Compiler Design

Submitted By: Submitted To:


Surinder Kumar Ms. Pallavi

([Link]) CSE, 6th Sem) Assistant Professor

Roll No: 2300040

SESSION: 2025–2026
Q1. What is Minimizing DFA?
Answer:

Introduction:

DFA (Deterministic Finite Automaton) ek finite state machine hai jo strings ko accept/reject
karta hai.
DFA Minimization ka matlab hai DFA ko simplify karna by reducing number of states
without changing its language.

👉 Simple words:
Same kaam karne wala DFA → but minimum states ke saath

Why Minimization Needed?

 Memory saving

 Faster execution

 Efficient design

 Easy implementation

Concept

DFA me kuch states equivalent hote hain → unko merge kar sakte hain.

👉 Equivalent states = jo same input par same behavior dete hain

Steps of DFA Minimization

Step 1: Remove Unreachable States

 Jo states start state se reach hi nahi hote → remove

Step 2: Partition States

 Final states (F)

 Non-final states (NF)


Q2. What is Error Handling?
Answer:

Introduction:

Compiler ka kaam sirf code translate karna nahi, balki errors detect aur handle karna bhi
hota hai.

👉 Error handling ensures:

 Program correct ho

 User ko proper feedback mile

Types of Errors

1. Lexical Errors

 Invalid tokens

 Example:

int 123abc;

2. Syntax Errors

 Grammar rules break

 Example:

if (a > b

3. Semantic Errors

 Meaning wrong

 Example:

int a = "hello";
4. Runtime Errors

 Execution time error

 Example: divide by zero

Error Handling Techniques

1. Panic Mode

 Error milte hi skip until safe point


👉 Fast but less accurate

2. Phrase Level Recovery

 Minor correction karke continue

3. Error Productions

 Grammar me error rules add

4. Global Correction

 Minimum changes find karke correct

Goals of Error Handling

 Detect errors early

 Continue compilation

 Provide meaningful message


Q3. Introduction to LALR Parser
Answer:

Introduction

LALR (Look Ahead LR) parser ek bottom-up parser hai jo LR parser ka optimized version
hai.

👉 Use hota hai:

 Compiler design me

 Syntax analysis ke liye

Full Form

LALR = Look Ahead Left to Right, Rightmost Derivation

Concept

 Input left to right read karta hai

 Rightmost derivation use karta hai

 Lookahead symbol use karta hai decision ke liye

Why LALR?

 LR parser powerful hai but memory heavy

 LALR same power + less memory

Working

1. Input read

2. Stack maintain

3. Shift/Reduce operations perform


Q4. What is the Role of Parser?
Answer:

Introduction

Parser compiler ka second phase hota hai (after lexical analysis).

👉 Role:
Tokens ko grammar ke according check karna

Functions of Parser

1. Syntax Checking

 Code grammar follow karta hai ya nahi

2. Parse Tree Generation

 Program ka hierarchical structure banata hai

3. Error Detection

 Syntax errors identify karta hai

4. Intermediate Representation

 Next phase ke liye data ready karta hai

Types of Parser

1. Top-Down Parser

 Root → leaf

 Example: Recursive descent


Q5. Write Down Syntax Directed Definitions (SDD)
Answer:

Introduction

Syntax Directed Definition (SDD) ek method hai jisme grammar ke saath attributes aur
rules attach kiye jate hain.

👉 Use hota hai:

 Semantic analysis

 Meaning define karne ke liye

Concept

Grammar + Attributes + Rules = SDD

Types of Attributes

1. Synthesized Attributes

 Child → Parent flow

2. Inherited Attributes

 Parent → Child flow

Example

Grammar:

E → E1 + T
E→T

SDD:

[Link] = [Link] + [Link]

You might also like