210 likes | 552 Views
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.
E N D
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 • 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.
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.
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
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.
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.
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 • .> • .= • <.
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.
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.
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.