0% found this document useful (0 votes)
23 views

FAFL Final Lecture 23.2 CMH

Uploaded by

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

FAFL Final Lecture 23.2 CMH

Uploaded by

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

Established as per the Section 2(f) of the UGC Act, 1956

Approved by AICTE, COA and BCI, New Delhi

Lecture 23.2
Parse Trees
S c h o o l o f C o m p u t i n g a n d I n f o r m a t i o n Te c h n o l o g y

Chaithra M H
Assistant Professor

AY:2020-2021
OUTLINE

Recap of Previous Lecture

Topic of the Lecture

Objective and Outcome of Lecture

Lecture Discussion

• A Simple Example of DFA


• Simple Problems on DFA Construction
• DFA accepting strings containing given prefix
Parse Trees
Recap of Previous Lecture
RECAP OF PREVIOUS LECTURE

• Finite Automata
Course Description
• Transition Diagram
Finite • Configuration of Finite Automata
Automata • Language Accepted and Rejected by FA
• Transition Function (δ)
• Deterministic Finite Automata - Definition
Parse Trees
To p i c o f t h e L e c t u r e
TOPIC OF THE LECTURE

Deterministic • A simple example of a DFA


Finite • Simple Problems on DFA Construction
Automata • DFA accepting strings that contain given prefix
Parse Trees
Pa rse Tre e - e x a m p le s
PARSE TREE - EXAMPLES

Example 1- Consider the grammar shown below and construct the parse tree having a string w=
a*b+c
T T + T | T * T
T  a|b|c

Left most derivation :


T Parse tree
T →T*T ( Using T  T * T)
→ a*T (Using T → a) T T
Solution *
→ a*T+T (Using T→ T * T)
→ a*b+T (Using T→ b) a T + T
→ a*b+c (Using T → c)

b c
PARSE TREE - EXAMPLES

Example 2- Consider the grammar shown below and construct the parse tree
having a string x = a * b + c
Z→Z+Z|Z*Z|a|b|c
Solution Z Parse tree
Left most derivation :
Z →Z+Z Z + Z
→Z*Z+Z (Using Z  Z * Z)
→a*Z+Z (Using Z a) Z * Z
c
→a*b+Z (Using Z b)
→a*b+c (Using Z c) a b
Parse Trees
Yi e l d o f a T r e e
YIELD OF A TREE

Example - Consider the grammar shown below and construct the parse tree
having a string w = a * b + c
I→I+I|I*I|a|b|c
Solution I Parse tree
Left most derivation :
I →I+I
I + I
→I*I+I (Using II*I)
→a*I+I (Using Ia) I * I
c
→a*b+I (Using Ib)
→a*b+c (Using Ic) a b
Reading a leaf nodes from left to right (leaving ԑ-symbols is any), is said to be Yield
of a tree
DISCUSSION
5 MINUTES
SUMMARY OF THE LECTURE

Definition of Parse tree


Parse tree with examples Yield of a tree
with examples
QUIZ TIME
10 MINUTES

“All of you have to give quiz where there will be 8 questions covering part1 and part 2 of
lecture. It is compulsory as it is used for assessment and attendance”
QUIZ
Questions from Lecture 23.1 & 23.2

1. Output of parser is

A) Parse tree B) Object code

2. The concept of grammar is much used in this part of the compiler

A) Lexical analysis B) parser


QUIZ
Questions from Lecture 23.1 & 23.2

3. Parsing is also known as _________

A) Syntax analysis B) Semantic analsis

4. In a Derivation, if a variable is replaced at every LHS then it is


called________

A) parser B) LMD
QUIZ
Questions from Lecture 23.1 & 23.2

5. In a Derivation, if a variable is replaced at every LHS then it is called________


representation of a grammar.
A) LMD B) RMD

6. Reading a leaf nodes from LHS to RHS is called _______

A) Sentential B) Yield of a tree


QUIZ
Questions from Lecture 23.1 & 23.2

7. The context free grammar S → SS | 0S1 | 1S0 | ɛ generates

A) Equal number of 0’s and 1’s B) Any number of 0’s and 1’s

8. Which of the following statement is false?

A) In derivation tree, the label of B) In derivation tree, the label of


each leaf node is terminal all nodes except leaf nodes is a variable

C) In derivation tree, if the root of a sub D) None of these


tree is X then it is called –tree
THANK YOU

You might also like