0% found this document useful (0 votes)
33 views5 pages

Compiler Design Assignments Overview

This document contains 10 questions related to compiler design for Assignment 5. The questions cover topics like code generation, register allocation, basic blocks, control flow graphs, data flow analysis, peephole optimization, and more. Students are asked to explain concepts, differentiate between topics, provide examples, and translate code snippets into intermediate representations. The assignment is due on October 13th, 2023 and is to be submitted to Mr. Abhishek K.C. Sharma.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views5 pages

Compiler Design Assignments Overview

This document contains 10 questions related to compiler design for Assignment 5. The questions cover topics like code generation, register allocation, basic blocks, control flow graphs, data flow analysis, peephole optimization, and more. Students are asked to explain concepts, differentiate between topics, provide examples, and translate code snippets into intermediate representations. The assignment is due on October 13th, 2023 and is to be submitted to Mr. Abhishek K.C. Sharma.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Compiler Design(BTCS601)

Assignment-01 Date: 09-Aug-2023

Q.1 Explain the Booting process of a System along with the Types of
Booting.
Q.2 What is a BIOS? What are the roles of ROM BIOS and CMOS RAM?
Q.3 Explain various levels of Programming Languages.
Q.4 Explain various Types of Memories along with their Characteristics.
Q.5 Explain the concept of the Von-Newman model by taking the Statement
C=A+B along with a neat and clean diagram and try to generate Symbolic
(Assembly/Mnemonic/HEX) Code and Machine Code.
Q.6 Explain the complete execution process of a “C/C++” program from the
very beginning to till the end. What are the contents of the executable file?
Q.7 What are Finite Automata? What are the NFA and DFA? Give the
conversion process of NFA to DFA.
Q.8 What is Regular Expression? Explain with suitable examples.
Q.9 Describe Context-Free Grammar (CFG). Also, explain CNF and GNF.
Q. 10 Describe PDA and Construct the PDA for anbn.

Date of Submission –18-Aug-2022


Mr. Abhishek K.C. Sharma
Subject Teachers {Sections: VII Semester (B, E, I) & V Semester (J)}
Compiler Design(BTCS601)
Assignment-02 Date: 18-Aug-2023
Q.1 What is a Compiler? Give the primary tasks of a Compiler.
Q.2. What are “Compiler” and “De-compiler”? Why are these needed?
Q.3 Describe the Compiler and its phases with a neat and clean diagram.
Q.4 Explain the “Analysis-Synthesis Model” {Grouping of Phases/Pass-I &
Pass-II/Single Pass vs. Multi-Pass/Frontend & Backend} of Compiler in
brief.
Q.5 Explain the various types of translators (Cousins of Compilers).
Q.6 Provide the Details of Compiler Construction Tools?
Q. 7 What is input Buffering? Describe the techniques of Single Buffering
and Double Buffering Schemes.
Q. 8 What is Lexical Analysis? Explain the Role of Lexical Analyzer. Give
Specification of Tokens.
Q.9 What is LEX? Describe auxiliary definitions and translation rules for
LEX with suitable examples. Give a short description of tools “LEX”.
Q.10 Write short notes on the following:
a. Boot-strapping
b. Cross-Compiler
c. Back Patching
d. Sentinels
e. Error and Recovery Schemes

Date of Submission –28-Aug-2022

Mr. Abhishek K.C. Sharma


Subject Teachers {Sections: VII Semester (B, E, I) & V Semester (J)}
Compiler Design(BTCS601)
Assignment-03 Date: 8-September-2023
Q.1 What is Syntax Analysis? Explain the Role of Parser.
Q.2 Write a short note:
(a) Polish and Reverse Polish notations.
(b) Ambiguous Grammar.
(C) Operator Precedence and Associativity.
Q.3 Describe the classifications of Parsing techniques along with a suitable block
diagram.
Q.4 Explain the leftmost and rightmost derivations with suitable examples.
Q.5 Difference b/w Parse tree and Syntax tree?
Q.6 Describe Brute-Force Parser.
Q.7 Explain the Recursive-Descent Parsing & Predictive Parsing.
Q.8 What is Left Recursion? How is it removed? Explain the need and process of
Left Factoring.
Q.9 Explain the Rules for generating the FIRST and FOLLOW sets of the symbols
for the Grammar.
Q.10. Consider the following Grammar and Construct the LL(1) Parser:
S -> A A -> BC | DBC B -> Bb | ε C -> c | ε D -> a | d
(1) Check left recursion.
(2) Check left factoring.
(3) Transition Diagram
(4) FIRST & FOLLOW.
(5) Parsing Table.
(6) Block Diagram.
(7) Parsing Algorithm.
(8) Parsing with String dbb.

Date of Submission –15-September- 2023


