0% found this document useful (0 votes)
31 views8 pages

CS3501 CD Qb-Unit 2

CS3501 CD QB-UNIT 2

Uploaded by

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

CS3501 CD Qb-Unit 2

CS3501 CD QB-UNIT 2

Uploaded by

paviganesh8789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

DEPARTMENT OF COMPUTING TECHNOLOGIES

Name of the Faculty Member : Mrs.R.PAVITHRA


Designation and Department : ASSISTANT PROFESSOR / CT
Academic Year : 2024-2025(ODD)
Class : III -CSE
Subject with Code & Name : CS3501 – COMPILER DESIGN
QUESTION BANK
UNIT-2 SYNTAX ANALYSIS

1. What are the goals of error handler in a parser? [NOV/DEC 2023]

The goals of an error handler in a parser are designed to ensure robustness


and usability when dealing with errors during the parsing process

 Error Detection

 Error Reporting

 Error Recovery

 Contextual Analysis

 Fallback Mechanisms

 User-Friendly Feedback

2. Define parse tree. [NOV/DEC 2023]

A parse tree, also known as a syntax tree, is a graphical representation


of the syntactic structure of a sentence in a formal language. It illustrates

Page 1 of 8
how the components of the sentence (such as words and phrases) are
organized according to the rules of grammar.

3. What are the different error-recovery strategies that a parser can


employ to recover from a syntactic error? [NOV/DEC 2021]

 Panic mode recovery


 Phrase level recovery
 Error Production.
 Global Correction.

4. Define the function of left factoring. [NOV/DEC 2021]

 Elimination of Ambiguity

 Improvement in Parsing Efficiency

 Support for LL Parsing Techniques

 Simplification of Grammar Rules

 Compatibility with Recursive Descent Parsing

5. Consider the following grammar : [NOV/DEC 2021]

S→A
A → A + A |B++
B→y
Show a leftmost and rightmost derivation for the string “y + + + y + +”

6. Consider the following grammar and demonstrate that the grammar is


ambiguous by showing two different parse trees for some string.

[NOV/DEC 2021]

S → AB |aaB

A → a|Aa

B→b

Page 2 of 8
7. Define Recursive Descent Parsing?

A Recursive Descent Parser (RDP) is a type of top-down parsing technique


used incomputer science to analyze and process a language's syntax

8. Differentiate Top Down parsing and Bottom Up parsing?


[APR/MAY 2012]
Top Down parsing Bottom Up parsing
It is a parsing strategy that first It is a parsing strategy that first
looks atthe highest level of the parse looks atthe lowest level of the parse
tree andworks tree andworks up
down the parse tree by using therules the parse tree by using the
of grammar. rulesof grammar.
This parsing technique uses This parsing technique uses Right
Left MostDerivation. MostDerivation.
Example: Recursive Descent parser. Example: Its Shift Reduce parser.

9. Compare Syntax tree and Parse tree. [NOV/DEC 2012]

Syntax tree:
A special kind of tree called a syntax tree is used, in which
each node represents an operation and the children of a node
represent the arguments of the operation.

Parse Tree:

A parse tree may be viewed as a graphical representation for a


derivation that filters out the choice regarding replacement order.
Each interior node of a parse tree is labeled by some nonterminal A
and that the children of the node are labeled from left to right by
symbols in the right side of the production by which this A was
replaced in the derivation. The leaves of the parse tree are terminal
symbols.

10.Write the rule to eliminate left recursion in a grammar.

[NOV/DEC 2012]

Page 3 of 8
A grammar is said to be left recursive if it has a non-terminal A such that
there is a derivation A=>Aα for some string α.

If there is a production A → Aα |β it can be replaced with a


sequence of two productions

A → βA’
A’→ αA’ | ε
without changing the set of strings derivable from A
11.Mention the role of semantic analysis. [NOV/DEC 2012]
There is more to a front end than simply syntax. The compiler needs
semantic information, e.g., the types (integer, real, pointer to array of integers,
etc) of the objects involved. This enables checking for semantic errors and
inserting type conversion where necessary.

For example, if y was declared to be a real and x3 an integer, We need


to insert (unary, i.e., one operand) conversion operators “inttoreal” and
“realtoint” as shown on the right.

12.Draw the syntax tree for the expression: a=b*-c +b*-c


[NOV/DEC 2012]
A syntax tree depicts the natural hierarchical structure of a source
program. A DAG (Directed Acyclic Graph) gives the same information but in
a more compact way because common sub-expressions are identified. A
syntax tree for the assignment statement a:=b*-c+b*-c appear in the figure.

