 Hello, welcome to the session CFG Derivation Trees and Ambiguity Languages. At the end of this session, the student will be able to explain the Contacts-Free Grammar and Ambiguity in CFG. My Ambiguist Grammar can be defined as a grammar G is ambiguous if there is a word having at least two different pastries, means a word can be derived with the help of two derivations, so that should be two leftmost derivation or two rightmost derivation. Other way we can define ambiguous as following any string W is having multiple derivation trees or string W with multiple leftmost derivation or it is having multiple rightmost derivation. What is the ambiguity? That is something having more than one possible meaning and therefore possible confusion. Here we can see with example that S produces AB, A producing A, AB and A producing null. So, here we are deriving different words S starts symbol, it is producing AB and finally it is producing B. S producing AB, A, A, B, B. So, finally word is ABB, S producing AB, A, A, B, B and finally it is A, A, B, B, B. So, here you can see that we are having three different words with one production, so this is not called as an ambiguous. Then what is ambiguous? See in this example S is producing A, AB, A is producing null, A, AB, A, A, B producing B, B, C, B, C and B. Now here we will try one word A, A, B, B. So, first we will derive S producing AB, here A like most A, A, B is producing here with terminal, non-terminal and terminals. So, A, A, B, B. Is there any other derivation? So yes, there are two more derivations, we will see S is AB, then A is producing A, A, B is going for non-terminal B, A is going A and B. So, finally we are getting A, A, B, B as our word. So, here S is A, A is producing A, A, A is giving A, A and finally A null. Here this A is producing A that is terminal, non-terminal. Here A is giving A, B and here A. So, here A, A, B, B. So, that is our word. So, here for a single word we can produce three different derivations and three different pastries. So, here two rightmost derivations. So, this is a three possible derivations for a single word. So, this is the ambiguous grammar. One more example, here we can A plus A into A. For this the production E into E plus E, E producing E plus E or E producing E into E or single parenthesis E or small A that is non-terminal, terminal A sorry. E producing E plus E that will be replaced by A plus E that is derived by and replaced by A plus E into E which is going again A plus A into E, A plus A into A. So, this is a one pastry we are producing. Now, here we will check if any other pastries available. So, here this is a one more pastry. This side we are doing first A plus A that is it is producing like this from the top side E is having E into E, E into E then E is having E plus E and finally A plus A into A. So, again we are having the same derivation. So, these are two pastries here for one production one grammar. So, this is the ambiguous. Why it is ambiguous and why we are caring for this ambiguous? So, here ambiguity here we will take one example that A is equal to 2. So, we are replacing A with the value 2. So, here we can see that A is replaced by value 2. Now, in the first pastry we will check it. So, this will be A into A that is giving 2 into 2. So, this value is 4 and then here addition of 2, 2 plus 4 it is giving 6 and in this pastry you can see this is a first it is going this side 2 plus 2, 4 and 4 into 2, 8. So, here we are producing two different answers for one grammar. So, it is 6 and it is 8. Now, we have to decide which one is correct. So, here the correct answer as per our rule 2 into 2 first that is 4 and then plus 2 that is 4 plus 2 is 6. So, this is a correct answer. So, another pastry which is producing this 8 is false or it is a incorrect. So, ambiguity is bad for programming language and we have to remove the ambiguity which is present in the grammar. So, this is a grammar ambiguous grammar we need to convert it into the unambiguous grammar. So, here what we will do E plus E here we will replace it E plus T. So, E is nothing but here is replaced by T. So, E plus T second that E will consider as T and T will be replaced by T into F. So, we are using different variables here instead of the same ambiguous. So, T is nothing but F and F is then it is a parenthesis E and then F will be replaced with this terminal symbol A. Now, with this we are drawing this pastry. So, this pastry is giving the answer and which is an unambiguous. So, this is our non-ambiguous grammar E is producing E plus T, E is T, T is producing T into F, T is F, F is having E with parenthesis and F is E. So, this is a unique language as it is having unique derivation and unique past. One more example of this ambiguity is in the language that is when we are using if expression in the statement it may create ambiguity. As you can see this example if expression 1 then expression 2 then statement 1 else and statement 2. Sometimes else is not mentioned every time. So, that time it produces ambiguous grammar or ambiguous meaning. So, here also we can see we are having two pastries for one if statement. So, this is an ambiguous grammar and we need to be corrected pause for a while and find a grammar is ambiguous or unambiguous. The productions are given as producing A, A, B, S and it is producing A, A, B and A is producing B, B, B, A it is producing B, B, B and B is A or null value. So, here the solution is given. So, as we can see here two derivations are there it is a ambiguous. So, this is the first derivation it is derived with the help of the same grammar and same productions S is A, A, B, A, B, B, B, B here capital B is replaced by this null value and then A, B, B, A, A, B, B, B, B, B. So, it is derived step by step you can see here and finally we are getting the word A, B, B, B, B and here second derivation we can see that using that start same but it is deriving again the same word. So, these are different production but giving the same output of same string or word. So, this is a ambiguous. Thank you.