Q. In an LR parser, what is the purpose of the 'shift' action?
A.
To reduce a production.
B.
To push a state onto the stack.
C.
To pop a state from the stack.
D.
To accept the input.
Show solution
Solution
The 'shift' action in an LR parser moves the next input symbol onto the stack and transitions to a new state.
Correct Answer:
B
— To push a state onto the stack.
Learn More →
Q. In lexical analysis, what is a 'token'?
A.
A sequence of characters in the source code
B.
A data structure representing a keyword or identifier
C.
A type of error in the source code
D.
A part of the syntax tree
Show solution
Solution
A token is a data structure that represents a keyword, identifier, or other meaningful element in the source code.
Correct Answer:
B
— A data structure representing a keyword or identifier
Learn More →
Q. In LR parsing, what is the significance of the 'shift' action?
A.
To reduce the current production.
B.
To move the input pointer to the next token.
C.
To add a new production to the parse tree.
D.
To backtrack to a previous state.
Show solution
Solution
The 'shift' action in LR parsing moves the input pointer to the next token.
Correct Answer:
B
— To move the input pointer to the next token.
Learn More →
Q. In syntax-directed translation, what does an attribute represent?
A.
A semantic value associated with a grammar symbol
B.
A token type in lexical analysis
C.
A machine instruction in code generation
D.
A parsing strategy
Show solution
Solution
An attribute represents a semantic value associated with a grammar symbol in syntax-directed translation.
Correct Answer:
A
— A semantic value associated with a grammar symbol
Learn More →
Q. In syntax-directed translation, what is an intermediate code?
A.
A high-level representation of the source code
B.
A low-level machine code
C.
A representation that is easier to optimize than source code
D.
A representation that is not used in modern compilers
Show solution
Solution
Intermediate code is a representation that is easier to optimize than the original source code.
Correct Answer:
C
— A representation that is easier to optimize than source code
Learn More →
Q. In syntax-directed translation, what is the role of semantic actions?
A.
To define the grammar
B.
To perform type checking
C.
To generate intermediate code
D.
To handle syntax errors
Show solution
Solution
Semantic actions in syntax-directed translation are used to generate intermediate code based on the parse tree.
Correct Answer:
C
— To generate intermediate code
Learn More →
Q. In syntax-directed translation, which of the following is true about synthesized attributes?
A.
They are computed from the attributes of the parent node
B.
They are computed from the attributes of the child nodes
C.
They can only be used in inherited attributes
D.
They are not used in syntax-directed definitions
Show solution
Solution
Synthesized attributes are computed from the attributes of the child nodes in syntax-directed translation.
Correct Answer:
B
— They are computed from the attributes of the child nodes
Learn More →
Q. In the context of LL parsing, what does the '1' in LL(1) signify?
A.
One lookahead token is used.
B.
One leftmost derivation is produced.
C.
One parsing table is required.
D.
One recursive call is made.
Show solution
Solution
The '1' in LL(1) indicates that one lookahead token is used to make parsing decisions.
Correct Answer:
A
— One lookahead token is used.
Learn More →
Q. In three-address code, how is a binary operation typically represented?
A.
result = operand1 operator operand2
B.
operand1 operator operand2 = result
C.
result operator operand1 operand2
D.
operand1 operand2 operator = result
Show solution
Solution
Three-address code represents binary operations in the form 'result = operand1 operator operand2', which clearly indicates the result of the operation.
Correct Answer:
A
— result = operand1 operator operand2
Learn More →
Q. In three-address code, how many operands can each instruction have?
A.
One
B.
Two
C.
Three
D.
Four
Show solution
Solution
Three-address code typically allows for at most three operands: two source operands and one destination operand.
Correct Answer:
C
— Three
Learn More →
Q. What does common subexpression elimination achieve?
A.
It reduces the number of variables
B.
It eliminates duplicate calculations
C.
It simplifies control flow
D.
It increases the number of function calls
Show solution
Solution
Common subexpression elimination achieves the elimination of duplicate calculations, thus optimizing the code.
Correct Answer:
B
— It eliminates duplicate calculations
Learn More →
Q. What does dead code elimination refer to?
A.
Removing code that is never executed
B.
Optimizing loops
C.
Reducing variable declarations
D.
Simplifying expressions
Show solution
Solution
Dead code elimination refers to removing code that is never executed, which can help reduce the size of the code.
Correct Answer:
A
— Removing code that is never executed
Learn More →
Q. What does LR stand for in LR parsing?
A.
Left-to-right
B.
Right-to-left
C.
Left-to-right with lookahead
D.
Right-to-left with lookahead
Show solution
Solution
LR parsing stands for Left-to-right parsing with a rightmost derivation in reverse.
Correct Answer:
A
— Left-to-right
Learn More →
Q. What does the 'reduce' action do in an LR parser?
A.
It shifts the next input symbol onto the stack.
B.
It pops symbols from the stack and replaces them with a non-terminal.
C.
It accepts the input string.
D.
It generates an error.
Show solution
Solution
The 'reduce' action in an LR parser pops a number of symbols from the stack and replaces them with a non-terminal according to a production rule.
Correct Answer:
B
— It pops symbols from the stack and replaces them with a non-terminal.
Learn More →
Q. What does the term 'grammar ambiguity' refer to?
A.
Multiple valid parse trees for a single input
B.
The inability to parse a string
C.
A grammar that cannot be expressed in BNF
D.
A grammar with too many productions
Show solution
Solution
Grammar ambiguity refers to the situation where multiple valid parse trees can be generated for a single input string.
Correct Answer:
A
— Multiple valid parse trees for a single input
Learn More →
Q. What does the term 'register allocation' refer to in code generation?
A.
Assigning variables to CPU registers
B.
Allocating memory for dynamic variables
C.
Managing stack space for function calls
D.
Distributing tasks among multiple processors
Show solution
Solution
Register allocation refers to the process of assigning variables to CPU registers to optimize access speed.
Correct Answer:
A
— Assigning variables to CPU registers
Learn More →
Q. What does the term 'symbol table' refer to in a compiler?
A.
A table of syntax rules
B.
A data structure that stores information about identifiers
C.
A list of optimization techniques
D.
A representation of the abstract syntax tree
Show solution
Solution
A symbol table is a data structure that stores information about identifiers, such as their types and scopes.
Correct Answer:
B
— A data structure that stores information about identifiers
Learn More →
Q. What does the term 'token' refer to in the context of lexical analysis?
A.
A sequence of characters
B.
A data structure for syntax trees
C.
A meaningful sequence of characters
D.
A type of error in parsing
Show solution
Solution
In lexical analysis, a token refers to a meaningful sequence of characters that represents a basic element of the language.
Correct Answer:
C
— A meaningful sequence of characters
Learn More →
Q. What is a 'lexeme' in the context of lexical analysis?
A.
The smallest unit of meaning in a programming language
B.
The actual sequence of characters that matches a token
C.
A type of syntax error
D.
A representation of a variable in the symbol table
Show solution
Solution
A lexeme is the actual sequence of characters in the source code that matches a token.
Correct Answer:
B
— The actual sequence of characters that matches a token
Learn More →
A.
The smallest unit of a program
B.
A sequence of characters that matches a token
C.
A type of syntax error
D.
A part of the symbol table
Show solution
Solution
A lexeme is a sequence of characters in the source code that matches a token defined by the lexical analyzer.
Correct Answer:
B
— A sequence of characters that matches a token
Learn More →
Q. What is a common application of syntax-directed translation in compilers?
A.
Lexical analysis
B.
Code generation
C.
Syntax checking
D.
Semantic analysis
Show solution
Solution
A common application of syntax-directed translation in compilers is semantic analysis.
Correct Answer:
D
— Semantic analysis
Learn More →
Q. What is a common characteristic of intermediate code?
A.
It is always in binary format
B.
It is platform-specific
C.
It is easier to analyze than high-level code
D.
It cannot be optimized
Show solution
Solution
Intermediate code is generally easier to analyze than high-level code due to its simpler structure and reduced abstraction.
Correct Answer:
C
— It is easier to analyze than high-level code
Learn More →
Q. What is a common limitation of LL parsers?
A.
They cannot handle ambiguous grammars.
B.
They require more memory than LR parsers.
C.
They can only parse regular languages.
D.
They are slower than LR parsers.
Show solution
Solution
LL parsers cannot handle ambiguous grammars, which limits their applicability.
Correct Answer:
A
— They cannot handle ambiguous grammars.
Learn More →
Q. What is a common optimization technique applied during intermediate code generation?
A.
Loop unrolling
B.
Dead code elimination
C.
Inlining
D.
All of the above
Show solution
Solution
All of the listed techniques can be applied during the optimization phase of intermediate code generation to improve performance.
Correct Answer:
D
— All of the above
Learn More →
Q. What is intermediate code in the context of compilers?
A.
The final machine code
B.
A high-level representation of the source code
C.
An abstract representation of the program
D.
The source code itself
Show solution
Solution
Intermediate code is an abstract representation of the program that is independent of the target machine, allowing for easier optimization and code generation.
Correct Answer:
C
— An abstract representation of the program
Learn More →
Q. What is loop unrolling?
A.
A technique to increase the number of iterations in a loop
B.
A method to reduce the overhead of loop control
C.
A way to eliminate loops entirely
D.
A technique to optimize recursive functions
Show solution
Solution
Loop unrolling is a method to reduce the overhead of loop control by increasing the number of operations performed in each iteration.
Correct Answer:
B
— A method to reduce the overhead of loop control
Learn More →
Q. What is the advantage of using an abstract syntax tree (AST) in intermediate code generation?
A.
It is easier to optimize than linear representations
B.
It directly represents machine instructions
C.
It simplifies lexical analysis
D.
It is more compact than binary code
Show solution
Solution
An abstract syntax tree (AST) provides a hierarchical representation of the program structure, making it easier to apply optimizations compared to linear representations.
Correct Answer:
A
— It is easier to optimize than linear representations
Learn More →
Q. What is the main advantage of using syntax-directed translation?
A.
It simplifies the parsing process
B.
It allows for easy integration of semantic analysis
C.
It eliminates the need for an intermediate representation
D.
It speeds up the lexical analysis phase
Show solution
Solution
The main advantage of using syntax-directed translation is that it allows for easy integration of semantic analysis.
Correct Answer:
B
— It allows for easy integration of semantic analysis
Learn More →
Q. What is the main challenge of optimizing code for different architectures?
A.
Different programming languages
B.
Varying instruction sets and performance characteristics
C.
Inconsistent coding standards
D.
Lack of documentation
Show solution
Solution
The main challenge of optimizing code for different architectures is the varying instruction sets and performance characteristics.
Correct Answer:
B
— Varying instruction sets and performance characteristics
Learn More →
Q. What is the main characteristic of LL parsing?
A.
It uses a top-down approach.
B.
It uses a bottom-up approach.
C.
It requires left recursion.
D.
It is non-deterministic.
Show solution
Solution
LL parsing is a top-down parsing technique that processes the input from left to right and constructs a leftmost derivation of the sentence.
Correct Answer:
A
— It uses a top-down approach.
Learn More →
Showing 1 to 30 of 98 (4 Pages)