Compiler Contruction 1 Mark
Compiler Contruction 1 Mark
1. Loop optimization
2. Inline functions
3. Dead code elimination
4. Code motion
5. Constant folding
6. Strength reduction
7. Peephole optimization
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.