Page 4 of 8
.

Fig: Graphical Representation of a := b * -c + b * -c


13.Eliminate left recursion from the following grammar A->Ac/Aad/bd/€.
A->bdA‟/A‟
A‟->cA‟/adA‟/€
14.Eliminate left recursion from the grammar S-> Aa | b ; A-> Ac | Sd | €.
Ans: S-> Aa
| b ; A-> Ac|
Aad |bd|€

15.Write the role of parser. [APR/ MAY 2015]


a. The parser or syntactic analyzer obtains a string of tokens
from the lexical analyzer and verifies that the string can be
generated by the grammar for the source language.
b. It reports any syntax errors in the program.
c. It also recovers from commonly occurring errors so that it can
continue processing its input.
16.Write a grammar for branching statement. [APR/ MAY 2016]
S ->iEtS | iEtSeS | a E -> b
17.Write the algorithm for FIRST and FOLLOW in parser. [APR/ MAY
2016]
First() : Let  be a string of grammar symbols. First() is the set that
includes every terminal that appears leftmost in  or in any string
originating from .
Follow () : Let A be a non-terminal. Follow(A) is the set of
terminals a that can appear directly to the right of A in some
sentential form. (S  Aa, for some  and
).
Rules for follow( ):
Page 5 of 8
1. If S is a start symbol, then FOLLOW(S) contains $.
2. If there is a production A → αBβ, then everything in FIRST(β)
except ε is placed in follow(B).
3. If there is a production A → αB, or a production A → αBβ
where FIRST(β) contains ε, then everything in FOLLOW(A)
is in FOLLOW(B).

18.What is meant by handle pruning? [NOV/DEC 2016]


An Handle of a string is a sub string that matches the right side of
production and whose reduction to the non terminal on the left side of the
production represents one step along the reverse of a rightmost derivation.
The process of obtaining rightmost derivation in reverse is known as
Handle Pruning.
Consider the grammar:
E → E+E/E*E/(E)/id
And the input string
id1+id2*id3
The rightmost derivation is :
→ E +E

→ E+E*E

→ E+E*id3

→ E+id2*id 3

→ id1+id2*id3

19.Define YACC.
Yacc - Yet Another Compiler-Compiler
 Tool which will produce a parser for a given grammar.
 YACC (Yet Another Compiler Compiler) is a program
designed to compile a LALR(1) grammar and to produce the
source code of the syntactic analyzer of the language produced
by this grammar.

Page 6 of 8
20.What is LL (1) grammar? Give the properties of LL (1) grammar.
L : Scan input from Left to Right
L : Construct a Leftmost Derivation
1 : Use “1” input symbol as lookahead in conjunction with stack to
decide on the parsing action LL(1) grammars == they have no
multiply-defined entries in the parsing

Part-B
1. Briefly discuss about design of a syntax analyzer for a sample
Language [Nov/Dec 2023]
2. Explain LR parsing algorithm with example [Nov/Dec 17,2023]
3. How context free grammar will work and compare various parser
techniques performance using various code blocks example
[Nov/Dec 2023]
4. Construct a predictive parsing table for the grammar.
S->(L)|a
L->L,S|S
and show whether the following string will be accepted or not.
(a,(a,(a, a ))) [Nov / Dec 2021]
5. Write an Algorithm and construct SLR Parsing Table for the
following context freegrammar. Check whether the string id + id*id is
a valid string [Nov / Dec 2021]
i. E→E+T | T
Page 7 of 8
ii. T→T*F | F F→F*| a| b

6. Construct LL (1) parsing table for the following grammar using


FIRST and FOLLOW set. [Nov / Dec 2020]
S->UVW
U->(S)|aSb|d
V->aV|e
W->cW|e. Give the parsing actions for the input string “(dc)ac”.
7. Consider the following grammar. Parse the input string “abbcde”
using stack implementation of shift-reduce parser. [Nov / Dec 2020]
S → aABe
A → Abc | b
B→d
8. Explain LALR Parsing algorithm with example

9. Explain in detail YACC [Nov / Dec 2017]

10.Give the LALR for the given grammar.S->AAA->Aa|b


11.Construct Stack implementation of shift reduce parsing for the
Grammar E->E+EE->E*EE->(E)E->id and the input string
id1+id2*id3

STAFF INCHARGE HOD

Page 8 of 8

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy