 Hello everyone, I am Mrs. Sunita Dore. Topic covered here is bottom-up passing, shift-reduce passing. A top-down passer tries to create a pass tree from the root towards the leaf, scanning input from left to right, while bottom-up passer constructs pass tree for an input string beginning at the leaves and working up towards the root. In this video, we are going to cover a general style of bottom-up syntax analysis known as shift-reduce passing. Learning outcome, at the end of the session, students will be able to derive the actions of a shift-reduce passer for a given string of grammar in passing and identify the conflicts during the shift-reduce passing. Shift-reduce passing constructs pass tree for an input string beginning at the leaves and working up towards the root. So we can think this process as one of reducing a string w to the start symbol of a grammar. At each deduction step, a particular substring matching the right side of the production is replaced by the symbol on the left side of that production and if the substring is chosen correctly at each step, a rightmost derivation in reverse is traced out. Consider the grammar for the arithmetic expression string id into id, leftmost derivation for id into id and the bottom-up passing for string id into id is also given on the slide. A handle of a string is a substring that matches the right side of a production and whose reduction to the non-terminal on the left side of that production represent one step along the reverse of rightmost derivation. Consider the grammar for arithmetic expression capital E derives capital E plus capital E. Capital E derives capital E into capital E. Capital E derives in parenthesis capital E and capital E derives id. Here we underline a handle of each right-sentential form. For example, id1 is an handle of the right-sentential form id1 plus id2 into id3 because id is the right side of the production E derives id and replacing id1 by E produces the previous right-sentential form E plus id2 into id3. The string appearing to the right of a handle contains only terminal symbol. As this grammar is ambiguous, there is another rightmost derivation of the same string id1 plus id2 into id3. In this derivation capital E plus capital E is a handle of capital E plus capital E into id3 whereas id3 by itself is a handle of this same right-sentential form. The first derivation gives star a higher precedence than plus whereas second gives plus the higher precedence. Rightmost derivation in reverse can be obtained by handle pruning. Consider the grammar and the input string id1 plus id2 into id3. The sequence of the reduction shown in the first table reduces id1 plus id2 into id3 to the start symbol capital E. As this grammar is ambiguous, there is one more sequence of reduction shown in the second table which also reduces id1 plus id2 into id3 to the start symbol capital E. Consider the same grammar after eliminating the ambiguity from the grammar considered in the previous slide. Since this grammar is unambiguous, so there here we get only one derivation for the string id1 plus id2 into id3. There are two problems if we are to pass the string by handle pruning. The first is to locate the substring to be reduced in the right-sentential form and the second is to determine what production to choose in case there is more than one production with that substring on the right-hand side. A convenient way to implement a shift reduced parser is to use a stack to hold the grammar in the symbols and an input buffer to hold the string w to be passed. We use dollar to mark the bottom of the stack and also the right end of the input. Initially, the stack is empty and the string w is on the input as shown here on the slide. The parser shifts 0 or more input symbol onto the stack until a handle beta is on the top of the stack. The parser then reduces beta to the left-hand side of the appropriate production. The parser repeats this cycle until it has detected an error or until the stack contains the start symbol and the input is empty. After entering acceptance configuration, the parser holds and announces successful completion of parsing. There are four possible actions a shift reduced parser can make shift, reduce, accept and error. In shift action, the next input symbol is shifted onto the top of the stack. In reduce action, the parser knows the right end of the handle is at the top of the stack. It locates the left hand of the handle within the stack and decides with what term, non-terminal to replace the handle. In accept action, the parser announced successful completion of parsing. In an error action, the parser discovered that a syntax error has occurred and calls an error recovery routine. Consider stack implementation of shift reduce parsing for id1 plus id2 into id3 using the grammar given on the slide. First table represents the action a shift reduced parser might make in passing the input string id1 plus id2 into id3 according to the grammar given. As the grammar is ambiguous, the grammar has two rightmost derivation for this input. Second table shows another sequence of steps a shift reduced parser might make. Till now, we consider the shift reduced parsing and stack implementation of shift reduced parsing. Now pause this video and reflect on this question for a minute or two minutes and write your response. Once you return the answer to this question, then you can restart playing this video. The question is derive the string id plus id from following grammar using shift reduced parsing. I hope all of you have completed this activity. So the question was derive the string id plus id from following grammar using shift reduced parsing. As this grammar is ambiguous, there will be only one sequence of steps a shift reduced parsing might take as shown in the table. There are context free grammar for which shift reduced parsing cannot be used. There are two conflicts in search grammar. Knowing the entire stack content and the next input symbol, parser cannot decide whether to shift or to reduce that is shift reduced conflict or parser cannot decide which of the several reductions to make that is the reduce reduce conflict. Consider the example that is statement derives if expression then statement or if expression then statement else statement or other. If we have a shift reduced parser in the configuration like stack contains if expression then statement and the input is else dollar. We cannot tell whether if expression then statement is the handle no matter what appears below it on the stack. So here there is a shift reduced conflict depending on what follows the else on the input it might be correct to reduce the if expression then statement to statement or it might be correct to shift else and then look for another statement to complete the alternative if expression then statement. So here we cannot tell whether to shift or reduce in this case. So this grammar is not ll1. Consider the example for reduce reduce conflict where we have a lexical analyzer that returns token id for all identifiers regardless of usage. Suppose the language invoke the procedure by giving their names with the parameter surrounded by parenthesis and the array are referenced by the same syntax. Since the translation of indices in the array references and the parameters in the procedure calls are different we use different production to generate the list of actual parameter and indices. So the grammar have the productions given on this slide. A statement beginning with a of i, j would appear as the token stream id in bracket id, id to the parser. After shifting the first 3 tokens onto the stack a shift reduce parser would be in the configuration that is stack contains id left parenthesis id while the input is comma id right parenthesis and the dollar. So the id on the top of the stack must be reduced by reduce but by which productions. The correct choice is a production 5 if capital E is a procedure and the production 7 if the capital E is an array. This is the reference used for preparing this presentation. Thank you.