Mr. Abhishek K.C. Sharma
Subject Teachers {Sections: VII Semester (B, E, I) & V Semester (J)}
Compiler Design (BTCS601)
Assignment-04 Date: 15-Sep-2023
Q.1 Describe the Bottom–up parser and its classifications.
Q.2 What is shift-reduce Parser?
Q.3 What is Operator Precedence Grammar?
Q.4 Explain the LR Parser along with its features and types.
Q.5 Draw the block diagram of LR Parser.
Q.6 Perform the SLR Parsing on the following Grammar G by explaining every
point in detail. Grammar G:
(1) E -> E+T
(2) E -> T
(3) T -> T*F
(4) T -> F
(5) F -> (E)
(6) F -> id
(i) Augmented Grammar G’.
(ii) Preparing Canonical Set of items LR (0) through closure operation.
(iii) Preparing Transition Diagram T.
(iv) Block Diagram for LR Parser.
(v) Algorithm for constructing parsing Table.
(vi) Constructing Parsing Table M.
(vii) Performing the SLR Parsing by use of the string id*id+id.
Q.7 Differentiate b/w CLR and LALR with parsing.
Q.8 What is Syntax Directed Translations [Semantic Phase]? Also, explain its
roles.
Q.9 Write Short notes on:
(i) Annotated Parse Tree.
(ii) S-attribute Definitions (Synthesized)
(iii) L-attribute Definitions (Inherited)
(iv) Dependency Graphs
Q.10 Parameter passing techniques. Explain various techniques.

Date of Submission –27-Sep-2023

Mr. Abhishek K.C. Sharma


Subject Teachers {Sections: VII Semester (B, E, I) & V Semester (J)}
Compiler Design (BTCS601)
Assignment-05 Date: 29-Sep-2023
Q.1 What do you mean by three address code?
Translate the expression
-(a+b)*(c+d)+(a+b+c) into Quadruples, Triples, Indirect triples.
Q.1 Difference b/w Syntax Tree and DAG.
a) Construct the DAG for the following basic block:
d := b * c
e := a + b
b := b * c
a := e – d
b) Construct the DAG for the following basic blocks:
(i) t1=4*i (ii) t2=a[t1] (iii)t3=4*i
(iv)t4=b[t2] (v) t5=t2*t4 (vi)t6=prod+t5
(vii)prod=t6 (viii)t7=i+1 (ix) i=t7
(x) if i<=20 goto step (1)
Q.3 What do you mean by Activation Record?
Q.4 What is the difference between dynamic and static storage management?
Explain the importance of run-time storage management in the compiler.
Q.5 What do you understand by code generation? What are the general issues in
designing a code generator? What is register allocation and assignment?
Generate the code for the following expression using only one register.
d := b * c
e := a + b
b := b * c
a := e - d
Q.6 What do you mean by optimization technique? Explain the principle sources of
optimization with suitable examples.
Q.7 What is a basic block? Discuss various transformations that can be done on the
basic block with the help of a suitable example.
Q.8 What do you mean by control flow graph?
Q.9 What is global data-flow analysis? What is its use in code optimization?
Q.10 Explain the process of peephole optimization.

Date of Submission –13-Oct-2023

Mr. Abhishek K.C. Sharma


Subject Teachers {Sections: VII Semester (B, E, I) & V Semester (J)}

Common questions

Powered by AI

Parsing techniques are generally categorized into top-down and bottom-up approaches. Top-down parsers, including Recursive-Descent and LL parsers, construct the parse tree from the top (start symbol) by applying grammar rules to predict the input sequence. They use methods like backtracking, although predictive parsers aim to eliminate backtracking by left factoring and eliminating left recursion. Bottom-up parsers, such as LR and SLR parsers, begin with input symbols and incrementally combine them using grammar rules to build up to the start symbol, effectively constructing the tree from leaves upwards. These parsers handle a broader class of grammars, including all LR(k) grammars, and are used where the input-driven predictive approach falls short due to complexities or ambiguities. The choice between these approaches affects robustness and efficiency, with bottom-up parsers generally offering higher parsing power and dealing more efficiently with diverse language features .

Left factoring is a grammar transformation technique used to eliminate ambiguity by restructuring grammar to favor a predictive parsing approach. It involves transforming a grammar so two or more productions for a non-terminal begin with the same sequence of symbols into a form where such common prefixes are factored out. This is crucial for top-down parsing strategies, such as LL(1), which require decisions based exclusively on a limited lookahead, typically only the next input symbol. For instance, if a grammar contains rules like A -> αβ1 | αβ2, left factoring transforms it to A -> αA'; A' -> β1 | β2. Left factoring prevents parser conflicts by making it more straightforward to choose which production to apply, thus facilitating the design of efficient parsers .

