Q. Which of the following best describes 'tokenization'?
A.
The process of generating machine code
B.
The process of converting source code into tokens
C.
The process of optimizing code
D.
The process of parsing syntax
Show solution
Solution
Tokenization is the process of converting source code into tokens that can be processed by the compiler.
Correct Answer:
B
— The process of converting source code into tokens
Learn More →
Q. Which of the following best describes inherited attributes?
A.
Attributes passed from parent to child nodes
B.
Attributes computed from child nodes
C.
Attributes that do not affect the translation
D.
Attributes that are only used in semantic actions
Show solution
Solution
Inherited attributes are attributes passed from parent to child nodes in syntax-directed translation.
Correct Answer:
A
— Attributes passed from parent to child nodes
Learn More →
Q. Which of the following best describes synthesized attributes?
A.
Attributes that are passed down from parent to child nodes
B.
Attributes that are computed from the values of child nodes
C.
Attributes that are used only during lexical analysis
D.
Attributes that are not used in syntax-directed translation
Show solution
Solution
Synthesized attributes are computed from the values of child nodes in the parse tree.
Correct Answer:
B
— Attributes that are computed from the values of child nodes
Learn More →
Q. Which of the following best describes the relationship between a lexer and a parser?
A.
The lexer generates machine code, while the parser checks syntax
B.
The lexer produces tokens, which the parser uses to build a syntax tree
C.
The lexer and parser perform the same function
D.
The parser generates tokens, while the lexer checks syntax
Show solution
Solution
The lexer produces tokens that the parser uses to build a syntax tree, making them complementary components in the compilation process.
Correct Answer:
B
— The lexer produces tokens, which the parser uses to build a syntax tree
Learn More →
Q. Which of the following best describes the relationship between syntax trees and intermediate code?
A.
Syntax trees are generated after intermediate code
B.
Intermediate code is generated directly from syntax trees
C.
Syntax trees and intermediate code are the same
D.
Intermediate code is generated before syntax trees
Show solution
Solution
Intermediate code is often generated from syntax trees, which represent the structure of the source code.
Correct Answer:
B
— Intermediate code is generated directly from syntax trees
Learn More →
Q. Which of the following grammars can be parsed using LL(1) parsing?
A.
Left-recursive grammars
B.
Ambiguous grammars
C.
Non-left-recursive and unambiguous grammars
D.
Context-free grammars only
Show solution
Solution
LL(1) parsing can only be applied to non-left-recursive and unambiguous grammars.
Correct Answer:
C
— Non-left-recursive and unambiguous grammars
Learn More →
Q. Which of the following is a benefit of using intermediate code in a compiler?
A.
It eliminates the need for parsing
B.
It allows for easier debugging of the source code
C.
It enables code generation for multiple target architectures
D.
It simplifies lexical analysis
Show solution
Solution
Using intermediate code allows a compiler to generate code for multiple target architectures from the same intermediate representation, enhancing portability.
Correct Answer:
C
— It enables code generation for multiple target architectures
Learn More →
Q. Which of the following is a characteristic of a runtime environment?
A.
It is only used during compilation
B.
It manages memory allocation and deallocation
C.
It translates high-level code to machine code
D.
It performs syntax analysis
Show solution
Solution
A runtime environment manages memory allocation and deallocation during the execution of a program.
Correct Answer:
B
— It manages memory allocation and deallocation
Learn More →
Q. Which of the following is a characteristic of LL(1) parsing?
A.
It uses a stack for parsing
B.
It can handle left recursion
C.
It requires backtracking
D.
It is a top-down parsing method
Show solution
Solution
LL(1) parsing is a top-down parsing method that does not require backtracking and cannot handle left recursion.
Correct Answer:
D
— It is a top-down parsing method
Learn More →
Q. Which of the following is a common data structure used to represent the syntax tree in compilers?
A.
Array
B.
Linked list
C.
Binary tree
D.
Hash table
Show solution
Solution
A binary tree is commonly used to represent the syntax tree, where each node represents a construct in the source code.
Correct Answer:
C
— Binary tree
Learn More →
Q. Which of the following is a common error detected by a lexical analyzer?
A.
Syntax errors
B.
Type errors
C.
Unrecognized characters
D.
Semantic errors
Show solution
Solution
A lexical analyzer can detect unrecognized characters that do not match any defined tokens.
Correct Answer:
C
— Unrecognized characters
Learn More →
Q. Which of the following is a common form of intermediate code generated by syntax-directed translation?
A.
Assembly language
B.
Three-address code
C.
Bytecode
D.
Machine code
Show solution
Solution
Three-address code is a common form of intermediate code generated by syntax-directed translation.
Correct Answer:
B
— Three-address code
Learn More →
Q. Which of the following is a common method for performing constant folding?
A.
Evaluating expressions at compile time
B.
Removing unused variables
C.
Inlining functions
D.
Rearranging code for efficiency
Show solution
Solution
Constant folding involves evaluating constant expressions at compile time to simplify the code.
Correct Answer:
A
— Evaluating expressions at compile time
Learn More →
Q. Which of the following is a common technique used in code optimization?
A.
Inlining functions
B.
Adding more comments
C.
Increasing variable scope
D.
Using more complex data structures
Show solution
Solution
Inlining functions is a common technique used in code optimization to reduce function call overhead.
Correct Answer:
A
— Inlining functions
Learn More →
Q. Which of the following is a common technique used in lexical analysis?
A.
Recursive descent parsing
B.
Finite state machines
C.
Dynamic programming
D.
Backtracking
Show solution
Solution
Finite state machines are commonly used in lexical analysis to recognize tokens based on regular expressions.
Correct Answer:
B
— Finite state machines
Learn More →
Q. Which of the following is a key advantage of LR parsing over LL parsing?
A.
LR parsing can handle left recursion.
B.
LR parsing is simpler to implement.
C.
LL parsing can handle more complex grammars.
D.
LR parsing requires less memory.
Show solution
Solution
LR parsing can handle left recursion, which LL parsing cannot.
Correct Answer:
A
— LR parsing can handle left recursion.
Learn More →
Q. Which of the following is a requirement for an LL(1) parser?
A.
The grammar must be left recursive.
B.
The grammar must be ambiguous.
C.
The grammar must be free of left recursion.
D.
The grammar must have multiple left factors.
Show solution
Solution
An LL(1) parser requires the grammar to be free of left recursion to ensure that it can make decisions based on a single lookahead token.
Correct Answer:
C
— The grammar must be free of left recursion.
Learn More →
Q. Which of the following is an advantage of using intermediate code?
A.
It simplifies the parsing process
B.
It allows for easier debugging
C.
It enables machine-independent optimizations
D.
It eliminates the need for a front-end
Show solution
Solution
Intermediate code allows for optimizations that are independent of the target machine, making it easier to optimize across different architectures.
Correct Answer:
C
— It enables machine-independent optimizations
Learn More →
Q. Which of the following is an example of a syntax error?
A.
Using an undeclared variable
B.
Missing a semicolon
C.
Dividing by zero
D.
Using the wrong data type
Show solution
Solution
A syntax error occurs when the code does not conform to the grammatical rules of the programming language, such as missing a semicolon.
Correct Answer:
B
— Missing a semicolon
Learn More →
Q. Which of the following is NOT a benefit of code optimization?
A.
Improved performance
B.
Reduced memory usage
C.
Increased code complexity
D.
Faster execution time
Show solution
Solution
Increased code complexity is NOT a benefit of code optimization; optimizations aim to maintain or reduce complexity.
Correct Answer:
C
— Increased code complexity
Learn More →
Q. Which of the following is NOT a common form of intermediate code?
A.
Three-address code
B.
Abstract syntax tree
C.
Bytecode
D.
Machine code
Show solution
Solution
Machine code is the final output of a compiler, while three-address code, abstract syntax trees, and bytecode are forms of intermediate code.
Correct Answer:
D
— Machine code
Learn More →
Q. Which of the following is NOT a phase of syntax analysis?
A.
Parsing
B.
Lexical analysis
C.
Semantic analysis
D.
Intermediate code generation
Show solution
Solution
Intermediate code generation is not a phase of syntax analysis; it occurs after syntax analysis.
Correct Answer:
D
— Intermediate code generation
Learn More →
Q. Which of the following is NOT a phase of the compilation process?
A.
Lexical analysis
B.
Syntax analysis
C.
Runtime environment setup
D.
Code generation
Show solution
Solution
Runtime environment setup is not a phase of compilation; it is part of the execution of the compiled program.
Correct Answer:
C
— Runtime environment setup
Learn More →
Q. Which of the following is NOT a type of attribute in syntax-directed translation?
A.
Synthesized attribute
B.
Inherited attribute
C.
Static attribute
D.
Contextual attribute
Show solution
Solution
Static attribute is not a recognized type of attribute in syntax-directed translation.
Correct Answer:
C
— Static attribute
Learn More →
Q. Which of the following is NOT a type of LR parser?
A.
SLR
B.
LALR
C.
LR(1)
D.
LL(1)
Show solution
Solution
LL(1) is not a type of LR parser; it is a type of LL parser.
Correct Answer:
D
— LL(1)
Learn More →
Q. Which of the following is NOT a type of parsing technique?
A.
Top-down parsing
B.
Bottom-up parsing
C.
Left-to-right parsing
D.
Right-to-left parsing
Show solution
Solution
Right-to-left parsing is not a standard parsing technique; the common techniques are top-down and bottom-up.
Correct Answer:
D
— Right-to-left parsing
Learn More →
Q. Which of the following is NOT a typical output of a lexical analyzer?
A.
Tokens
B.
Symbol table
C.
Abstract syntax tree
D.
Error messages
Show solution
Solution
An abstract syntax tree is typically produced by the parser, not the lexical analyzer.
Correct Answer:
C
— Abstract syntax tree
Learn More →
Q. Which of the following is true about SLR parsing?
A.
It uses a single lookahead token.
B.
It is a type of LL parsing.
C.
It can handle all context-free grammars.
D.
It is less powerful than canonical LR parsing.
Show solution
Solution
SLR parsing is less powerful than canonical LR parsing as it uses a simpler method for constructing the parsing table.
Correct Answer:
D
— It is less powerful than canonical LR parsing.
Learn More →
Q. Which of the following optimizations can be performed on intermediate code?
A.
Dead code elimination
B.
Lexical analysis
C.
Syntax checking
D.
Code generation
Show solution
Solution
Dead code elimination is an optimization technique that can be applied to intermediate code to remove code that does not affect the program's output.
Correct Answer:
A
— Dead code elimination
Learn More →
Q. Which of the following parsing techniques can handle a larger class of grammars?
A.
LL parsing
B.
LR parsing
C.
Recursive descent parsing
D.
Predictive parsing
Show solution
Solution
LR parsing can handle a larger class of grammars compared to LL parsing, including all deterministic context-free grammars.
Correct Answer:
B
— LR parsing
Learn More →
Showing 61 to 90 of 98 (4 Pages)