0% found this document useful (0 votes)
14 views

Operator Precedence Parsing

The document defines leading and trailing symbols for grammar rules and uses them to construct an operator precedence parsing table according to two rules. Rule 1 defines the relations between leading symbols of the start symbol and trailing symbols of the start symbol. Rule 2 uses the leading and trailing symbols of non-terminals on the right hand side of rules to fill in additional relations in the table. The document provides examples of applying the two rules to construct the operator precedence table for a sample grammar.

Uploaded by

Right Way
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Operator Precedence Parsing

The document defines leading and trailing symbols for grammar rules and uses them to construct an operator precedence parsing table according to two rules. Rule 1 defines the relations between leading symbols of the start symbol and trailing symbols of the start symbol. Rule 2 uses the leading and trailing symbols of non-terminals on the right hand side of rules to fill in additional relations in the table. The document provides examples of applying the two rules to construct the operator precedence table for a sample grammar.

Uploaded by

Right Way
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

• s

Leading
• Leading(A) ={a | a is left most terminal in some string
derived from A}
• A -> Ya ;Y is a single non-Terminal; Here Y can be ε;
• a ∈ Leading(A)
• E -> E+T|T; T->T*F|F; F->(E)|id
• Leading(F) = {(,id}; Leading(T) = {*}; Leading(E) = {+}
• A -> Y ; Y is a single non-Terminal; Here  can be any
string;
• Leading(Y) ∈ Leading(A)
• {(,id} ∈ Leading(T); Due to T->F
• Leading(T) = {*,(,id}
• {*,(,id} ∈ Leading(E) ; Due to E->T
• Leading(E) = {+,*,(,id}
Leading
• Finally,
• Leading(F) = {(,id}
• Leading(T) = {*,(,id}
• Leading(E) = {+,*,(,id}
Trailing
• Trailing(A) ={a | a is right most terminal in some string
derived from A}
• A -> aY ; Y is a single non-Terminal; Here Y can be ε;
• a ∈ Trailing(A)
• E -> E+T|T; T->T*F|F; F->(E)|id
• Trailing(F) = {),id}; Trailing(T) = {*}; Trailing(E) = {+}
• A -> Y ; Y is a single non-Terminal; Here  can be any
string;
• Trailing(Y) ∈ Trailing(A)
• {),id} ∈ Trailing(T) ; Due to T->F
• Trailing(T) = {*,),id}
• {*,),id} ∈ Trailing(E) ; Due to E->T
• Trailing(E) = {+,*,),id}
Trailing
• Finally,
• Trailing(F) = {),id}
• Trailing(T) = {*,),id}
• Trailing(E) = {+,*,),id}
Construction of Operator-precedence
relations : Rule-1
• $<a for all a ∈ Leading(StartSymbol)($ in row, a in column)
• b>$ for all b ∈ Trailing(StartSymbol)(b in row,$ in column)
• $<+; $<*; $<(; $<id;
• +<$; *<$; )<$; id<$;
+ * ( ) id $
+ >
* >
(
) >
id >
$ < < < <
• If Y -> ab𝛾;  is ε or a single non-Terminal
then a = b;

+ * ( ) id $
+ >
* >
( =
) >
id >
$ < < < <
• If Y -> aA; a<b for all b in Leading(A)
• E -> E+T ==> +<* ; +<(; +<id
• T -> T*F ==> *<(; *<id
• F -> (E) ==> (<+; (<*; (<(; (<id
+ * ( ) id $
+ < < < >
* < < >
( < < < = <
) >
id >
$ < < < <
• If Y -> Ab; a>b for all a in Trailing(A)
• E -> E+T ==> +>+; *>+; )>+; id>+
• T -> T * F ==> *>*; )>*; id>*
• F -> (E) ==> * > ); +>); )>); id>)
+ * ( ) id $
+ > < < > < >
* > > < > < >
( < < < = <
) > > > >
id > > > >
$ < < < <

You might also like