1 / 10

CONFLICTS IN PARSING

CONFLICTS IN PARSING. In the process of Parsing,a stage where there is a problem in deciding the production to be used is referred to as CONFLICT. There are two kinds of conflicts possible a) Shift-Reduce Conflict. b) Reduce-Reduce Conflict. SHIFT REDUCE CONFLICT.

aquene
Download Presentation

CONFLICTS IN PARSING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CONFLICTS IN PARSING • In the process of Parsing,a stage where there is a problem in deciding the production to be used is referred to as CONFLICT. • There are two kinds of conflicts possible a) Shift-Reduce Conflict. b) Reduce-Reduce Conflict.

  2. SHIFT REDUCE CONFLICT • Consider the symbol-stack in process of parsing as X = $F • Now,there input string,w points to * • There also exists a production T->F. • We can either SHIFT,thereby X = $F* • We can REDUCE,thereby X = $T. • This condition is referred to as shift reduce conflict.

  3. REDUCE REDUCE CONFLICT • Consider the symbol-stack in process of parsing as X = $MaAB • Let's say there exists two productions which give rise to Aab. • Y->Aab and X->Aab. • Now,which production to be chosen for reduction is again a question. • This is called Reduce Reduce Conflict.

  4. RESOLUTION OF CONFLICTS • These conflicts depend on the implementation and can be removed by using the following parsers. a)Operator Precedence Parser b)LR Parser : i)SLR Parser ii)CLR Parser iii)LALR Parser

  5. OPERATOR PRECEDENCE PARSER • This is a very primitive parser • This works only for Mathematical/Arithmetic expressions. • It consists of a Precedence Table,which serves as information when the stack top and the current input symbol is known and we want to shift or reduce.This is valid for a specific set of grammar.

  6. OPERATOR GRAMMAR • The operator grammar produces all the strings that can be parsed using an operator precedence parser.No other strings will be parsed.Hence,the language follows certain restrictions. • No ϵ-Transitions are allowed. • No 2 or more consecutive Non terminal symbols allowed in the body of any production.

  7. PRECEDENCE INFORMATION • To design a Precedence Table,we need to store the precedence information.So,whenever two terminals A,B occur,we can define few precedence operators • .> • .= • <.

  8. DEFINITION OF OPERATORS • A .> B implies that A has higher precedence than B. • A <. B implies that A has lesser precedence than B. • A .= B implies that A has equal precedence as B.

  9. PRECEDNCE TABLE • Consider 3 sample terminals id,+,*,$ • The precedence order is id > * >+ >$ • Wherever 2 operators have same precedence,like a = '+' and b = '+'.where a occurs before b in an expression.Now,we check for associativity of the operator.As '+' is left associative,a .> b will be assigned in the table.

  10. PRECEDENCE TABLE • The terminal a is on the Row and the terminal b is on the column and here is the final precedence table • In this way,Precedence table can be made for any grammar which will be used in Parsing.

More Related