0% found this document useful (0 votes)
3 views

Compiler Contruction 1 Mark

The document outlines various concepts related to programming and compilers, including code optimization techniques, the definition of a sentinel, handles, and the phases of a compiler. It discusses the functionalities of LEX, parsing methods, attributes in grammars, and conflicts in LR parsers. Additionally, it covers topics such as bootstrapping, basic blocks, operand descriptors, and the yywrap() function in the LEX library.

Uploaded by

omkarparande22
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Compiler Contruction 1 Mark

The document outlines various concepts related to programming and compilers, including code optimization techniques, the definition of a sentinel, handles, and the phases of a compiler. It discusses the functionalities of LEX, parsing methods, attributes in grammars, and conflicts in LR parsers. Additionally, it covers topics such as bootstrapping, basic blocks, operand descriptors, and the yywrap() function in the LEX library.

Uploaded by

omkarparande22
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1) List code optimization technique.

Here’s a concise answer for a one-mark question:

Code optimization techniques include:

1. Loop optimization
2. Inline functions
3. Dead code elimination
4. Code motion
5. Constant folding
6. Strength reduction
7. Peephole optimization

These techniques improve code efficiency and reduce resource usage.

2) What is sential?
A sentinel is a special value used to signal the end of a data structure or loop, without
requiring additional condition checks. For example, -1 might be used as a sentinel to indicate
the end of an input sequence.

3)Define the term handle


A handle is a reference or identifier used by a program to access a resource, such as a file,
object, or memory block, without directly exposing the resource's underlying details.

4) LEX is a scanner provided by linux operating system state true


or false justify.
False.

Justification:
LEX is not a hardware scanner but rather a software tool used for lexical analysis. It is a
program that generates lexical analyzers (scanners) for use in the compilation process. In the
context of programming, LEX is commonly used to process and analyze strings of text by
breaking them into meaningful components, called tokens. It is widely used in Unix-based
systems, including Linux, but it is not inherently provided by the Linux operating system
itself. Instead, it is a standalone tool that can be installed and used within the Linux
environment.

For actual hardware scanning (e.g., document scanners), Linux provides other software tools
and drivers, such as SANE (Scanner Access Now Easy).

5)Define boostrapping
Bootstrapping is the process of starting a system or program with minimal resources, often
referring to the initialization of a computer or compiling a complex system starting from a
simpler initial program.

6) LALR is the best bottom up parsing method justify.


True.

Justification:
LALR (Look-Ahead LR) is considered one of the best bottom-up parsing methods because it
combines the simplicity of SLR parsing with the power of Canonical LR parsing. It is
efficient in terms of memory usage and handles a wide range of grammars effectively,
making it well-suited for practical use in compilers.

7) Define basic block


Basic Block:
A basic block is a sequence of consecutive statements in a program with only one entry point
and one exit point, where control flow enters at the beginning and leaves at the end without
branching, except at the last statement.

8) Differentiate between synthesis & inherited attributes


Difference between Synthesized and Inherited Attributes:

 Synthesized Attributes: These are attributes calculated from the values of the
attributes of a node's children in the parse tree.
 Inherited Attributes: These are attributes computed based on the values of the
attributes of a node's parent or siblings in the parse tree.

9) What is parser ?
Parser:
A parser is a component of a compiler or interpreter that analyzes the syntax of a given input
program, ensuring it adheres to the rules of a formal grammar, and typically constructs a
parse tree or abstract syntax tree as output.

10) List all phases of the compiler.


Phases of a Compiler:

1. Lexical Analysis
2. Syntax Analysis
3. Semantic Analysis
4. Intermediate Code Generation
5. Code Optimization
6. Code Generation
7. Symbol Table Management and Error Handling (supporting roles across phases).
11) What is the use of lookahead pointer.
The lookahead pointer is used in parsers to examine upcoming input symbols (tokens)
without consuming them, helping to decide which production rule to apply next. It allows the
parser to make decisions based on future input, enabling more efficient parsing, particularly
in techniques like LL and LR parsing.

12)State true or false, “Target code is generated in the analysis


phase of the

compiler”.
False.

Justification:
Target code is generated during the code generation phase of the compiler, not during the
analysis phase. The analysis phase includes lexical analysis, syntax analysis, and semantic
analysis, which focus on understanding and checking the source code. Code generation,
which translates intermediate representations into target machine code, occurs later in the
compilation process.

13)What is the output of LEX program?


The output of a LEX program is a lexical analyzer or scanner. It generates C code for a
lexical analyzer that can tokenize input data based on the regular expressions defined in the
LEX source file. This generated code, when compiled and run, performs lexical analysis on
the input and produces a stream of tokens.

14)Terminals can have synthesized attributes, but not inherited


attributes.

State true or false.


True.

Justification:
Terminals in a grammar (such as tokens in a lexical analyzer) can have synthesized
attributes, which are computed from the terminal itself or its children in the parse tree.
However, inherited attributes are typically associated with non-terminal symbols, as they
are passed down from parent or sibling nodes in the parse tree. Terminals do not have
inherited attributes because they do not have parent or sibling nodes in the parse tree.

15)Define operand descriptors.

Operand descriptors are data structures used in a compiler's intermediate representation to


describe operands, such as variables, constants, or temporary values, including their types,
values, and memory locations. They help manage and track operands during code generation
and optimization.

16) State True or False. The yywrap() lex library function by


default always

return 1.
True.

Justification:
By default, the yywrap() function in the LEX library always returns 1, indicating the end of
input. This behavior signifies that no more input is available for the lexical analyzer.
However, the function can be customized by the user to change this behavior if needed.

17) List the two aspects of compilation.


The two main aspects of compilation are:

1. Analysis
2. Synthesis

 Analysis: Involves breaking down the source code into a form that can be processed,
such as through lexical, syntax, and semantic analysis.
 Synthesis: Involves constructing the target code (e.g., machine code or intermediate
code) from the analyzed representation of the source code.

18) List the different types of conflicts that occur in LR parser.


The different types of conflicts that can occur in an LR parser are:

1. Shift/Reduce Conflict: Occurs when the parser has to decide whether to shift (read
the next symbol) or reduce (apply a production rule) based on the current state and
lookahead symbol.
2. Reduce/Reduce Conflict: Occurs when the parser has to decide between two or more
possible reductions, but the current input allows for more than one valid production to
be applied.

19) What is handle pruning?


Handle Pruning is the process of identifying and removing a handle in a bottom-up parser.
A handle is a sub-string of the input that matches the right-hand side of a production rule,
and reducing this handle to the non-terminal on the left-hand side is part of the parsing
process. In handle pruning, the parser repeatedly applies these reductions to simplify the
input until it is reduced to the start symbol, effectively parsing the input.
20) List the techniques used in code optimization.
The techniques used in code optimization include:

1. Loop Optimization: Improving loops to reduce unnecessary iterations and operations


(e.g., loop unrolling, loop fusion).
2. Constant Folding and Propagation: Precomputing constant expressions at compile-
time.
3. Inlinining: Replacing function calls with the actual code of the function to reduce the
overhead of calling.
4. Dead Code Elimination: Removing code that does not affect the program's output.
5. Common Subexpression Elimination: Identifying and reusing expressions that are
computed multiple times.
6. Register Allocation: Efficiently assigning variables to registers to speed up
execution.
7. Strength Reduction: Replacing expensive operations (e.g., multiplication) with
cheaper ones (e.g., addition).
8. Instruction Scheduling: Reordering instructions to minimize pipeline stalls and
improve parallelism.

You might also like