The tasks of a lexical analyzer in lexical analysis involve scanning the source code, recognizing and extracting tokens, and classifying them while ignoring whitespace and comments. It reads the source code character by character and groups them into meaningful sequences known as tokens, such as keywords, operators, identifiers, and literals. The lexical analyzer also removes whitespace and comments, simplifying what gets processed in later compiler stages. Additionally, it generates tokens with relevant information and updates symbol tables with identifiers. It must also handle lexical errors gracefully, providing meaningful error messages or ignoring erroneous patterns where possible .

Deterministic Finite Automata (DFA) differ from Non-deterministic Finite Automata (NFA) in that, for each state in a DFA, there is exactly one transition for every input symbol, leading to a single next state. In contrast, an NFA may have multiple possible next states for a given input from a state, or even transitions on epsilon (ε) without any input symbol. Converting an NFA to a DFA, known as the subset construction method, is significant because DFAs have deterministic transitions that simplify implementation and typically improve performance, facilitating execution within lexical analyzers. While NFAs are often simpler to construct and specify, DFAs offer more practical computational use since they avoid the computational complexity of exploring multiple transitions and need no backtracking, thus speeding up the lexical analysis process in compilers .

The Von-Neumann architecture is a computer architecture design model that uses a single storage structure to hold both instructions and data, which means a program instruction and memory data are stored in the same memory and accessed via the same buses. Using the statement C=A+B, the architecture allows the fetch-decode-execute cycle to operate as follows: Fetch the instruction from memory, decode to determine the operation (addition, in this case) and the operands (A and B), execute the instruction by performing addition, storing the result in C. Symbolic code in assembly might look like: LOAD R1, A; LOAD R2, B; ADD R1, R2; STORE R1, C. The machine code would be the binary opcodes corresponding to these operations. Conversion to machine code would involve using the architecture's specific opcode set for loading, arithmetic, and storing operations .

A parser plays a critical role in syntax analysis, which is the second phase of a compiler. It checks the source code for syntactic correctness against the grammar of the programming language. The parser transforms linear sequences of tokens from the lexical analyzer into hierarchical structures like syntax trees, based on grammar rules. This phase ensures that the program satisfies the language's grammar and syntax rules. Correct syntax analysis is essential as it lays the groundwork for semantic analysis, generation of intermediate code, and optimization, as errors detected here need to be resolved before moving onto these subsequent phases .

The booting process of a system refers to the sequence of operations that starts when a computer is powered on and ends when the operating system is loaded and ready for use. The two main types of booting are Cold Booting (or hard boot) and Warm Booting (or soft boot). Cold Booting involves starting a computer from an initially powered-down state, whereas Warm Booting involves restarting a computer without turning off the power. Cold Booting typically occurs when the system is powered on after being completely shut down, and involves POST (Power-On Self-Test) checks, loading the boot loader, and then the operating system. Warm Booting skips hardware initialization processes as power is not fully cut off, and usually involves a software command to restart the system .

A Control Flow Graph (CFG) is a representation used in compiler design to describe the flow of control during program execution. Each node represents a basic block of instructions, and edges represent control flow paths between blocks, capturing possible execution pathways, including loops and branches. CFGs are crucial for several optimization strategies because they expose opportunities to enhance code performance. For example, by identifying unreachable code, loops, and invariant computations, a compiler can apply optimizations like dead code elimination, loop unrolling, and code motion. CFGs ensure that optimizations maintain the logical execution of code while improving efficiency, serving as a backbone for tasks such as data flow analysis and resource allocation .

Regular expressions are sequences of characters that form search patterns, used for matching character combinations in strings. In compiler design, regular expressions are fundamental for specifying the lexical syntax of programming languages. They are used to describe the lexical patterns of tokens, such as keywords, identifiers, literals, and operators. For example, a regular expression for an identifier might be [a-zA-Z_][a-zA-Z0-9_]*, which indicates that an identifier starts with a letter or underscore followed by any combination of letters, numbers, or underscores. Regular expressions are often converted into finite automata for efficient pattern matching during lexical analysis .

A Parse tree, also known as a concrete syntax tree, represents the syntactic structure of a string according to the rules of a formal grammar, showing all the syntax rules used in deriving the string. Each interior node of the parse tree represents a production used in the derivation, and leaf nodes represent individual tokens. In contrast, a Syntax tree, or abstract syntax tree (AST), is a simplified version of the parse tree that omits nodes for syntax structures that do not affect execution semantics or are redundant for later stages. It represents the hierarchical structure of the source code. For example, consider the expression 'a + b * c': The parse tree will show all operations and precedence indications (like multiplication before addition), while the syntax tree will include only essential structure, with 'b * c' directly under the multiplication node, and its result combined with 'a' under the addition node, reflecting precedence and associativity without grammatical details .

You might also like