 So we started looking at specifying them in terms of grammars. And there were two examples. One was looking at how to specify a balanced set of parenthesis. And this was the grammar for specifying a balanced set of parenthesis. And then we had another grammar that we accepted. We are going to look at all digits subtracted by a plus or minus sign. And then the next thing we said was that now we want to check the process of parsing that are given a string in either this language or this language. One way to look at that is that if I can derive it from the start symbol by tracing continuously some non-termination on the right hand side with one of its productions, then I know that there is a valid string in the language. So let's look at an example of that. So suppose I want to check whether there is a valid string in the second language or the language specified by this grammar. One way to check this is that if this is my start symbol, can I derive it from the start symbol? And derivation means that I am going to say that this is a non-terminal, which gives me one of these rules. And if I replace it by one of the rules and continuously keep on doing, what I have not said is which rule and which non-terminal to expand. But suppose somehow I am able to pick up the right tool. So let's say that suppose I say that list is replaced by list minus digit. And also then I notice that this is now a terminal. This is a terminal, but this is a non-terminal. So I decide to replace this by again one of the rules I have. And this time I decide to use the first rule. And that gives me list goes to list plus digit. And then the remaining part remains as it is. And then I decide that since this is a non-terminal, at this point of time I want to use another rule. So I decide that I want to use the third rule of the production. And replace that by a digit. And now I find that this is the non-terminal. And now I want to start using one of the rules here for replacement. And then I go around and say that this first digit is replaced by, let's say, a production which says digit goes to three. So this gives me three. And then I decide that I want to replace this particular non-terminal by again one of its productions. And this time the production I want to use is which says digit goes to four. So I will have, and now this is the only non-terminal that is left. And I want to use a production which says digit goes to five. And if I do that, I'll end up getting this. Now once I get this string, I can say that this particular string belongs to the language which is specified by this graph. But there are several things I have left unspecified here. One, I was saying that, so you can see here that I had list going to list minus digit. Why did I choose this rule and not some other rule? So which rule to pick up? Somehow there was a magic happening and I was always able to pick the right one. Second thing that I had an option here of saying that this digit could have been replaced by five and I could have continued rest of the derivation. So in which order I am replacing, that was not specified. So which rule to pick up? That is left unspecified, which symbol to pick up here for extension that is left unspecified. But somehow I managed to pick up the right ones and reach this. And final answer is that the string belongs to the language. Now for process of parsing, it is very important that not only we give this answer which is saying yes or no because it is possible that at some point of time I picked up either the wrong symbol or I had picked up the wrong production. Then it is possible that although this is a valid string, I would not have reached that conclusion. So it is important to know that which symbol to pick up and which production to pick up just giving this answer that this particular string belongs to the language specified by this because it can be derived from the start symbol is not sufficient for you. And the whole process of parsing is about picking up the order and picking up the right production. So we need to understand how to do that. So let us move on. So here is another example I just picked up. So I am now trying to show that this string 9 minus 5 plus 2 belongs to the language specified by the grammar and these are the sequences I follow in the production. And therefore we say that this belongs to the language which is specified by this grammar. And the word that we are using context-free grammar perhaps you already know it from your theory of computation. It is coming from the fact that when I look at expansion of any of these non-terminals, I did not look at what was in the left and what was on the right inside of this. I just looked at this with an isolation which is what is going to be used for that. So there is one more example of a grammar. So there is a grammar if you are familiar with any block structured language or Pascal. This says that a block is something which always has a keyword begin and end in the beginning and end and then you have statements between these two symbols. And then these statements actually derive a list of statements or it could be null. That means a block would just consist of two keywords begin and end. And then the statement list derives. Now this is a recursive rule which says that statement list derives a statement list followed by a single statement or it just derives a statement. So you can see that what I am doing here is basically saying that a block consists of two keywords begin and end and what you have in between are statements and each statement must end with a semi-colon except the last one. These are the set of strings which are being derived by this particular grammar. You can see slowly what I am building up is that I am telling you how to start specifying programming languages using context-free grammar. So I gave you an example of a simple expression which consists of just digits and plus and minus symbol and slowly we will start editing. So is this concept clear? At least the part of derivation. So let us look at few more things. And now we say that how do I build syntax analyzer? So let me go back and try to give you a similarity with what we did in the laxical analysis. We said in laxical analysis you have a set of specifications. And then you are talking about certain kind of ordering, certain priorities, some maximal bunch principle and so on. So just specifications are not sufficient. You need to do something more to really build a parser. So testing for membership that whether a string belongs to the language specified, you can just say yes and no answer. This is the base syntax analyzer. But also this syntax analyzer must do additional things. One, it must generate a parse tree and I will define what parse tree is. But basically parse tree is capturing in which order I am doing the derivation. And then it must also handle all the errors. And when I say gracefully what that means is that it should not just do a order for stop at the first error but should try to find as many errors as possible. So it should recover from an error and that should continue from that point. And important thing here is that the way I write my grammar that is important because I can write multiple grammars which is specified in the same language. I can write g1 and g2 which have totally different form but when I look at strings which are generated by them they are exactly identical strings. But the form is important. So whether I pick up g1 or g2 for parsing that is important and we will see what are the properties which will determine whether some grammar is better than the other grammar. So we will look at that and then the tools we talk about. So yet is one possible tool. Bison is another tool. Antler is yet another tool. All those tools are going to be sensitive to the way you write your grammar. So for example, if you are familiar how many of you have heard this word antler? You have heard this tool called antler? Yet? Bison? No. So you only know yet, right? So these are three of the popular names. And you can see they belong to the species of the same animal. All those things. So yet was one of the first tools which was built up. And this also belongs to a category of parsers known as bottom of parsers. We will see what bottom of parsers are. But antler is actually a bottom parser. And bison is supposedly improved version of yet. It gives you a faster version of faster. So we will see all these. So what is derivation? I already showed you a form of derivation. So what we say is that if you have a production of this form. Now look at the form. This says A goes to alpha. And here we have to be careful with the notation. So when we use symbols like alpha, what that means is it is not a terminal or non-terminal. Normally in this context, this is used to have a stream of terminals and non-terminals. So this is not just one symbol, but actually this is a string. So this says that when A goes to alpha. And we are saying that A derives alpha. And the notation we use here is a thick arrow which says that A derives alpha. So normally if you start reading textbooks and if you start reading papers. There is without definition some kind of nomenclature which has evolved. And that is when you have uppercase letters. That is normally going to be a non-terminal. When you have a legend letter like alpha, beta, gamma and so on. Those are normally going to be streams of terminals and non-terminals. And lowercase letter or something which is like a proper noun and so on. Those are going to be terminals. And somewhere you will find that there is always a confusion. So you will have to look at the context and we will try to understand. Now we also say that if alpha A beta derives alpha gamma beta. Then A going to gamma must be a production. Because the only way this string alpha A beta can derive alpha gamma beta is that A derives gamma. So you can see that it is not affected by the context. Alpha is on left of A, beta is on right of B. And when I replace A by gamma then alpha remains on the left and beta remains on the right. So you can see here that when I am saying that this digit derives fourth. Whatever is on the left of this digit and whatever is on right of this digit. That is copied as it is. That does not change. So this is a derivation and this must be production. Then only this derivation could have been valid. And if I say that if I have a sequence of derivations which says alpha 1 derives alpha 2. Which derives alpha 3 and so on. Then that is okay. So that notation will come later. So this says that alpha 1 derives alpha A. So I can have a series of derivations and this is actually deriving it one or more steps. So I would like to capture that somewhere. So we say that given a grammar G now I am trying to define these strings in terms of derivations. And we are saying that if I have a grammar G and G has a language which is LG. Then what we can write is that all the strings which are in LG can be derived from the start system. So this can be done in one or more steps. So S derives W if W belongs to LG. And this says that if S derives alpha in 0 more steps. Then we say that this string alpha which is a string of terminals and non-terminals is a sentential format. So looking at here. If I say list is my start symbol and list is deriving list minus digit. Then we say that this actually is a sentential format of grammar I have. Similarly list plus digit minus digit is also a sentential form of the grammar I have. So basically whatever string of terminals and non-terminals can be derived from the start symbol. All those are sentential forms of my grammar. Now this also gives you a hint saying that when I start doing parsing. And I want to flag errors and I want to do error recovery. At any point of time if you reach a situation that something is not a valid sentential form of the grammar. Then what will you do? You can immediately flag an error. You can immediately say that this is not a valid sentential form. And therefore this cannot be the grammar and therefore there is an error. So these are some notations you have to be aware of. So continuing on this. So if in a sentential form. Now let's look at this. So let me just catch something I did here. So one thing I said was I am not worried about the order to begin with. And I did not worry about which rule to pick up. But actually I was using an order without saying it. And what I was doing was that all the time I was looking at the leftmost non-terminal. And I was expanding that. So if you see here this is a non-terminal but I chose not to expand this. I chose to expand this. And when I expanded this then again I decided to expand this and not this and this. So what I was doing was that all the time I was picking up the leftmost non-terminal. And expanding that till everything got replaced by one of the terminals. What I still did not tell you is that how did I pick up the rule. So in derivation if I say that all the time if I have some sentential form. And the leftmost non-terminal is replaced then we say that this is the leftmost derivation. So what I have shown you is actually a leftmost derivation. Now similarly I can write each leftmost derivation. And the notation I am using here is in derivation I am saying this is leftmost derivation. And what we are saying here is that if I have WA gamma. And please understand the notation here. So WA gamma where W is a string of terminals. A is a non-terminal and gamma is a string of terminals and non-terminals. And what we say here is that if I replace A. And obviously A going to delta must be one of the productions in my language. Then we say that this is a leftmost derivation. Because on left of A I only have terminal symbols. And on right of A I have terminals and non-terminals. So this actually is a leftmost derivation. So this notation says that if I keep on doing leftmost derivation zero more steps. I keep on generating terminal symbols on the left hand side. And similarly I can talk about a rightmost derivation. Like I talked about leftmost derivation. If I always replace my rightmost non-terminal with one of the symbols or the tokens. Then this is going to be a rightmost derivation. So they are similar and we look at both. And here is now a catch. And here we say that some grammars may be ambiguous. And like I said that it is important that you have multiple grammars. Which generate the same language. And your tool is sensitive to the form of the grammar. We say that some grammars are ambiguous. Because they can produce more than one leftmost derivation. Or more than one rightmost derivation of the same string. And that becomes problematic for us. And we will see what the problems are. Because at any point of time if we have an ambiguity. Ambiguity can create problems. And we will see what kind of problems it can create. Any questions, comments up to this point. Is this concept becoming clear to everyone? Or we are slowly moving towards a parser. Because each parser will just try to have two things built into the design. Which rule to pick up and which symbol to pick up. So if I am doing a top-down parser. And I will define formally what top-down parsers are. Then I am looking at leftmost derivation. If I am looking at a bottom-up parser. I am looking at rightmost derivation. And somehow I am able to pick up the right tool. By looking at certain symbols. So what I want to do now is. I want to slowly move to a data structure. And then after introducing this data structure. I will continue with rest of the parsing. So what you have to do now is that. I want to capture all this information in the parser. So what information I am trying to capture. I am trying to capture information about. What rules are used for this variation. So as the name suggests. That you have a data structure called tree. Then tree has very limited points. It has a root. It has leaf nodes. And it has internal nodes. And if I can specify each of these. Then my job is done. So what are the root nodes in a tree? In this case. If I say that. I am making a tree. Root node is a node that corresponds to the start solution. And the leaf nodes. Are the nodes which correspond to. As far as grammar is concerned. Set of terminals. And internal nodes. They correspond to a non-terminal. So this is all I have. That I have a start symbol. I have internal nodes which correspond to. The non-terminals. And the leaf nodes. Which correspond to the terminals. Now if I try to look at the derivation there. And if I try to construct a parse tree for. 3 plus 4 minus 5. How will I do that? I will say that. I have this list. Which corresponds to the root node. And then this. I will draw this. On this side. So I have this list. Which derives. List goes to. List minus. So what I will do here is. I will say that. Corresponding to each of its. Right hand side symbols. And then I will have edges. Which will connect this. So I will say this actually. Derives. List minus. And then I did a derivation of this list. And the derivation one saying that. This goes to. List plus digit. So this gets replaced by. List plus digit. And then this list. Got. A derivation set list goes to digit. So here is a digit. And then. This digit went to 3. So this digit goes to 3. And then. The next digit goes to 4. So this digit goes to 4. And this digit goes to 5. So this really is a pass 3, 4. 3 plus 4 minus 5. With respect to the grammar. A different grammar will give you. Different pass. So this shows how the start symbol of a grammar. Derives a string in the language. So starting from here. If I am trying to grab this string. It says 3 plus 4 minus 5. Show you all the steps. And root is leveled by the start symbol. Leaf nodes are leveled by the tokens. And internal nodes are leveled by. Non-terminal. And how are edges constructed. That if I have a production which says. A goes to. X1, X2, Xn. Then. I must have. Some. Subtree here. Where the. Parent is going to be leveled by A. And the children nodes are going to be leveled by. X1 to Xn. And this is going to be an edge from. A to X1, A to X2 and so on. So this is like if I say that. If I just look at this part of. Or this subtree of my tree. This is. Parent is leveled by list. And all the children nodes are leveled by. All the symbols on the right hand side. And there is an edge from all this. Just a comment. Many of you are sleeping peacefully here. My advice is that. Better than you lose night for sleeping. And. Don't come to the class or. Here is one guy who is closing off. Okay. Another guy. Back to you. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Please. Have a good week. Please. Please. Please. Please help me. Have a good week. Please. Please. Please. Please. I am letting you皎 Please. Please. Please. Please. Please. You are doing a electrician. This is as n2? Okay. Umm. I will leave that on the right. Okay? 3 plus 4 minus 5, but let me say that my grammar looks something like this. Suppose I had a grammar which says list goes to list plus list or list goes to list minus list and then I say list goes to digit, this is the grammar I have as opposed to the earlier grammar and then I say that now digit goes to everything from 0 to 1. Now what will happen? Something very interesting can happen because now if I try to say that I am looking at 3 plus 4 minus 5, I can have multiple pastries for this. Can you see that? How do I get multiple pastries? Because I can always say list goes to list plus list and then I can expand the right hand side first or I can expand the left hand side first. So what will happen here is that grammar can have more than one pastry for a string. So look at this grammar. So I have string going to string plus string or string going to string minus string and then string going to one of the digits. I just absorb that step here and now if I try to construct pastry for this, the one pastry will look something like this that I will first say string goes to string plus string and then I may decide to expand the left hand most non-terminal by saying this string goes to string minus string and then this goes to 9, this goes to 5 and this goes to 2. So I am doing a left most derivation. Now I will do another left most derivation to derive the same thing from this now. So my left most derivation may be that I say string goes to string minus string. So instead of using this rule, I picked up this rule. Now why did I choose the first rule? I did not answer that, I did not specify that. So randomly I am choosing a rule so I just picked up another rule but I have at least said that I want to do the first derivation so I will not expand the right hand one but I will expand this and I have to say that this expands to 9. And then I decide that I want to now expand this and I expand this by saying that I am using a rule which says string goes to string plus string and then again this is my left most non-terminal so I decide to expand this and now this is the only left most non-terminal which I will expand to this. So I get 2 parsed trees, 2 left most derivations which are given with the same string and this I say is an ambiguous grammar. So the way this grammar has been written is giving rise to an ambiguity. Now if I am looking at the process of parsing, process of parsing just needs to check whether this is valid string in the language or not and that turns out that does not matter because I am getting the same answer, yes this is a valid string. So where is the problem? Is ambiguity therefore a problem? Because I am always in both the cases I am getting the same answer. See it would have a bigger problem if in one case the parsing would have filled that did not happen right. So where is the catch in ambiguity or there is no problem with ambiguity. Some reaction something, so is ambiguity a problem or not? Sir, where is the problem in deciding the priority of variations like where to parent states? Depth of parent states. So suppose I just take this, is this an issue? Sir, if instead of plus there would be. No, don't say inspeed I mean just tell me with respect to this example, is there any problem with either of this parsing or this parsing? Both are fine, well not exactly okay. Do you remember the Bortman's rule from your class 6 mathematics, class 6 mathematics right. Now what can happen is that when I start evaluating this at some point of time I will have to book out general and then I will say in this case okay I will say that I will start generating code for subtree and when I pick up code generating code for this subtree this will say that I want to subtract 5 from 9 and then it says I want to add 2 to that okay whereas when I start generating code for here it will say that I want to add 5 and 2 and then I subtract the result from 9. Now which parsing gives me the correct result? The first one, the second one is obviously giving me the correct result okay simpler than that okay and therefore I don't want to generate parsedies which will interpret my expression differently okay which will violate rules of mathematics okay this one actually is valid okay and that is the problem that I will be between that when I start associating meaning with these things then I will find that because of ambiguity I can get more than one meaning and some of the meanings are going to be invalid okay. So I want to make sure that ambiguity is handled in a manner that I never generate more than one parsedie because then there is no question of more than one interpretation and therefore I mean if you now see that the form of the grammar is important okay the way I wrote this grammar versus this grammar you will find that in this grammar I will not be able to generate ambiguous piece but in this grammar I can generate ambiguous piece by doing that most derivation okay. So ambiguity is a problem because meaning of the pronouns may be invalid okay and that is why I want to avoid ambiguity and it can be handled in more than one way okay so one way to handle ambiguity is that I start looking at all my operators and say that they have certain associativity they have certain residences and those must never be valid okay and the second thing is second way of doing is that I need to exit the grammar rather than so if you remember your LAC exercise okay somewhere at the top you had symbols like this okay and then I could write you remember this form one of the exercises in India okay they are saying that what are the operators which are left to associative what are the operators which are right to associative what are the operators which have higher incidence what are the operators which have lower incidence and so on okay. So you can specify this in the tool but this is not part of the grammar right this is what is tool providing okay what we would like to do that is that rather than handling it through a tool we make it part of the grammar so what we do is we re-read the grammar that is a much cleaner way so I won't depend upon the tool and there are more general techniques for handling ambiguity okay this is like I want to write a program I have to go through the specifications and make sure that I handle ambiguities correctly and this at least at this point of time we have no algorithm and such an algorithm will not be possible which can automatically convert an ambiguous grammar into an ambiguous grammar so if I give you grammar like this there is no algorithm which can convert this into grammar like this there is something we have to manually handle there is something we have to understand how do I write grammars and then actually write grammars which are going to be unambiguous so another aspect we come up with that we want to handle the associativity because this is also going to be captured as part of the grammar so if you have an operand and it has operators on both the sides then I want to pick up which operator is going to take this particular operand so you know that when you talk about associativity we say that addition is left associative okay or addition, multiplication, division and so on they are left associative so if B has plus on both the sides we know that I am going to evaluate A plus B first before I add C to this okay so this is what associativity is and we know that all these arithmetic operators are left associative so what I am enforcing here is nothing but chord mastery okay and exponentiation and assignment are right associative and this way I have written this grammar okay you can see that this grammar actually is a left recursive grammar okay and left recursive means that if I look at the first symbol first symbol is same as the left inside so I can keep on doing recursion on this and keep on expanding this so I can also generate for these kind of symbols I can write grammars which are right recursive and which will enforce right associativity so if I say assignment then assignment must be expanded from the right inside okay so when I write something like this so another way to look at this is that how do I put brackets okay so mentally if I say that I want to put brackets on this I am going to put brackets like this okay and if I say A is assigned B is assigned C I am going to put brackets I am going to put brackets like this so basically this is making my pre right heavy and this is making my pre left heavy okay and the same thing is captured here when I have right recursive rules I am saying right is going to letter being assigned right or letter and then letter is going to one of these okay so this will capture all the right associativity okay so form therefore okay once again coming back to this form that form of the grammar is important and I want to make sure that form is such that all the associativity and all the prejudices they are captured right in the now and you do not have to specify anything in a tool clear okay so presidences okay once again okay that even if I do not put brackets I know because of my knowledge of arithmetic that so same thing I will do with rest of the constructs that although I can have multiple pastries for this so suppose now I enrich my rules by saying that I will have one more rule which says list goes to list star list and I have one more rule which says list goes to list divided by list okay and then try to pass this train I can get multiple interpretations of this okay so one possible interpretation could be this interpretation another interpretation could be this as far as this grammar is concerned and you know that one of them is incorrect okay the first one is obviously not correct because we know that multiplication will take higher precedence and therefore this will get evaluated first before the addition happens okay so I have to make sure that that part is captured so presidences is going to determine the correct interpretation okay now ambiguity just does not come because of arithmetic expressions ambiguity can come because of other language constructs also okay so there is another problem okay and this is what we know as danglingel's problem okay that most programming languages will have a statement which will say if there else and then they will have a statement which will say if then okay and you can have a masking of those therefore in a sentence you may not have equal number of them and else's and question immediately comes is then what is the association between else's and then's if I look at it else is it associated which then it is associated with okay and how do I resolve that question so the grammar is something like this which says a statement space if expression this is a Boolean expression then statement or if expression then statement I'll say and this immediately gives rise to recursion which says that I can have any amount of nesting of if then I'll say okay so now let me give you this particular state which says if even then if e2 then s1 else s2 what is the meaning of this in which order I'm going to evaluate this so if even is true what will I do if even is true what we get executed if you do but if even is false then well why not s2 gets executed according to this grammar okay where does it say that if this is false then nothing should get executed because I can interpret this as saying that if e2 then s1 that is one statement and then if even then this is true else this statement is like okay so basically what can happen is that I can have two pastries for this this is one possible pastry which says statement goes to if expression then statement else statement and this statement gets expanded to then part and the second pastries of this form it says if expression then the statement and the statement has else lost so basically question I have to answer is whether this else is part of this statement or this else is part of this state right both are valid pastries as far as this interpretation is concerned okay but if I just try to make a block diagram for this and give you proper indentation this is a block diagram corresponding to this and this is the block diagram corresponding to this and which one is correct second one and why is that so what is the rule I am using here in case of paradigmatic I was using what is the rule I am using here nothing like in almost here so all we need to say here is one way to look at that is that each else must get associated with the closest then okay if I just do that that is the resolution okay now one way to handle that is that either I again now using yet how do I specify that else must be associated with the closest then here I was able to say what is the associativity what is the precedence how do I specify that in yet we have used this rule yet right so tell me how will you specify it in yet so I said there are two ways of rewriting the grammar one was that I give all this information about associativity and precedences as part of the tool and second was to rewrite the grammar itself okay so if I use the first technique and try to rewrite this grammar so that all the associativity and precedences are taking care of how do I do that well at least I am not aware of how to do that okay but what we can certainly do is we can rewrite the grammar okay so general rule is so we will see how to rewrite the grammar so I will show you more than one way of rewriting it so general rule is that match else with the closest previous then and this grammar can be now rewritten by saying that I can either have all the balance set of else is in that so I can have either have statements where number of else is our number of that in an associativity issue is very simple okay so these are called as match statement so match statement have equal number of else is in that okay or I can have unmatched statement where the number of else is okay so those are all unbalanced okay and now if it is matched then everything has to be matched right so if it is matched then if it is if expression then then this part has to be exactly match because this is unmatched then this whole thing will become unmatched right and if I say that this part is must have else and this part also must be matched so now you can see that if I am talking about match statement I have equal number of them analysis and then in the next thing also I have only the match statement okay so this will make sure that I do not have unequal number of them analysis but if I have others and what are these others which are any other statement other than if okay that will not change my number of them analysis okay but if I have unmatched okay so first thing that will happen is that if I do not have an else here then I can put any statement doesn't matter what statement whether this is matched or unmatched okay this itself just by having a then here not having an else here as match made it unmatched okay but if I say that I have to have this else associated associating with this then then at least the statement after then must be matched right then only this else can get associated because if this is not matched then it will not get associated it will get associated with one of the then okay so this is one way of writing so now you can see that I am not really using any of the tool specification anything which is specific to tool but I have really written my grammar okay by recognizing this fact that I can have more number of them than else's and then I can rewrite my grammar in this form here I say if this is unmatched then obviously this part has to be unmatched but at least this part has become matched and if you have completely matched then you only have equal number of matches equal number of them so this is one way of writing this is not the only way okay and I will show you more ways of rewriting okay a question others other is any statement so for example assignment why repeatedly anything which is other than if then else this one what about this first of all this is both unmatched if expression then so we are talking of this one right okay yeah so so I am saying that I am not trying to write specifications of statements which have unequal number of them okay now if it is unequal number of them analysis and I also want to capture this fact that each else must associate with it close with them okay then if I look at this okay if I have if then else then to make sure that this else associates with them okay between this I must have equal number of them analysis then only it can match okay but then whole thing has to be unbalanced then how do I make whole thing unbalanced by having an unmatched here so my life has another question here just for some other so why can't it be the other way around like unmatched statement switching here right then the problem will be we will not know how to match this then and else because if this part is unmatched that means it has more than then this else will get associated with another dance there no unmatched is not valid unmatched is okay but valid interpretation is that else was associated with some one of the dance but if I am writing a rule like this then this in this rule this is the right matching right so this is what I am capturing here we are not getting any expression than unmatched else match so the unmatched will have more number of there is than else so the else they have written down that can be associated with any of them from the unmatched part but then this expression then this expansion will become incorrect right what is the positive for this this is saying that this is one statement right so in this statement I want to make sure that this expansion happens such that this basically what you have to remember is that in this particular grammar rule if this is my expansion this is one statement if expression then matched else unmatched okay if I want to have this association then I must make sure that between them and else I have exact match and this will make sure that if I write my if than else grammar in this form that I will not have a problem of any kind of ambiguous let us move on to parsing now and see that with all this structure of the grammar and some of the transformations of the grammar I will leave for later when we know little more about parsing let us look at what is it that I want to do so what I want to do here is to begin with write certain grammars have certain strings and check whether these strings belong to the language which is specified by the grammar okay so this is the process of determination whether a string belongs to the language which is specified by the grammar okay and parsing is calling in two categories one is a string and now I will define these things with respect to the syntax parse tree I just constructed we say that if construction of parse tree starts from the root and goes up to the leaf nodes then this is really going in a top down manner and if construction of the parse tree starts from the leaf nodes and then finally the root gets constructed then we say that this is really a bottom of parser okay so one thing you can or another thing you can do is that if I am doing this derivation I am getting constructed from the start symbol and then I finally reach a string okay then I say this is really a top down parser because this is where I started constructing or if I start from the leaf nodes okay and slowly keep going back and say that yes I can reduce this whole string to the start symbol then that is bottom of parser okay because a parse tree which is getting constructed from the leaf nodes finally it will say that whether I can construct a root in that way it is going to be the bottom of parser okay so these are two techniques of parsing we will use and antler is a tool which supports top down parser and jack and bison are the tools which support bottom of parser then we will also see methods of doing top down parsing versus bottom up and we actually see that bottom of parsers are more powerful compared to top down parser okay and when I say more powerful what is that bottom of parsers will be able to handle more languages than what a top down parser can handle okay the set of languages which can be specified by a top down parser or can be handled by a top down parser are fewer than bottom of parser and therefore although we use both the methods ultimately we will spend little more time on bottom of parser as compared to top of parser okay so this is where I want to break and we will continue our discussion in the next class from this point on and our next class is on Sunday 11.45