JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD B.Tech III PRINCIPLES OF COMPILER CONSTRUCTION Previous Question Paper (August - 2022 - R18)
Answer any five questions. All questions carry equal marks.
Main
What is the need for a compiler? Explain various phases in compiler construction.
Answer
A compiler is a specialized program that translates source code written in a high-level programming language into machine-executable code. Its primary need arises from the fact that computer hardware understands only binary machine instructions, whereas high-level languages provide abstraction, readability, and portability for programmers. By automating the translation process, compilers ensure that complex logic can be executed efficiently on diverse hardware architectures while performing error checking and optimization.
The compilation process is divided into several logical phases:
- Lexical Analysis (Scanning): Reads the source code as a stream of characters and groups them into meaningful sequences called tokens.
- Syntax Analysis (Parsing): Takes tokens and creates a hierarchical structure, typically a Parse Tree or Abstract Syntax Tree, based on the language's grammar rules.
- Semantic Analysis: Checks the tree for semantic consistency, such as type checking and scope resolution, ensuring the program makes sense according to language rules.
- Intermediate Code Generation: Produces a machine-independent, low-level representation of the source code, such as Three-Address Code.
- Code Optimization: Refines the intermediate code to improve execution speed and reduce memory consumption without changing the program's output.
- Code Generation: Translates the optimized intermediate code into the target machine language or assembly code.
Additionally, the Symbol Table Manager and Error Handler interact with all phases to maintain identifier information and report diagnostic messages during the process.
Define token. Explain how it is represented.
Answer
A token is the smallest individual unit of a programming language that has a specific meaning to the compiler, such as keywords, identifiers, operators, constants, or punctuation marks.
Tokens are typically represented as a pair consisting of a token name (a category like 'identifier' or 'keyword') and an optional attribute value (a pointer to the symbol table entry for that specific token). For example, in the statement count = 10;, the tokens are represented as:
Give the Lex program structure with an example for identifying keywords in ‘C’ language.
Answer
Sign in to view the complete answer paper.
Convert 01*+11 Regular expression to NFA and DFA.
Answer
Sign in to view the complete answer paper.
Define context free grammar, parse tree and syntax tree.
Answer
Sign in to view the complete answer paper.
Explain the steps to construct SLR parsing table.
Answer
Sign in to view the complete answer paper.
What is left factoring and left recursion in context free grammars? Explain the steps to eliminate these in context free grammars.
Answer
Sign in to view the complete answer paper.
Write an algorithm for working principle of predicate parser.
Answer
Sign in to view the complete answer paper.
What are S-attributes and L- attributes grammar? Explain with an example.
Answer
Sign in to view the complete answer paper.
Explain the SDD specification of simple type checker.
Answer
Sign in to view the complete answer paper.
Explain various forms of intermediate code.
Answer
Sign in to view the complete answer paper.
Write the three address code for “if and while” statements.
Answer
Sign in to view the complete answer paper.
Compare various storage allocation methods.
Answer
Sign in to view the complete answer paper.
What is DAG? Explain its representation for a basic block.
Answer
Sign in to view the complete answer paper.
Explain the principle source of code optimization.
Answer
Sign in to view the complete answer paper.
Write about data flow analysis of structured program.
Answer
Sign in to view the complete answer paper.