0% found this document useful (0 votes)
3 views6 pages

Syntax Analysis in Compiler Design

The document contains a series of questions and answers related to syntax analysis in the compilation process, covering topics such as parse trees, parsing techniques, and grammar types. It includes multiple-choice questions that test knowledge on context-free grammar, parsing algorithms, and error recovery strategies. The answers provided indicate the correct options for each question.

Uploaded by

dinksrawf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Syntax Analysis in Compiler Design

The document contains a series of questions and answers related to syntax analysis in the compilation process, covering topics such as parse trees, parsing techniques, and grammar types. It includes multiple-choice questions that test knowledge on context-free grammar, parsing algorithms, and error recovery strategies. The answers provided indicate the correct options for each question.

Uploaded by

dinksrawf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Syntax Analyzer

1) What is the purpose of syntax analysis in the compilation process?


A. To analyze the physical structure of the program.
B. To analyze the logical structure of the program.
C. To analyze the syntax of the program.
D. To analyze the semantic structure of the program.
2) What is a context-free grammar?
A. A grammar that describes the syntax of a programming language.
B. A grammar that describes the semantics of a programming language.
C. A grammar that describes the physical structure of a program.
D. A grammar that describes the logical structure of a program.
3) What is a parse tree?
A. A tree-like data structure that represents the syntactic structure of a program.
B. A tree-like data structure that represents the semantic structure of a program.
C. A tree-like data structure that represents the physical structure of a program.
D. A tree-like data structure that represents the logical structure of a program.
4) What is the difference between a parse tree and an abstract syntax tree (AST)?
A. A parse tree represents the concrete syntax, while an AST represents the abstract syntax.
B. A parse tree represents the abstract syntax, while an AST represents the concrete syntax.
C. A parse tree is a tree-like data structure, while an AST is a graph-like data structure.
D. A parse tree is generated during lexical analysis, while an AST is generated during semantic
analysis.
5) Which of the following is NOT a common type of parser?
A. LL parser.
B. LR parser.
C. SLR parser.
D. LALR parser.
6) What is the main advantage of using a top-down parsing technique?
A. It is more efficient in terms of time and space complexity.
B. It can handle a wider class of grammars compared to bottom-up parsing.
C. It is easier to implement and debug.
D. It produces a more compact parse tree.
7) Which parsing technique uses a stack to store grammar symbols and a parsing table for
decision-making?
A. Recursive descent parsing.
B. Shift-reduce parsing.
C. Top-down parsing.
D. Bottom-up parsing.
8) What is the purpose of a parsing table in shift-reduce parsing?
A. To store the input source code.
B. To store the grammar rules.
C. To store the intermediate code generated by the parser.
D. To guide the parser's actions during the parsing process.
9) Which parsing technique builds the parse tree from the leaves (tokens) to the root (start
symbol)?
A. Recursive descent parsing.
B. Shift-reduce parsing.
C. Top-down parsing.
D. Bottom-up parsing.
10) Which of the following is NOT a common bottom-up parsing algorithm?
A. SLR parsing.
B. LALR parsing.
C. LR parsing.
D. LL parsing.
11) What is the purpose of the lookahead symbol in parsing?
A. To determine which production rule to apply.
B. To indicate the end of the input.
C. To store the parsed tokens.
D. To store the parse tree.
12) Which parsing technique can handle left-recursive productions?
A. Recursive descent parsing.
B. Shift-reduce parsing.
C. Top-down parsing.
D. Bottom-up parsing.
13) What is a shift action in shift-reduce parsing?
A. It moves the input pointer to the right.
B. It reduces a group of grammar symbols to a nonterminal.
C. It adds a grammar symbol to the stack.
D. It indicates the completion of the parsing process.
14) Which of the following parsing algorithms is more powerful in terms of the class of grammars it
can handle?
A. LL parsing.
B. LR parsing.
C. SLR parsing.
D. LALR parsing.
15) What is left factoring in the context of parsing?
A. It is a technique used to eliminate left recursion from grammar rules.
B. It is a technique used to combine similar productions into a single production.
C. It is a technique used to determine the next input symbol during parsing.
D. It is a technique used to combine multiple parsing algorithms into a single algorithm.
16) Which of the following is NOT an advantage of LR parsing?
A. It can handle a wide class of grammars, including left-recursive grammars.
B. It is more efficient in terms of time and space complexity compared to LL parsing.
C. It can generate a parse table that can be used for efficient parsing.
D. It is easier to implement and debug compared to LL parsing.
17) Which of the following is NOT a step in the parsing process?
A. Lexical analysis.
B. Syntactic analysis.
C. Semantic analysis.
D. Code generation.
18) What is the purpose of an LL(1) item in LL parsing?
A. To represent a production rule in the grammar.
B. To indicate the current position in the parsing process.
C. To store the lookahead symbols for a particular production rule.
D. To store the intermediate results of the parsing process.
19) Which of the following is NOT a valid LR parsing table entry?
A. Shift.
B. Reduce.
C. Accept.
D. Loop.
20) What is the purpose of the follow set in LL parsing?
A. To determine the start symbol of the grammar.
B. To determine the lookahead symbol during parsing.
C. To determine the first set of a nonterminal symbol.
D. To determine the follow set of a nonterminal symbol.
21) Which of the following is NOT a top-down parsing technique?
A. Recursive descent parsing.
B. LL parsing.
C. LALR parsing.
D. Predictive parsing.
22) What is left recursion in the context of parsing?
A. It is a parsing technique that starts from the leftmost symbol and expands it until the
rightmost symbol is reached.
B. It is a technique used to eliminate nonterminal symbols from the grammar.
C. It is a technique used to eliminate ambiguity from the grammar.
D. It is a situation where a nonterminal symbol appears as the leftmost symbol in its own
production rule.
23) Which of the following is NOT a step in the bottom-up parsing process?
A. Reduction.
B. Shifting.
C. Parsing.
D. Matching.
24) What is LL parsing?
A. A top-down parsing technique that reads the input from left to right and constructs a
leftmost derivation.
B. A bottom-up parsing technique that reads the input from left to right and constructs a
rightmost derivation.
C. A parsing technique that generates an abstract syntax tree from the input.
D. A parsing technique that analyzes the semantics of a program.
25) Which of the following is NOT a characteristic of LL parsing?
A. It uses a predictive parsing table.
B. It is easy to implement and understand.
C. It can handle left-recursive grammars.
D. It can handle a wide class of grammars.
26) What is the main advantage of LL parsing?
A. It has better time and space complexity compared to other parsing techniques.
B. It can handle a wider class of grammars compared to other parsing techniques.
C. It is easier to implement and debug compared to other parsing techniques.
D. It produces a more compact parse tree compared to other parsing techniques.
27) Which of the following is NOT a step in LL parsing?
A. Tokenization.
B. Construction of the parsing table.
C. Parsing the input using the parsing table.
D. Building the parse tree.
28) What is the significance of the "1" in LL(1) parsing?
A. It represents the number of lookahead symbols.
B. It represents the number of nonterminal symbols in the grammar.
C. It represents the number of terminal symbols in the grammar.
D. It represents the number of production rules in the grammar.
29) What is the FIRST set of a nonterminal symbol?
A. The set of terminal symbols that can appear as the first symbol in a derivation of the
nonterminal.
B. The set of terminal symbols that can appear as the last symbol in a derivation of the
nonterminal.
C. The set of nonterminal symbols that can appear as the first symbol in a derivation of the
nonterminal.
D. The set of nonterminal symbols that can appear as the last symbol in a derivation of the
nonterminal.
30) Which of the following is NOT a factor that can lead to a parsing conflict in LL parsing?
A. First/Follow conflict.
B. Shift/Reduce conflict.
C. Reduce/Reduce conflict.
D. Lookahead conflict.
31) What is a parsing table in LL parsing?
A. A table that maps nonterminal symbols and lookahead symbols to production rules.
B. A table that stores the intermediate results of the parsing process.
C. A table that represents the abstract syntax tree of the input program.
D. A table that maps terminal symbols and nonterminal symbols to lexer rules.
32) The output from the parser is usually.
A. Symbol table
B. String.
C. Source programs.
D. Parse tree.
33) Panic mode is a type of strategy.
A. Error detection.
B. Error avoidance.
C. Error recovery.
D. Error creation.
34) A grammar that produces more than one parse tree for some sentence is said to be .
A. ambiguous
B. semantic
C. syntactic
D. unambiguous
35) An efficient non-backtracking from of top-down parser is called.
A. Unproductive parser.
B. Predictive parser.
C. Ambiguous parser.
D. Sematic parser.

Answer

1. C
2. A
3. A
4. A
5. C
6. C
7. B
8. D
9. D
10. D
11. A
12. A
13. A
14. B
15. B
16. D
17. A
18. C
19. D
20. D
21. C
22. D
23. D
24. A
25. D
26. C
27. A
28. A
29. A
30. D
31. A
32. D
33. C
34. A
35. B

You might also like