 Welcome to the lecture on syntax analysis part 6. So, today we will continue with bottom up parsing study what are SLR1 grammars, LR1 grammars, etcetera, etcetera. To do a bit of recap, so we discussed the concept of viable prefixes, items, valid items and then we also discussed the procedure for building the LR0 automaton. Here is the example I showed you last time and the method of construction is very simple you know the to begin with the item s prime to dot s is the only one which we are going to have and then we take the closure on it. So, that gives you an initial set of items and now we continuously apply the go to function and go on including as many sets of items as possible into the collection c and when we cannot add any more items we stop. So, each set in the above collection is a state of the LR0 DFA and this DFA recognizes viable prefixes. So, each state of the DFA contains only items which are valid for a particular viable prefix or a set of viable prefixes. So, let me explain how exactly LR0 parsing happens with respect to this particular DFA. So, let us consider the simple string id which is derived from this grammar. So, we start with s going to e hash apply this production and then we apply the production e going to t and finally, we apply the production t going to id. So, we get the string id hash. So, let us see how it is parsed using this LR0 automaton. So, as usual we begin with state 0 which is the initial state and then on the input id we go to state number 3. So, remember state 0 is on the stack now id is pushed on to the stack when we see it and it takes you to state 3 which is again pushed on to the stack. So, in state 3 it says it is a reduced state. So, and the reduction is by the production t going to id. So, the implication of this would be to pop the top symbol of the stack and since the state is also included we pop two symbols of the stack and that actually exposes the state 0 on the stack. Now, the non terminal on the left hand side is t. So, we apply the go to function on state 0 and that takes us to state number 2. So, now we have pushed the non terminal t on to the stack and the state number 2 also on to the stack. Now, it says again reduced by e to t. So, we pop state 2 and the non terminal t from the stack again we get state 0 as the top of stack and now since the non terminal on the left hand side is e we apply the go to function on state 0 and the non terminal e which takes us to the state number 1. Now, the next input symbol is hash because this is a shift state it is not a reduced state and on hash it goes to state 5 where a reduction by s going to e hash is actually indicated. So, we again pop items from the stack and this state 0 and we push the non terminal s on to the stack and that is an acceptance. So, this is how the terminal string id is parsed. So, let us consider a slightly more complicated terminal string id plus id. So, id plus id hash is derived from this grammar using s going to e hash then e going to e plus t this t will go to id this e will go to t and then go to id. So, that is how id plus id would be hash would be derived again we start from 0 go to state 3 which indicates a reduction go back and on t we go to state 2 which again indicates a reduction. So, go back to state 0 pop symbols and then go to state 1 on e. So, now the plus will take us to state 6 and id will take us to state 3 again there is a reduction. So, remember that 3 and 6 are on the stack. So, we pop these two id and sorry id and 3 are pop from the stack to expose the non terminal 6 and 6 on the non terminal t takes us to state 8. So, here we now have on the stack e plus e 0 e 1 plus 6 t and 8 which indicates a reduction by e to e plus t. So, we go all the way back to state 0 and on e we again go back to state 1. So, and then hash makes it go to state 5 and we accept the string. So, this is how parsing happens using this automaton of course, all this is made easier once we actually have the table itself. So, here is the table. So, before going to this table I must explain how exactly the table is filled. So, shift and reduce actions in the state are filled as we now discussed. If a state contains an item of the form a going to alpha dot that is called a reduce item then a reduction by the production a to alpha is the action in that state. If there are no reduce items in a state then it is a shift state and shift is the appropriate action. There could be shift reduce conflicts or reduce reduce conflicts. So, when thus that happen there is a shift item and there is also a reduce item in the same state or there is more than one reduce item in the same state. So, it is you know it is normal to have more than one shift item in a state. So, there is no question of having a shift shift conflict at all. So, if there are no shift reduce or reduce reduce conflicts in any state of this DFA then the grammar is said to be L R 0 otherwise it is not L R 0. So, this is the you know table for the set of items that we have already constructed. So, let me show you the procedure for filling it. So, we actually look at the items. So, we have state 0 we assume that we have not filled anything here. So, the whole table is empty. So, in the we have state 0 and let us see on which items indicate shift on a terminal symbol because the non terminals after the dot really indicate a go to. So, only the terminal symbols after the dot indicate a shift on to the stack. So, there is a parenthesis and there is a I D as well. So, on state 0 for the left parenthesis there is a shift and for the I D there is another shift. So, when we advance the dot after the left parenthesis you know. So, the state that we get into would be you know. So, this is a state number 4. So, here it is right. So, parenthesis dot E and then the other one on I D you know 0 on I D goes to the state T going to I D dot. So, that is state number 3. So, now the go to part can also be filled for this particular state. So, there is a non terminal E after the dot in these items and there is a non terminal T after the dot in this particular item and the other two we have already considered. So, on the non terminal E it goes to a state which contains the item E going to E plus dot T and that would be state number 1. So, this is you know on. So, E dot hash and then E dot plus T and then E dot minus T. So, of course, S going to dot E hash is also an item with E on the right hand side and after the dot. So, all these three items actually are in state 1. So, that we have a go to of 0 on the non terminal E as state number 1. So, and similarly 0 go to of 0 on non terminal T is state number 2 that is this particular thing you know. So, E going to dot T will yield us the item E going to T dot. So, this is the manner in which we are going to fill all the entries in this particular table. So, now again if you consider the same string I D hash and with the help of these this table and the set of items. Let us just again make sure that we understand how it is parsed. So, we start from state 0 and on I D it says shift and go to state 3. So, that is the state number 3 here and we see that it is a reduce item that is the reason why this state indicates you know this state indicates a reduction by the production T going to I D. And then you know. So, that means we must pop the stack. So, I D is removed state 3 is removed and we get state 0 again on the stack. So, the non terminal T from state 0 takes us to state number 2. So, that is here. So, we would have pushed the non terminal T and the state number 2 on to the stack. So, we have gone to state number 2 here and it has only a reduce item. So, there is a reduction by E 2 T which brings us back to state 0 and state 0 on E it takes us to state 1 that is this particular state and state 1 contains you know S going to E dot hash E going to E dot plus T and E going to E dot minus T. And then we read hash we go to state number 5. So, that this is state number 5 and which is an accept state. So, in state number 5 the entire row says accept on any symbol. So, that is how the string is parsed. So, and you can also see that there is exactly one entry in every one of these you know slots right. Here of course, accept is nothing but a comment you know. So, reduction by 1 and the it says it is an accept state. So, it is not that there are 2 entries of a reduce or you know nature or something like that. So, this is a grammar which is definitely L R 0 because there are no conflicts in any state. So, let us go further take another example of how the L R 0 automaton is constructed. So, this is the grammar and this is the automaton that we will study how to construct it as well. So, we start from state 0. So, this is the augmented grammar S prime going to dot S S going to sorry S going S S prime going to S S prime going S going to A A S and S going to C. And the initial item we begin with is always S prime going to dot S. So, applying the closure we add these 2 items S going to dot A S and dot S going to dot C. There are no more items to be added. So, once state 0 is constructed we you know construct the go to state for this particular item S prime going to dot S becomes S prime going to S dot no more items can be added here that gives us state 1. So, when we advance the dot after the A here. So, we get A dot A S. So, that gives us this item and now the closure includes all these items you know starting with A and then there is a item with S after the dot. So, the S items are also again added. So, remember there are 2 S items here S going to A dot A S and S going to dot A S, but the dots in are different positions. So, there is nothing incorrect about this. So, now S going to C dot gives us state 3. So, we have covered all the items in state 0 this does not give us any more. So, here it gives us S going to A A dot S and then we add these 2 items by the closure operation and then this gives us A going to B dot A. So, that is this state and then A going to S dot P that would be this state with this closure items with these closure items and S going to A dot A S is the same state number 2 and S going to C dot is already covered it is state number 3. So, this gives us S going to A A S dot that is state number 5 and this item gives us S going to A dot A S which is already state number 2. So, no new states are added here and this of course, S going to dot C again gives us nothing more extra. So, this state again does not give us any extra states B dot A going to B dot A gives us A going to B A dot again this is a reduced state and nothing more can be added to this. So, this of course, gives us some more it gives us a state A going to S B dot and B going to B dot A is state number 10 with extra closure items here and this and this do not give us any extra states B going to S dot is a state which is state number 12. So, this B A dot B going to B dot A gives us B going to B A dot and the others do not generate any more new states. So, you can see that this particular grammar does not have any shift reduce or reduce reduce conflicts in any state there is exactly one reduce item in a state whenever there is one. So, and there is not any shift item as well. So, this is a grammar which is L R 0 here is the you know table for it and here is the table the sets of items the grammar and the D F A all put together. So, let us just take one state and understand again how to fill the table. So, state number 2. So, here from state number 2 on B. So, we go to state number 6 right. So, B dot A. So, state number 6 is here B dot A. So, state number 2 on B says shift 6 right and then there is a C here. So, on C it should go to state number 3. So, 2 on C says go to state number 3 and on A of course, this remains you know dot A S this is S going to dot A A S. So, this generates a state which is state number 2 itself. So, it remains in state number 2 and the operation is shift. So, you can see the self directed arc here right regarding the go to part of the table. So, 2 on S you know. So, 2 on S goes to state number 8. So, the reason being there is a symbol S after the dot A going to dot S B. So, this goes to the state containing A going to S dot B. So, A going to S dot B is here right state number 8 and on non-terminal 8 goes to state number 4. So, that is because we have S going to A dot A S. So, this gives us state number 4 which contains A A dot S. So, this is the way in which we fill up the entire table and since there is exactly one entry in each of the slots this grammar is indeed L R 0. So far we saw examples where the grammar is L R 0. So, it is time to move on and find out you know whether there are grammars which are not L R 0 at all they violate the L R 0 property indeed. So, we take the old grammar with plus and minus, but remember the old grammar had S going to E hash. We have really removed the hash. So, now it is time to explain why we removed it and what happens if we remove it. So, let us construct the set of items for this. I am not going to explain it in great detail again, but we have this first item and then the closure. Then the items S going to dot E S going to dot E plus T and E going to dot E minus T they give is to state number 1 which contains S going to E dot E going to E dot plus T and E going to E dot minus T. So, it is easy to see that there is one reduced item and there are two shift items. So, this is the reduced item and these two are the shift items. So, there is a shift reduce conflict in this particular state. So, once we reach this particular state on a particular input symbol, you know we are not able to say whether the state should reduce by the production S going to E or shift the next item on to the stack. Remember the table when we actually operate using the table the parser does not see what exactly is the item and then decide the action you know it is there is exactly one action in each of the slots. So, on 2 on a becomes S 2 etcetera. So, whereas, for the reduce there we always had exactly one item R 4 and this was S 7. So, in the entire row we always said it is a reduce by 4 see for state number 5 it is always a reduce by production number 2 and for state number 3 it is always a reduce by production number 3 and so on. So, in other words for the shift item you know we see what exactly is the symbol and push it on to the stack, but for the reduce item we should be able to say that it is a reduction by a particular production without even bothering about the next input symbol. So, this is the drawback of the L R 0 parsing strategy because we do not consider the you know what exactly is the next input symbol in order to say whether it is a reduction or it is a shift. So, in this case the grammar fails the L R 0 test, but this is an introduction to the next class of grammars called S L R 1 or simple L R 1 grammars. So, it so happens the next topic is S L R 1. So, let me mention what happens there. So, we actually compute what is known as the follow set of the non-terminal S whenever there is a reduction, we compute the non the follow of the left hand side non-terminal which happens to be a dollar. So, if we want to do a reduction then we do it only on dollar and on plus and minus we do a shift this actually resolves the conflict and makes the grammar go ahead with the same parsing strategy. So, doing this is similar to having an end marker such as hash that we had here. So, if we had a hash here S going to E hash then this state would not have been a reduced state it would still have been a shift state. So, the reduced state would have been the next one you know S going to E hash dot. So, the assumption here is the input no matter which syntax error you know occurs in the input there will always be one hash symbol coming in. So, if the hash symbol itself is making missing then the parser stops with an error somewhere in the middle, but if the hash symbol definitely exists then it can go on you know. So, it will definitely read that and if there is an error it provides an error otherwise it goes on. So, the hash symbol makes this grammar L R 0 and removing the hash symbol which is a marker in the input makes this non L R 0, but fortunately there is another way of breaking this type and that is the using the S L R 1 strategy. If the grammar is not L R 0 we try to resolve conflicts in the states using one look ahead symbol L R 0 we never used any look ahead to resolve the conflict here we try to use the look ahead symbol. So, how do we do that? We saw that the you know expression grammar of course, even the simplified expression grammar is not L R 0. So, let me show you the grammar here. So, this is S going to dot E etcetera etcetera. So, this is the full expression grammar S going to T E E going to E plus T E going to T T going to F star T T going to F T going to F going to parenthesis E parenthesis and F going to I D. So, to begin with we have S going to dot E and then we add the closure items we get state one by advancing the dot for this particular item and for this item as well. So, we get these two items in the state number one and there are no more items to be added by closure because there is nothing after the dot here and there is only a terminal symbol after the dot here. So, it is easy to see that there is a you know shift reduce conflict here right. So, similarly you know this thing going further we get this state T going to F dot star T and we also have it has the item T going to F dot as well. So, again there is a shift reduce conflict this is a reduce item this is a shift item. So, in both these states there are shift reduce conflicts and how to resolve it you know that is the discussion we right now are going to have. The expression grammar is not L R 0 that is what we saw just now. There are the state contains the items T going to F dot and T going to F dot star T this has shift reduce conflicts not only that this state S going to E dot and E going to E dot plus T also has shift reduce conflicts. So, what we do now is consider the reduce item T going to F dot. So, this has the symbol T the non terminal T on the left hand side of the production T going to F. So, we consider the symbols in the follow set of T. So, recall that follow set of T says these are the only symbols which can legally follow T in any sentential form. So, it is fair to consider the symbols which follow this particular non terminal and say for those symbols. So, in this case plus right parenthesis and dollar these are the three symbols which can be in the follow of T. So, we say reduction by T to F can be performed on seeing one of these symbols otherwise the sentential form is you know incorrect. So, we cannot make a reduction by T at T to F. So, seeing one of these symbols in the input and you know since shift requires seeing star in the input that is here. So, there is no conflict between the reduction and the shift. Shift says C star in the input and our new strategy says reduction by T to F provided the next input symbol is either plus or right parenthesis or dollar. So, these are the only symbols the follow T symbols are the only ones which can legally follow T in any sentential form. So, the reduction by T to F when one of these symbols is seen is obviously correct. So, when shift is you know reduced conflicts are resolved using the follow set the grammar uses SLR 1 strategy and if we can indeed resolve all the conflicts in this manner then the grammar is said to be SLR 1. So, we saw how to you know resolve conflict in this case right. So, in this case also we can do that. So, we consider the follow of S follow of S is just dollar. So, reduction on dollar and shift on plus again the conflicts can be very easily eliminated. So, this grammar happens to be SLR 1 even though it is not LR 0. So, now how do we construct the SLR 1 parsing table it is fairly straight forward. So, we again build the set we build the LR 0 automaton as usual and once it is built parsing actions for straight i are determined using the follow symbol. So, one if there is a shift item alpha a going to alpha dot a beta and alpha a dot beta is in some other straight i j. So, this is straight i this is straight j right. So, we add the action i comma a equal to shift j to the table when. So, we are looking at the next symbol and then making it a shift whereas, in the case of a reduction we set action i comma a equal to reduce by a to alpha for all the symbols in the follow of a that is it. So, for the item S prime going to S dot we set it as accept on dollar and any shift reduce or reduce reduce conflicts in the table after filling all this implies that the grammar is not SLR 1. The go to part is as usual. So, we have a going to alpha dot a beta in the straight i and a going to alpha a dot beta in the straight j. So, we set go to of i comma a equal to j. So, this is and any other you know entry is made as error. So, here is an example of a grammar that is not LR 0 and the grammar is definitely SLR 1. So, again the grammar is S prime going to S, S going to ASB and S going to epsilon. So, I have chosen this example because of the production S going to epsilon. So, straight 0 contains the first item S prime going to dot S and then S prime going to dot ASB and S prime going to dot are added to it. So, in some text books instead of adding the item S going to dot it is indicated as S going to epsilon dot which is perfectly, but be careful you one should not you know generate the next item S going to epsilon dot again. Now, S going to dot is the only item that can be generated which of course, can be written as S going to dot epsilon, but we should not regard epsilon as another symbol and generate one more straight S going to epsilon dot that would be an error. Then we generate these states S prime going to S dot S prime going to dot ASB you know A dot S B dot ASB and dot S going to AS dot B and S going to ASB dot. So, if you look at the straight number 0 this epsilon production and epsilon item S going to dot it collides with these two you know. So, this is a reduction whereas, these two are shifts. So, there is a shift reduce conflict in straight number 0 and again in straight number 2 as well this collides with these two. So, here we have a reduce item and these two are shift. So, now suppose you know in both the cases the concerned non-terminal is S on the left hand side. So, let us consider the follow of the non-terminal S that happens to be dollar and B that is very easy to see because after this you know after this S would only be a dollar and here after the S there is a B. So, dollar and B are in the follow of S. So, if we say that on dollar and B it is a reduction and on A it is a shift it resolves the conflict in this state and similarly in this case again dollar and B indicate a reduce and A indicates a shift that again you know resolves the conflict in this state as well. So, one can fill up the SLR 1 table using these states now. So, on 0 on A it goes to straight number 2 and it is a shift on B it the symbol is in the follow therefore, it is a reduce item and again this is also a reduce action. So, for straight 1 it is always accept on dollar and for straight 2 for A we have a shift and for the other two symbols we have a reduce. So, straight number 3 on B has only a shift and straight number 4 again you know has a reduce on S to A S B and reduce on S to A S B. So, you compute the follow symbol of a follow symbols of S we get dollar and B therefore, it is a reduction in both these cases. So, we can see that there is exactly one entry in each of these slots therefore, the grammar is indeed SLR 1. So, now we saw L R 0 then we showed an example of non L R 0 now we then saw examples of SLR 1 because it uses a look ahead symbol 1 now it is time to see a grammar which is definitely not SLR 1. So, if the grammar is not SLR 1 obviously, it will not be L R 0 either. So, here is the same grammar as we saw before. So, the this grammar, but we added the production S going to A B the rest the other three productions are the same by adding S going to A B we actually make this grammar ambiguous. So, all ambiguous grammars are not L R k for any k. So, it cannot be L R 0 or even L R 1. So, let alone SLR 1, but it tells us a lot about the nature of non SLR 1 grammars. So, straight 0 contains all this straight 1 is here straight 2 is here and so on and because of the S going to dot item there is a shift reduce conflict in this state and shift reduce conflict in this state as well and the symbol that is involved is S. So, it is follow is dollar comma B and in straight number 0 a reduce on dollar and B and shift on A indeed results the conflict. So, there is no problem as far as straight number 0 is concerned and in straight number 2 unfortunately, there is already an item S going to A dot B. So, this means it is a shift on B and this says it must be a reduce on dollar and B. So, the conflict between this item and S going to dot still remains there is a shift reduce conflict even after using the you know follow symbols. So, this grammar fails to be SLR 1. So, let us take another example which is not SLR 1, this example is from the book by Aho, Lam, Sati and Ullman. The grammar is here and it is a very concocted grammar and we construct the states state 0, 1, 2, etcetera, etcetera this is fairly straight forward what is of importance to us is straight number 2. So, straight number 2 contains the item S going to L dot equal to R and it also contains the item R going to L dot. So, now the symbol R is on the left hand side of the reduce item. So, if you compute the follow of R it gives us dollar and equal to. So, again since dollar is ok, but equal to is also here right. So, this is a shift item which is shifted the symbol is shifted on the input symbol being equal to and this is a reduce item and our SLR 1 rule says it must be a reduction on both dollar and equal to. So, there is a shift reduce conflict even if you try to apply the SLR 1 strategy. So, therefore, this grammar is definitely not SLR 1, it was not L R 0, now it is not SLR 1 either. So, let us understand why this particular failure occurred in the last example or the one before. The problem is the SLR 1 parser considers only you know considers every symbol in the follow, the construction process does not remember enough left context to resolve the conflicts. So, let us take the L equal to R grammar that is this particular grammar this let us see how the symbol equal to got into the follow set. So, we start with S prime derive S then derive L equal to R. Now, this derives L equal to L that derives L equal to I D this is a rightmost derivation therefore, this must be derived first and then L 2 star R is applied and we get star R equal to I D. So, now equal to you know is in the follow set of R that is easy to see because this is a sentential form. The problem is the you know it is not possible to reduce the R alone to L if at all we reduce it must be star R reduce to L and it is not possible to have any reduction of R to L because you know we really do not have a production of that kind the only production we have is star R being reduced to L L going to star R is the only production whereas, in this case it says you know let L be reduced to R right. So, the reduction of L to R or the R to L can never happen in any sentential form. So, this is the basic difficulty the following rightmost derivation in reverse does not exist at all that is the direction of L to R. So, so that is we have let us say R equal to I D which gives us L equal to I D then gives us I D equal to I D. So, if we had this then we would have reduced L to R. So, similarly reduction of R to L on its own cannot happen. So, on equal to the moral of the story is on equal to the reduction should have been star R to L and it is never correct to reduce you know L to R just because of you know the here is the reduction from L to R, but it was not because of the equal to symbol, but because of a different reason. So, we will never get a sentential form and a derivation in which we can reduce L to R on seeing an equal to that would be incorrect. So, this is the reason why the SLR 1 strategy failed in the previous example. So, if we try to generalize the above whatever I said here the point is in some situations when a straight I appears on the top of the stack a viable prefix beta alpha may be on the stack such that it is not possible for beta a to be followed by a in any rate sentential form. So, in other words if we actually have you know a very limited follow then the situation can be rectified. So, here we have a general follow and equal to gets into the follow set right. So, it gets into the follow set of R, but otherwise if we have a limited follow then we would actually store enough of the left context to make sure that such you know things do not happen. So, this is the basic idea let us see how to implement it in the next class of grammars called L R 1 grammars and L R 1 parsers. So, what we really try to do here is we form items which are of the form a going to alpha dot beta comma a and a is of course, called as the look ahead symbol. So, this is nothing great on its own, but the way we actually derive states using such items is very different in this case. So, look ahead symbols have no role to play in shift items, but the reduce items of the form a going to alpha dot comma a a reduction is valid only if the input symbol is a. So, this you know input symbol actually is some kind of a limited follow that we mentioned in the last slide. So, then let us also finish of this definition of validity and L R 1 item a going to alpha dot beta comma a is valid for a viable prefix gamma if there is a derivation S deriving delta a w by right most derivations then we apply the production a going to alpha beta. So, in this case we consider this entire derivation and a to alpha beta has been applied. Now, if the first set of w that is the first symbol of w is actually a then this particular item is valid for the sentential form gamma equal to you know with the viable prefix gamma equal to delta alpha if w is empty that is a null then a must be dollar. So, in both these cases this item is valid for the viable prefix gamma which is equal to delta alpha. So, let us take an example S prime going to S and S going to A S B or epsilon. So, consider the derivation S prime going to S and S giving A S B. So, now you know the production applied at this point is S going to A S B. So, the handle ends at this point. So, this is dollar right end of the terminal string. So, a A S and A S B these are all the viable prefixes. So, the item A S going to A A dot S B comma dollar is valid for the viable prefix A. So, A is a viable prefix that I already mentioned. Now, the production which has been applied is A S B. So, if you A S going to A S B. So, here the production applied was S going to alpha beta. So, the w part you can see is empty. So, A is must be dollar which is indeed the case. For the second one we consider the item S going to A dot S B comma B and derivation is S prime giving S, S giving A S B and that giving us A A S B B. So, the production which has been applied at this point is the S going to A S B in the middle. So, the w part is this w B right and the viable prefixes are A A A A S and A S B. So, we look at the viable prefix A A and since w is once symbol B and the symbol B here also matches we know that this is valid for the viable prefix A E. So, how about the item S going to dot with a look ahead dollar? So, derive the null string S prime going to S going to epsilon. So, w is empty again. So, the symbol look ahead symbol must be dollar the only possible viable prefix is epsilon. So, everything is ok here and the last example S going to A S B dot comma B is valid for the viable prefix A A S B. So, again the same derivation. So, we have applied the production S going to A S B here. So, the last B is the w and that is the symbol here as well. So, that takes care of viable prefixes and let us proceed further. So, here we have an L R 1 grammar example and the set of items the automata and the table are all shown here. So, let us understand the procedure for constructing the set of items first and then move on to filling the table and so on. But in this slide what I want to show you is that each state contains many types of items. So, here is a reduce item for example, S going to dot and here we have shift items. This state also has reduce item and shift item this state also has reduce item and shift item, but the manner in which we are going to fill the table is going to be slightly different. So, even though we have many reduce items and shift items in each state this grammar is still L R 1 you know if you look at this particular table you can easily see that there is exactly one entry in each slot. So, the grammar is indeed L R 1. So, let us now understand how to construct the sets of items. The procedure is similar what we have is a closure procedure here also. So, we always begin let us say in the state we have the item S prime going to dot S comma dollar. So, the first symbol after the dot is a non-terminal. So, now we must add you know for the closure operation we must add items with starting from this non-terminal S. There are two of them S going to dot ASB and S going to dot. Now, the closure operation is very simple. So, what we consider is the symbols after the you know non-terminal S and concatenated with the look ahead symbol here. So, after the non-terminal S there is no symbol that is null string, but there is a dollar here. So, the concatenation of these two uses dollar and we take the first of this string and those symbols are actually listed as the look ahead symbols for the items that follow in the closure. So, here for example, the procedure says for each item A going to alpha dot B beta comma A in the item set I and we have a production B to gamma then consider each symbol in the first of beta A. So, here is the rest of the production after B and concatenated with the symbol A. So, that is the first of beta A. The reason we mention first of beta A and not a particular set of symbols is beta could consist of non-terminals. So, it could begin with non-terminals in which case there will be more than one item in the first set and it is possible that beta is null. So, this A which is definitely non-null takes care of producing at least one item for the first set. So, we form the items of the form B going to dot comma B. So, that is done for each of these you know elements in the first of beta A and add the item B going to dot comma dot comma comma B to the set of items B. So, that is how we add these two now this state you know does not grow because of the closure whereas, here we have A S going to A dot S B comma B. Now, after the S we have B and the look ahead is B. So, first of you know the beta A string is B B first of that would be little symbol B little B. So, we have little B as the look ahead in these two and the first part S is S going to dot A S B and S going to dot. So, this is how the closure operation is applied in the case of L R 1 items. So, basically we are trying to send the restricted follow as part of the item itself in the form of a look ahead. The go to is as it was before. So, if there is a if there is an item A going to alpha dot X beta with a look ahead A in the item set I. Then we form a new set I prime which contains the items A going to alpha X dot beta comma A. So, this part does not change in the go to then we form the closure of this particular go to. So, this particular I prime is actually made to undergo a closure operation and that gives us the go to set. So, let us see that in this example. So, state 0 we applied the closure and we got this and now to get state 1 we advance the dot by one position. So, that gives us S dot comma dollar. So, that is it here and state number 2 is obtained by advancing the dot after the A. So, we have S going to A dot S B comma dollar. So, that is the item here and then we get these items because of the closure operation. So, observe that after the dot after the S we have a B and here is a dollar. So, this is B dollar and the first of B dollar is just B. So, that is why these two symbols are B and from this item we have A S going to A dot S you know sorry this item S going to A dot A S B comma B gives us S going to A dot S B comma B. So, and then we add a few more items because of the closure operation. So, this is the example for creating the go to sets and now let us see how these two can be put together. This procedure is very similar to what we had before for each item set in C and each grammar symbol X if go to of I comma X is not equal to 5 and go to of I comma X is not in C grow the item set C rather the set of items C and add go to I X to it. So, C becomes better bigger set of item sets rather. So, each set in C above corresponds to a state of the DFA in this case it is called the L R 1 DFA and again this DFA recognizes viable prefixes and contains only those items which are valid for the viable prefixes that reach that particular state. So, getting back to this example. So, we have seen parts of this example already. So, here is state 0. So, we start with this item S prime going to dot S these two are added by closure then we get state 1, state 2, state 3 and state 4, state 5, state 6 and state 7. So, here is the DFA corresponding to it and here is the you know table. So, let us see how the table is filled for state 0 on little a is a shift and there is no item with a little b after the dot and this is a reduce item and the reduction happens only on dollar. So, we add reduce by S to epsilon and because of this dot S we have a go to entry as well. So, similarly for state number 1 we have just an accept you know there is nothing more possible this is S prime going to S dot and dollar and dollar it accepts. And for state number 2 on a on the symbol a we have a shift to state number 4. So, that is because of this and on a this is a reduction and on a b the reduction is possible by S to epsilon and this item gives rise to a go to that is go to number go to state number 3. So, in this manner you know we fill 3 as well which is just a shift on b and for state number 4 we have a go to that is state number 6 and then we have a shift because of this a and we have a reduce because of this. So, that is on b. So, you observe that even though there are many shift and reduce items in each state we really do not have more than one reduce or shift action in each of these slots in this particular table and therefore, this grammar happens to be L R 1. So, we will end the lecture here and continue with more examples in the next lecture. Thank you.