wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Compiler Design -Lexical analysis and Syntax analysis

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

Which phase of a compiler is responsible for converting source code into tokens?

a)

Syntax analysis

b)

Semantic Analysis

c)

Lexical analysis

d)

Code Generation

2.

What does the syntax analysis phase of a compiler produce?

a)

Intermediate code

b)

Token streams

c)

Symbol table

d)

Parse tree

3.

In compiler design, which of the following is NOT a type of intermediate representation (IR)?

a)

Abstract syntax tree

b)

machine code

c)

Three address code

d)

Context free grammar

4.

What is the purpose of the symbol table in a compiler?

a)

To optimize code

b)

To generate machine code

c)

To store information about identifiers

d)

To parse tokens

5.

In the context of parsing, what does the 'Follow' set of a non-terminal symbol contain?

a)

All terminal symbols that can appear at the beginning of the non-terminal's productions

b)

All terminal symbols that can follow the non-terminal in the grammar's rules

c)

All terminal symbols that can appear immediately after the non-terminal in any valid string

d)

All symbols that can be derived from the non-terminal

6.

Given a grammar, how do you compute the First() set for a non-terminal?

a)

it contains all terminal symbols that can appear at the beginning of any string derived from the non-terminal.

b)

It contains all terminal symbols that can follow the non-terminal in the grammar.

c)

It contains all symbols that can be derived from the non-terminal

d)

It contains all symbols that can be produced by the non-terminal in the grammar’s rules.

7.

In an LL(1) parsing table, what does a conflict at a table entry indicate?

a)

The grammar is left recursive

b)

The parser has successfully parsed the input

c)

The grammar is ambiguous

d)

The table is complete and correct

8.

What is a common limitation of top-down parsers?

a)
  • They cannot handle left-recursive grammars.

b)
  • They are slower than bottom-up parsers.

c)
  • They are unable to build parse trees.

d)
  • They require a large number of lookahead tokens.

9.

What is the purpose of the lookahead token in top-down parsing?

a)
  • To check for semantic errors

b)
  • To generate intermediate code

c)
  • To determine which production rule to apply next

d)
  • To backtrack and retry parsing strategies

10.

Which of the following is true about predictive parsing?

a)
  • It uses a stack to keep track of symbols during parsing.

b)
  • It relies on a parsing table that is constructed from the grammar's First() and Follow() sets.

c)

It requires backtracking to handle ambiguous grammars.

d)

It is a bottom-up parsing technique that generates parse trees from leaves to root.

11.

What is the primary challenge of shift-reduce parsing with respect to grammar?

a)
  • It requires grammars to be unambiguous and in a suitable form for parsing.

b)
  • It uses multiple lookahead tokens to resolve parsing conflicts.

c)
  • It may require backtracking to handle certain grammars.

d)
  • It can handle left-recursive grammars without modification.

12.

In shift-reduce parsing, what does the 'shift' operation do?

a)
  • It replaces a non-terminal symbol on the stack with a production rule.

b)

It moves the top symbol of the stack to the input buffer.

c)
  • It pushes the next input token onto the stack.

d)
  • It reduces a sequence of symbols on the stack to a non-terminal symbol.