 Hello everyone, I am Mrs. Sunita Do. Topic covered here is first set. In previous videos, we consider non-recursive predictive parser that has an input buffer, a stack, a passing table and an output string. Also, we consider how to pass the string of a given grammar using passing table. Now, the next task is to construct the passing table for which we need to compute two functions first set and the follow set. In this video, we are going to consider how to compute the first set for given grammar. Learning outcome. At the end of the session, students will be able to compute first set for a given grammar. The construction of a predictive parser is added by two functions associated with a grammar G. These functions are first and the follow set which allows us to fill in the entries of a predictive passing table for grammar G. If alpha is any string of grammar symbol, then first of alpha is a set of terminals that begin the string derived from alpha. If alpha derives epsilon in zero or more steps, then epsilon is also in the first of alpha. To compute first of x for all grammar symbol x, apply following rules until no more terminals or epsilon can be added to any first set. Rule number one, if x is a terminal, then first of x is x. If x derives epsilon is a production, then add epsilon to the first of x. And rule number three, if x is a non-terminal and capital X derives capital Y1, Y2 up to Yk is a production, then place small a in first of capital X. If first sum i small a is in first of capital Yi and epsilon is in all of first of capital Y1 and so on up to first of capital Y of i minus 1 that is capital Y1, Y2 up to Y of i minus 1 derives epsilon in zero or more steps. If epsilon is in first of capital Yj for j is equal to 1 to k, then add epsilon in first of capital X. So, we compute the first for any string capital Y1, Y2 up to Yn as add to the first of capital Y1, Y2 up to Yn on non-absolene symbol of first of capital Y1. Also add the non-absolene symbol of first of capital Y2, if epsilon is in first of capital Y1. The non-absolene symbol of first of capital Y3 if epsilon is in first of capital Y1 and first of capital Y2 and so on. Finally add epsilon to the first of capital Y1, Y2 up to Yn if for all i first of capital Yi contains epsilon. Consider the grammar for the arithmetic expression with the productions. Consider first production capital E derives capital TE dash. Here the right side of the production contains non-terminal capital T and E dash. Hence we apply rule number 3 to this production. So first of capital E is first of capital TE dash. We add to first of capital TE dash all non-absolent symbol of first of capital T and also we add the non-absolent symbol of first of capital E dash if epsilon is in first of capital T. Now first of capital T is first of capital FD dash so we add to first of capital FD dash all non-absolent symbol of first of capital F and also we add the non-absolent symbol of first of capital T dash if epsilon is in first of capital F. First of capital F is first of in parenthesis capital E and first of I D. First of in parenthesis capital E is left parenthesis and first of I D is I D as I D is terminal. Hence first of F is left parenthesis comma I D as the first of F does not contain epsilon. Hence the first of capital T is equal to first of capital F and also as the first of capital T does not contain epsilon. Hence the first of capital E is equal to first of capital T. Hence first of capital E is equal to first of capital T is equal to first of capital F equals to left parenthesis and ID. To compute the first of capital E dash, consider the production E dash derives plus capital T E dash or epsilon. First of capital E dash is first of plus capital T E dash and first of epsilon. First of plus capital T E dash is plus as plus is a terminal and first of epsilon is epsilon by rule 2. So first of capital E dash equals to plus comma epsilon. Now to compute the first of capital T dash, consider the production capital T dash derives star capital F D dash or epsilon. First of capital T dash is first of star capital F D dash and first of epsilon. First of star capital F D dash is star as star is a terminal and first of epsilon is epsilon. So first of capital T dash is star comma epsilon. Consider the second example of grammar with the productions capital S derives small i capital E small t capital S S dash or the small a that is on the right side of the production small i means if capital E means expression small t means then capital S means statement and capital S dash means statement dash so S derives if expression then statement L statement dash or small a. Capital S dash derives small e capital S or the epsilon that is S dash derives L statement or epsilon. Capital E derives small p. This grammar contains three non-terminal capital S capital S dash and capital E. Now consider the production capital S derives small i capital E small t capital S S dash or small e to compute first of capital S. First of capital S is first of small i capital E small t capital S S dash and first of small a. First of small i capital E small t capital S S dash is small i as small i is a terminal and first of small a is a small a. So first of capital S is small i comma small a. Now consider the production capital S dash derives small e capital S or epsilon for first of capital S dash. First of capital S dash is first of small e capital S and first of epsilon. First of small e capital S is small e and first of epsilon is epsilon by rule 2. So first of capital S dash is small e comma epsilon. To compute first of E capital E consider the production capital E derives small b. Now the first of capital E is first of small b which is small b. So first of capital E is small b. Consider the third example of the grammar with the productions given on this slide. This grammar contains three non-terminal capital S A and B. Now consider the production capital S derives capital A small a capital A small b or capital B small b capital B small a to compute first of capital S. First of capital S is first of capital A small a capital A small b and first of capital B small b capital B small a. So we add to the first of capital A small a capital A small b all the non-absolence symbol of first of capital A and also we add non-absolence symbol of first of small a if epsilon is in first of capital A and so on. First of capital A is epsilon by rule 2. As the first of capital A contains epsilon we find first of small a which is small a. As the first of small a does not contain epsilon so now we do not add anything to the first of capital A small a capital A small b and also we do not add epsilon to the first of capital A small a capital A small b. So first of capital A small a capital A small b is small a. Similarly first of capital B small b capital B small a is small b. Hence the first of capital S is small a small b. To compute the first of capital A consider the production A derives epsilon. First of capital A is epsilon by rule 2. Similarly, to compute the first of capital B consider the production capital B derives epsilon. The first of capital B is epsilon. Till now we consider how to compute the first set for the terminal as well as non-terminal. Now pause this video and reflect on this question for a minute or two minutes and write your response. Once you have written the answer to this question then you can restart playing this video. The question is compute first set for the following grammar. I hope all of you have completed this activity. Now consider how to compute the first set for this grammar. This grammar contains non-terminal capital S and the C. To compute the first of capital S consider the production capital S derives capital C C. First of capital S is first of capital C C and first of capital C C is first of first capital C and first of second capital C if first of first capital C contains epsilon. To compute the first of capital C consider the production capital C derives small c capital C or small d. First of capital C is a first of small c capital C and first of small d. First of small c capital C is small c and first of small d is small d. Hence first of first capital C is small c comma small d. As first of first capital C does not contain epsilon hence the first of capital S is first of first capital C which is small c comma small d. This is the reference used for preparing this presentation. Thank you.