Examples: Top Down Parsing | Compiler Design - Computer Science Engineering (CSE) PDF Download

Example 2:
Construct a predictive parsing table for the given grammar or Check whether the given grammar is LL(1) or not.
S → iEtSS| a
SI → eS | ∈
E → b
 

Solution: 1. Computation of First () set:

1. First (E) = first (b) = {b}

2. First (SI) = first (eS) È ∪ first (e) = {e, e}

3. first (S) = first (iEtSSI) È∪ first (a) = {i, a}

2. Computation of follow() set:

1. follow (S) = {$} È∪ first (SI)  {e} È ∪ follow (S) È ∪ follow (SI) = {$} È {e} = {e, $}

2. follow (SI) = follow  ∪ (S) = {e, $}

3. follow (E) = first (tSSI) = {t} 
 

3. The parsing table for this grammar is:
 

Examples: Top Down Parsing | Compiler Design - Computer Science Engineering (CSE)  
 

As the table multiply defined entry. The given grammar is not LL(1). 
 

Example 3:
Construct the FIRST and FOLLOW and predictive parse table for the grammar:
S→ AC$
C → c | Î A → aBCd | BQ | Î B → bB | d Q → q

Solution:
1. Finding the first () sets:
First (Q) = {q}
First (B) = {b, d} 
First (C) = {c, e}
First (A) = First (aBCd) È First (BQ) È First (e)
= {a} È First (B) È First (d) È{e}
= {a} È First (bB) È First (d) È {e}
= {a} È {b} È {d} È {e}
= {a, b, d, e} First (S) = First (AC$)
= (First (A)  {e}) È (First (C)  {e}) È First (e)
= ({a, b, d, e}  {e}) È ({c, e}  {e}) È {e}
= {a, b, d, c, e} 


2. Finding Follow () sets: Follow (S) = {#}
Follow (A) = (First (C) – {e}) È First ($) = ({c, e}  {e}) È {$}
Follow (A) = {c, $} Follow (B) = (First (C)  {e}) È First (d) È First (Q)
= {c} È {d} È {q} = {c, d, q} Follow (C) = (First ($) È First (d) = {d, $}
Follow (Q) = (First (A) = {c, $}

3. The parsing table for this grammar is: 
 

Examples: Top Down Parsing | Compiler Design - Computer Science Engineering (CSE)
 

4. Moves made by predictive parser on the input abdcdc$ is:
 

Examples: Top Down Parsing | Compiler Design - Computer Science Engineering (CSE)

The document Examples: Top Down Parsing | Compiler Design - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Compiler Design.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
26 videos|66 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Examples: Top Down Parsing - Compiler Design - Computer Science Engineering (CSE)

1. What is top-down parsing in computer science engineering?
Ans. Top-down parsing is a strategy used in computer science engineering to parse or analyze a programming language from the highest-level syntax to the lowest-level syntax. It starts with the start symbol of the language's grammar and recursively expands it by applying production rules until the input string is derived.
2. How does top-down parsing work in computer science engineering?
Ans. In top-down parsing, a parser starts with the start symbol of a grammar and tries to match the input string by recursively expanding non-terminal symbols using production rules. It applies a parsing algorithm such as recursive descent or LL(1) parsing to make predictions about which production rule to apply based on the next input symbol.
3. What is the difference between top-down and bottom-up parsing in computer science engineering?
Ans. The main difference between top-down and bottom-up parsing is the order in which parsing decisions are made. Top-down parsing starts with the start symbol and tries to match the input string by expanding non-terminal symbols, while bottom-up parsing starts with the input string and tries to reduce it to the start symbol. Top-down parsing is more suitable for LL(k) grammars, while bottom-up parsing is more flexible and can handle a wider range of grammars.
4. What are the advantages of top-down parsing in computer science engineering?
Ans. Some advantages of top-down parsing include: - It provides a clear and straightforward approach to parsing. - It is easy to implement and understand. - It can be easily modified to handle specific language constructs or grammar rules. - It allows for better error handling and recovery by providing error messages at the earliest possible stage of parsing.
5. What are the limitations of top-down parsing in computer science engineering?
Ans. Some limitations of top-down parsing include: - It may suffer from left-recursion and left-factoring issues in the grammar, which can lead to inefficiency or ambiguity. - It requires the grammar to be LL(k) for efficient parsing, limiting the types of grammars it can handle. - It may encounter backtracking issues when multiple production rules are applicable for a given input symbol, leading to performance overhead. - It may not be suitable for parsing languages with complex syntactic structures or ambiguous grammar rules.
26 videos|66 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Examples: Top Down Parsing | Compiler Design - Computer Science Engineering (CSE)

,

Extra Questions

,

Viva Questions

,

ppt

,

Examples: Top Down Parsing | Compiler Design - Computer Science Engineering (CSE)

,

mock tests for examination

,

Previous Year Questions with Solutions

,

Sample Paper

,

Summary

,

Examples: Top Down Parsing | Compiler Design - Computer Science Engineering (CSE)

,

Exam

,

MCQs

,

study material

,

shortcuts and tricks

,

pdf

,

Objective type Questions

,

Important questions

,

video lectures

,

past year papers

,

practice quizzes

,

Free

,

Semester Notes

;