retagged by
6,799 views
1 votes
1 votes

Consider the following grammar

E → E+T/T

T → T*F/F

F → id/(E)

Calculate Lead and Last for every Non terminal.

retagged by

2 Answers

Best answer
2 votes
2 votes

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
0 votes
0 votes

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

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

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

edited by

Related questions

0 votes
0 votes
1 answer
3
MayankSharma asked Nov 18, 2017
344 views
First {a} =?First{a, b} =?First{a, b, c} =?First {a, $} =?Where a, b, c are terminals.