in Compiler Design retagged by
5,525 views
2 votes
2 votes

Consider the following grammar

E → E+T/T

T → T*F/F

F → id/(E)

Calculate Lead and Last for every Non terminal.

in Compiler Design retagged by
5.5k views

3 Comments

from where u got this ???
0
0
Please solve it it is very important and basic question i know tht but i m having confuse. i beg you please solve i m very poor guy and i havent done coaching like you all guys over here.

thank you so much in advance please solve.
0
0
No gate question or any other questions will be in this way
0
0

Subscribe to GO Classes for GATE CSE 2022

2 Answers

2 votes
2 votes
 
Best answer

Lead :- Lead is a list of all those terminals symbols("operators") which can appear first on any right hand side of a production.

For each non-terminal i.e. left hand side,a Lead list containing the first terminal in each production for that non-terminal.Where a non-terminal is the first symbol on the right hand side, include both it and the first terminal following.e.g. for

X $\rightarrow$ a.... / Bc

includes a,c and B in X's Lead List.

Trail:- Trail or Last is a similar list of those terminals which can appear Last.

For each non-terminal i.e. left hand side,a Last or trail list containing the last terminal in each production for that non terminal.Where a non-terminal is the last symbol on the right hand side, include both it and the last terminal .e.g. for

Y $\rightarrow$ ....u / ....vW

includes u,v and W in Last or Trail list.

 

Now for the given Grammar

Lead(E) ={ + , * , id , (   }               Last={ + , * ,  id , )  }

Lead(T) ={ * , id , (   }                    Last={ * , id , )   }

Lead(F)={ id , ( }                            Last={ id , ) } 

 

selected by

1 comment

edited by
@shivani did u got answer or shud i tell...this is not gate type question...but it can appear in ISRO exam....///@sharma ji it wud have been ..better if you wud have explained step by step...for evry non-terminal plz update it
0
0
0 votes
0 votes

Lead(E) ={ ( +,*,id}                  Last(E) ={ +,*id, ) }

Lead(T) = { *,id,( }                Last(T) ={ *,id, ) }

Lead(F) = { id,( }                 Last(F) ={ id, ) }

edited by

5 Comments

@alok Are My dear , we r not scolding. But here we r to guide each other in a better way, right?. So, if one not getting the answer , other could find the way, if one do some mistake ,other could take in a right way. So, be happy - we all are for each other . smiley

1
1
edited by

alokthebranded without posting the answer how she did know that her answer was right or wrong .but you selected it and she thinks she was right and other users will also think the same that selected answer is right.

0
0

alokthebranded are itna preshan hone ki jaroorat nhi h.be cool be happy smiley

0
0
yes rt @Leen
0
0