{"id":63,"date":"2018-07-19T10:59:04","date_gmt":"2018-07-19T10:59:04","guid":{"rendered":"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=63"},"modified":"2018-07-19T11:00:43","modified_gmt":"2018-07-19T11:00:43","slug":"parsing-action-of-operator-precedence-parser-and-precedence-function","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/chapter\/parsing-action-of-operator-precedence-parser-and-precedence-function\/","title":{"rendered":"PARSING ACTION OF OPERATOR PRECEDENCE PARSER AND PRECEDENCE FUNCTION"},"content":{"raw":"<p style=\"text-align: justify\">After learning to construct the operator precedence parsing table, in this module we would learn the operator precedence parsing algorithm with an example and the errors that is encountered by an Operator Precedence parser. The precedence graph and precedence function associated with the operator precedence parser will also be discussed in this module.<\/p>\r\n&nbsp;\r\n\r\n<strong>13.1 Ope rator Precedence parsing<\/strong>\r\n\r\n&nbsp;\r\n\r\nWe have seen the first three steps in the Operator precedence parser. Verifying whether a grammar is operator precedence, computing of LEADING, TRAILING and construction of operator precedence parsing table was already done in the previous module. The next step is the Parsing algorithm and is given in algorithm 13.1\r\n\r\n&nbsp;\r\n\r\n<strong>Algorithm 13.1 (Grammar G, input string w, Parsing table T)<\/strong>\r\n\r\n&nbsp;\r\n\r\n{set p to point to the first symbol of w$ ;\r\n\r\n&nbsp;\r\n\r\n<strong>repeat forever<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>if <\/strong>( $ is on top of the stack<strong> and <\/strong>p points to $ )<strong> then return; \/\/ success else <\/strong>{\r\n\r\n&nbsp;\r\n\r\nlet a be the topmost terminal symbol on the stack; let b be the symbol pointed to by p;\r\n\r\n&nbsp;\r\n\r\n1. if ( a &lt;.b or a =\u00b7 b ) then { \/* SHIFT *\/\r\n\r\npush b onto the stack;\r\nadvance p to the next input symbol;\r\n}\r\n\r\n2. else if ( a .\r\n&gt; b ) then \/* REDUCE *\/\r\nrepeat pop stack\r\nuntil ( the top of stack terminal is related by &lt;.\u00a0 to the terminal most\u00a0 recently popped );\r\n3. else error(); \/*ERROR*\/\r\n<div>\r\n\r\n}\r\n\r\n&nbsp;\r\n\r\n}\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The input string \u201cw\u201d is appended with a \u201c$\u201d symbol at the end and is converted to w$. The stack is initialized with the $ symbol to acts as the initial stack symbol. As this parser is a bottom- up parser, the four actions of shift, reduce, error, accepts is handled by this parser also. The parser announces successful parsing and acceptance of a string, if there is a $ that matches the stack and the input. This is given in the beginning of the algorithm. The next step of the<\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n<p style=\"text-align: justify\">algorithm loops until the existence of a string. The stack symbol is compared with the input symbol for precedence relation in the parsing table. If the precedence relation is lesser than or equal to, then the input character is pushed on to the stack and thus making the input pointer advances by one position to the right. If the precedence relation is greater than, then we reduce by popping the stack till the top of stack terminal is related by &lt;. to the terminal most recently popped. If there is no relation defined between the symbols in the stack and input, we announce an error action.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Example 13.1 Consider the input string id + id * id and let us see how the parsing action is carried out by the Operator precedence parser. For quick reference, the parsing table is given table 13.1 and the parsing action is given in Table 13.2<\/p>\r\n&nbsp;\r\n\r\n<strong>Table 13.1 Parsing table<\/strong>\r\n\r\n<img class=\"size-full wp-image-64 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-25.png\" alt=\"\" width=\"725\" height=\"640\" \/>\r\n\r\n<img class=\"size-full wp-image-65 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-26.png\" alt=\"\" width=\"709\" height=\"129\" \/>\r\n\r\n<strong>13.2 Issues in Operator Precedence parsing.<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Operator-Precedence parsing cannot handle the unary minus if the grammar has binary subtraction operator. The best approach to solve this problem is to tackle the unary operator at the lexical phase using one or both of the following approaches:<\/p>\r\n&nbsp;\r\n<ul>\r\n \t<li style=\"text-align: justify\">The lexical analyzer can be made to return two different tokens for the unary minus and the binary minus.<\/li>\r\n \t<li style=\"text-align: justify\">The lexical analyzer will need a lookahead to distinguish the binary minus from the unary minus.<\/li>\r\n<\/ul>\r\nAfter identifying this, we then define the precedence of the all operators in comparison with unary- minus as follows:\r\n<ul>\r\n \t<li>For any operator q, we set q &lt;. unary- minus<\/li>\r\n \t<li>We then modify the relation,<\/li>\r\n \t<li>o if unary- minus has higher precedence than q, we set unary-minus .&gt; q<\/li>\r\n \t<li>o if unary- minus has lower (or equal) precedence than q , we set unary- minus &lt;. q<\/li>\r\n<\/ul>\r\n&nbsp;\r\n\r\nAfter constructing the precedence table based on the rules discussed in this section, the parsing action is similar to what has been already discussed.\r\n\r\n&nbsp;\r\n\r\n<strong>13.3 Precedence Functions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The operator precedence parsers usually do not store the precedence table with the relations, rather they are implemented in a special way. Operator precedence parsers use precedence functions that map terminal symbols to integers, and so the precedence re lations between the symbols are implemented by numerical comparison. Not every table of precedence relations has precedence functions but in practice for most grammars such functions can be designed.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The precedence table is typically stored as a precedence function. The precedence table is coded as two functions f() and g() corresponding to the row and table. The idea behind the precedence functions is to define nodes and edges for all the terminals of a grammar in terms of<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">the functions f() and g(). For symbols \u2018a\u2019 and \u2018b\u2019 we define the functions f(a) and g(b) based on the precedence between the operators \u2018a\u2019 and \u2018b. The following is used as the basis.<\/p>\r\n\r\n<ul>\r\n \t<li>if a &lt;. b then f(a) &lt; g(b)<\/li>\r\n \t<li>if a =\u00b7 b, then f(a) = g(b)<\/li>\r\n \t<li>if a .&gt; b, then f(a) &gt; g(b)<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">The algorithm for constructing the precedence function is given in Algorithm 13.2 where the input will be the precedence table.<\/p>\r\n&nbsp;\r\n\r\n<strong>Algorithm 13.2<\/strong>\r\n\r\n&nbsp;\r\n\r\nPrecedence_Function(Precedence table T, Precedence Function f)\r\n\r\n&nbsp;\r\n\r\n{\r\n<ol>\r\n \t<li style=\"text-align: justify\">Create symbols fa and gb for each \u2018a\u2019 that is a terminal or $.<\/li>\r\n \t<li style=\"text-align: justify\">Partition the created symbols into as many groups as possible, in such a way that if a =. b, then fa and gb are in the same group.<\/li>\r\n \t<li style=\"text-align: justify\">Create a directed graph whose nodes are the groups found in the previous step. For any \u2018a\u2019 and \u2018b\u2019, if a &lt;.b , place an edge from the group of gb to the group of fa. If a .&gt; b, place an edge from the group of fa to that of gb.<\/li>\r\n \t<li style=\"text-align: justify\">If the graph constructed has a cycle, then no precedence functions exist. If there are no cycle, let f(a) be the length of the longest path beginning at the group of fa ; let g(a) be the length of the longest path beginning at the group of ga.<\/li>\r\n<\/ol>\r\n}\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Algorithm 13.2 lists the steps involved in constructing the precedence graph. After constructing the precedence graph the precedence function computes the length of the longest path for all the terminals.<\/p>\r\n<p style=\"text-align: justify\">Example 13.2 Consider the expression grammar containing the terminals +. *, id and $ whose precedence table is defined in Table 13.1.<\/p>\r\n<p style=\"text-align: justify\">By step 2 of the algorithm, we could define the following functions for f() and g()<\/p>\r\n\r\n<ul>\r\n \t<li style=\"text-align: justify\">f+, f*, fi d, f$ are the four functions of \u2018f\u2019<\/li>\r\n \t<li>g+, g*, gi d, g$ are the four function of \u2018g\u2019<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify\">Since, there is no equal precedence relation in this table, f() and g() for all the terminals will not be in the same group. Using step 3 of the algorithm 13.2 we construct the edges and is given in figure 13.1<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-66 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-27.png\" alt=\"\" width=\"657\" height=\"854\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>13.4 Error handling in Operator Precedence Parser<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The operator precedence parser can handle only a small class of grammars. However, it cannot handle the unary minus (the lexical analyzer should handle the unary minus). The issues in Operator precedence parser is it finds difficulty in deciding the language of the grammar. This parser cannot have a relation between the terminal on the top of stack and the next input symbol. A handle is found (reduction step), but there is no production with this handle as RHS.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">However, to handle the small class of grammar the operator precedence parser has to perform error recovery by one of the following tasks:<\/p>\r\n\r\n<ol>\r\n \t<li style=\"text-align: justify\">As in the LL(1) parser, each empty entry in the precedence table is filled with a pointer to an error routine.<\/li>\r\n \t<li style=\"text-align: justify\">Matches what the popped handle resembles which right hand side of the production and tries to recover from that situation. In order to recover, we must modify (insert\/change)<\/li>\r\n<\/ol>\r\n<ul>\r\n \t<li>Stack or<\/li>\r\n \t<li>Input or<\/li>\r\n \t<li>Both<\/li>\r\n<\/ul>\r\nThe error recovery routines can be grouped into four scenarios as described below:\r\n\r\n&nbsp;\r\n\r\ne1: Scenario: Entire expression is missing: To handle this case, we insert \u201cid\u201d to the input and issue a message - \u2018missing operand\u2019 or \u2018no input\u2019\r\n\r\ne2: Scenario: Expression begins with a right parenthesis: To handle this case, we delete \u2018)\u2019 from the input and issue message - \u2018unbalanced right parenthesis\u2019\r\n\r\ne3: Scenario: Expression has, id or ) is followed by id or (. To handle this situation insert + to the input and issue message - \u2018missing operator\u2019\r\n\r\ne4: Scenario: expression ends with a left parenthesis. To handle this case,\u00a0\u00a0\u00a0\u00a0 pop\u00a0 ( from the stackand issue message: \u2018missing right parenthesis\u2019\r\n\r\n&nbsp;\r\n\r\nThe various scenarios are depicted in Table 13.4\r\n\r\n<img class=\"size-full wp-image-67 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-28.png\" alt=\"\" width=\"412\" height=\"341\" \/>\r\n\r\n<img class=\"size-full wp-image-68 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-29.png\" alt=\"\" width=\"657\" height=\"659\" \/>\r\n\r\n<img class=\"size-full wp-image-69 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-30.png\" alt=\"\" width=\"496\" height=\"349\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>Summary: <\/strong>This module discussed the parsing action of an Operator Precedence Parser. We also discussed precedence functions and some error recovery strategies of the operator precedence parser.","rendered":"<p style=\"text-align: justify\">After learning to construct the operator precedence parsing table, in this module we would learn the operator precedence parsing algorithm with an example and the errors that is encountered by an Operator Precedence parser. The precedence graph and precedence function associated with the operator precedence parser will also be discussed in this module.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>13.1 Ope rator Precedence parsing<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>We have seen the first three steps in the Operator precedence parser. Verifying whether a grammar is operator precedence, computing of LEADING, TRAILING and construction of operator precedence parsing table was already done in the previous module. The next step is the Parsing algorithm and is given in algorithm 13.1<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Algorithm 13.1 (Grammar G, input string w, Parsing table T)<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>{set p to point to the first symbol of w$ ;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>repeat forever<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>if <\/strong>( $ is on top of the stack<strong> and <\/strong>p points to $ )<strong> then return; \/\/ success else <\/strong>{<\/p>\n<p>&nbsp;<\/p>\n<p>let a be the topmost terminal symbol on the stack; let b be the symbol pointed to by p;<\/p>\n<p>&nbsp;<\/p>\n<p>1. if ( a &lt;.b or a =\u00b7 b ) then { \/* SHIFT *\/<\/p>\n<p>push b onto the stack;<br \/>\nadvance p to the next input symbol;<br \/>\n}<\/p>\n<p>2. else if ( a .<br \/>\n&gt; b ) then \/* REDUCE *\/<br \/>\nrepeat pop stack<br \/>\nuntil ( the top of stack terminal is related by &lt;.\u00a0 to the terminal most\u00a0 recently popped );<br \/>\n3. else error(); \/*ERROR*\/<\/p>\n<div>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The input string \u201cw\u201d is appended with a \u201c$\u201d symbol at the end and is converted to w$. The stack is initialized with the $ symbol to acts as the initial stack symbol. As this parser is a bottom- up parser, the four actions of shift, reduce, error, accepts is handled by this parser also. The parser announces successful parsing and acceptance of a string, if there is a $ that matches the stack and the input. This is given in the beginning of the algorithm. The next step of the<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">algorithm loops until the existence of a string. The stack symbol is compared with the input symbol for precedence relation in the parsing table. If the precedence relation is lesser than or equal to, then the input character is pushed on to the stack and thus making the input pointer advances by one position to the right. If the precedence relation is greater than, then we reduce by popping the stack till the top of stack terminal is related by &lt;. to the terminal most recently popped. If there is no relation defined between the symbols in the stack and input, we announce an error action.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Example 13.1 Consider the input string id + id * id and let us see how the parsing action is carried out by the Operator precedence parser. For quick reference, the parsing table is given table 13.1 and the parsing action is given in Table 13.2<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Table 13.1 Parsing table<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-64 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-25.png\" alt=\"\" width=\"725\" height=\"640\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-25.png 725w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-25-300x265.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-25-65x57.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-25-225x199.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-25-350x309.png 350w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-65 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-26.png\" alt=\"\" width=\"709\" height=\"129\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-26.png 709w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-26-300x55.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-26-65x12.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-26-225x41.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-26-350x64.png 350w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/p>\n<p><strong>13.2 Issues in Operator Precedence parsing.<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Operator-Precedence parsing cannot handle the unary minus if the grammar has binary subtraction operator. The best approach to solve this problem is to tackle the unary operator at the lexical phase using one or both of the following approaches:<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"text-align: justify\">The lexical analyzer can be made to return two different tokens for the unary minus and the binary minus.<\/li>\n<li style=\"text-align: justify\">The lexical analyzer will need a lookahead to distinguish the binary minus from the unary minus.<\/li>\n<\/ul>\n<p>After identifying this, we then define the precedence of the all operators in comparison with unary- minus as follows:<\/p>\n<ul>\n<li>For any operator q, we set q &lt;. unary- minus<\/li>\n<li>We then modify the relation,<\/li>\n<li>o if unary- minus has higher precedence than q, we set unary-minus .&gt; q<\/li>\n<li>o if unary- minus has lower (or equal) precedence than q , we set unary- minus &lt;. q<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>After constructing the precedence table based on the rules discussed in this section, the parsing action is similar to what has been already discussed.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>13.3 Precedence Functions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The operator precedence parsers usually do not store the precedence table with the relations, rather they are implemented in a special way. Operator precedence parsers use precedence functions that map terminal symbols to integers, and so the precedence re lations between the symbols are implemented by numerical comparison. Not every table of precedence relations has precedence functions but in practice for most grammars such functions can be designed.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The precedence table is typically stored as a precedence function. The precedence table is coded as two functions f() and g() corresponding to the row and table. The idea behind the precedence functions is to define nodes and edges for all the terminals of a grammar in terms of<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">the functions f() and g(). For symbols \u2018a\u2019 and \u2018b\u2019 we define the functions f(a) and g(b) based on the precedence between the operators \u2018a\u2019 and \u2018b. The following is used as the basis.<\/p>\n<ul>\n<li>if a &lt;. b then f(a) &lt; g(b)<\/li>\n<li>if a =\u00b7 b, then f(a) = g(b)<\/li>\n<li>if a .&gt; b, then f(a) &gt; g(b)<\/li>\n<\/ul>\n<p style=\"text-align: justify\">The algorithm for constructing the precedence function is given in Algorithm 13.2 where the input will be the precedence table.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Algorithm 13.2<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Precedence_Function(Precedence table T, Precedence Function f)<\/p>\n<p>&nbsp;<\/p>\n<p>{<\/p>\n<ol>\n<li style=\"text-align: justify\">Create symbols fa and gb for each \u2018a\u2019 that is a terminal or $.<\/li>\n<li style=\"text-align: justify\">Partition the created symbols into as many groups as possible, in such a way that if a =. b, then fa and gb are in the same group.<\/li>\n<li style=\"text-align: justify\">Create a directed graph whose nodes are the groups found in the previous step. For any \u2018a\u2019 and \u2018b\u2019, if a &lt;.b , place an edge from the group of gb to the group of fa. If a .&gt; b, place an edge from the group of fa to that of gb.<\/li>\n<li style=\"text-align: justify\">If the graph constructed has a cycle, then no precedence functions exist. If there are no cycle, let f(a) be the length of the longest path beginning at the group of fa ; let g(a) be the length of the longest path beginning at the group of ga.<\/li>\n<\/ol>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Algorithm 13.2 lists the steps involved in constructing the precedence graph. After constructing the precedence graph the precedence function computes the length of the longest path for all the terminals.<\/p>\n<p style=\"text-align: justify\">Example 13.2 Consider the expression grammar containing the terminals +. *, id and $ whose precedence table is defined in Table 13.1.<\/p>\n<p style=\"text-align: justify\">By step 2 of the algorithm, we could define the following functions for f() and g()<\/p>\n<ul>\n<li style=\"text-align: justify\">f+, f*, fi d, f$ are the four functions of \u2018f\u2019<\/li>\n<li>g+, g*, gi d, g$ are the four function of \u2018g\u2019<\/li>\n<\/ul>\n<p style=\"text-align: justify\">Since, there is no equal precedence relation in this table, f() and g() for all the terminals will not be in the same group. Using step 3 of the algorithm 13.2 we construct the edges and is given in figure 13.1<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-66 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-27.png\" alt=\"\" width=\"657\" height=\"854\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-27.png 657w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-27-231x300.png 231w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-27-65x84.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-27-225x292.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-27-350x455.png 350w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>13.4 Error handling in Operator Precedence Parser<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The operator precedence parser can handle only a small class of grammars. However, it cannot handle the unary minus (the lexical analyzer should handle the unary minus). The issues in Operator precedence parser is it finds difficulty in deciding the language of the grammar. This parser cannot have a relation between the terminal on the top of stack and the next input symbol. A handle is found (reduction step), but there is no production with this handle as RHS.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">However, to handle the small class of grammar the operator precedence parser has to perform error recovery by one of the following tasks:<\/p>\n<ol>\n<li style=\"text-align: justify\">As in the LL(1) parser, each empty entry in the precedence table is filled with a pointer to an error routine.<\/li>\n<li style=\"text-align: justify\">Matches what the popped handle resembles which right hand side of the production and tries to recover from that situation. In order to recover, we must modify (insert\/change)<\/li>\n<\/ol>\n<ul>\n<li>Stack or<\/li>\n<li>Input or<\/li>\n<li>Both<\/li>\n<\/ul>\n<p>The error recovery routines can be grouped into four scenarios as described below:<\/p>\n<p>&nbsp;<\/p>\n<p>e1: Scenario: Entire expression is missing: To handle this case, we insert \u201cid\u201d to the input and issue a message &#8211; \u2018missing operand\u2019 or \u2018no input\u2019<\/p>\n<p>e2: Scenario: Expression begins with a right parenthesis: To handle this case, we delete \u2018)\u2019 from the input and issue message &#8211; \u2018unbalanced right parenthesis\u2019<\/p>\n<p>e3: Scenario: Expression has, id or ) is followed by id or (. To handle this situation insert + to the input and issue message &#8211; \u2018missing operator\u2019<\/p>\n<p>e4: Scenario: expression ends with a left parenthesis. To handle this case,\u00a0\u00a0\u00a0\u00a0 pop\u00a0 ( from the stackand issue message: \u2018missing right parenthesis\u2019<\/p>\n<p>&nbsp;<\/p>\n<p>The various scenarios are depicted in Table 13.4<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-67 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-28.png\" alt=\"\" width=\"412\" height=\"341\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-28.png 412w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-28-300x248.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-28-65x54.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-28-225x186.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-28-350x290.png 350w\" sizes=\"auto, (max-width: 412px) 100vw, 412px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-68 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-29.png\" alt=\"\" width=\"657\" height=\"659\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-29.png 657w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-29-150x150.png 150w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-29-300x300.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-29-65x65.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-29-225x226.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-29-350x351.png 350w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-69 aligncenter\" src=\"http:\/\/csp10.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-30.png\" alt=\"\" width=\"496\" height=\"349\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-30.png 496w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-30-300x211.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-30-65x46.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-30-225x158.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-content\/uploads\/sites\/50\/2018\/07\/Untitled-30-350x246.png 350w\" sizes=\"auto, (max-width: 496px) 100vw, 496px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary: <\/strong>This module discussed the parsing action of an Operator Precedence Parser. We also discussed precedence functions and some error recovery strategies of the operator precedence parser.<\/p>\n","protected":false},"author":4,"menu_order":13,"template":"","meta":{"_acf_changed":false,"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-rajeswari-sridhar"],"pb_section_license":""},"chapter-type":[],"contributor":[59],"license":[],"class_list":["post-63","chapter","type-chapter","status-publish","hentry","contributor-dr-rajeswari-sridhar"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapters\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":2,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapters\/63\/revisions"}],"predecessor-version":[{"id":71,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapters\/63\/revisions\/71"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapters\/63\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/pressbooks\/v2\/chapter-type?post=63"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/wp\/v2\/contributor?post=63"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp10\/wp-json\/wp\/v2\/license?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}