NEW
Font size
WorksheetsCompiler Design -Lexical analysis and Syntax analysis
Total questions: 12
Worksheet time: 6mins
Which phase of a compiler is responsible for converting source code into tokens?
Syntax analysis
Semantic Analysis
Lexical analysis
Code Generation
What does the syntax analysis phase of a compiler produce?
Intermediate code
Token streams
Symbol table
Parse tree
In compiler design, which of the following is NOT a type of intermediate representation (IR)?
Abstract syntax tree
machine code
Three address code
Context free grammar
What is the purpose of the symbol table in a compiler?
To optimize code
To generate machine code
To store information about identifiers
To parse tokens
In the context of parsing, what does the 'Follow' set of a non-terminal symbol contain?
All terminal symbols that can appear at the beginning of the non-terminal's productions
All terminal symbols that can follow the non-terminal in the grammar's rules
All terminal symbols that can appear immediately after the non-terminal in any valid string
All symbols that can be derived from the non-terminal
Given a grammar, how do you compute the First() set for a non-terminal?
it contains all terminal symbols that can appear at the beginning of any string derived from the non-terminal.
It contains all terminal symbols that can follow the non-terminal in the grammar.
It contains all symbols that can be derived from the non-terminal
It contains all symbols that can be produced by the non-terminal in the grammar’s rules.
In an LL(1) parsing table, what does a conflict at a table entry indicate?
The grammar is left recursive
The parser has successfully parsed the input
The grammar is ambiguous
The table is complete and correct
What is a common limitation of top-down parsers?
They cannot handle left-recursive grammars.
They are slower than bottom-up parsers.
They are unable to build parse trees.
They require a large number of lookahead tokens.
What is the purpose of the lookahead token in top-down parsing?
To check for semantic errors
To generate intermediate code
To determine which production rule to apply next
To backtrack and retry parsing strategies
Which of the following is true about predictive parsing?
It uses a stack to keep track of symbols during parsing.
It relies on a parsing table that is constructed from the grammar's First() and Follow() sets.
It requires backtracking to handle ambiguous grammars.
It is a bottom-up parsing technique that generates parse trees from leaves to root.
What is the primary challenge of shift-reduce parsing with respect to grammar?
It requires grammars to be unambiguous and in a suitable form for parsing.
It uses multiple lookahead tokens to resolve parsing conflicts.
It may require backtracking to handle certain grammars.
It can handle left-recursive grammars without modification.
In shift-reduce parsing, what does the 'shift' operation do?
It replaces a non-terminal symbol on the stack with a production rule.
It moves the top symbol of the stack to the input buffer.
It pushes the next input token onto the stack.
It reduces a sequence of symbols on the stack to a non-terminal symbol.
