Write down steps to set precedence relationship for operator precedence grammar.Design precedence table for : E -> E+E | E*E | E^E | id
There are the three operator precedence relations:
a
> b |
means that terminal
"a" has the higher precedence than terminal "b" |
a
< b |
means that terminal
"a" has the lower precedence
than terminal "b" |
a
= b |
means that terminal
"a" and "b"
both have same precedence |
Precedence table:
|
+ |
* |
( |
) |
id |
$ |
+ |
> |
< |
< |
> |
< |
> |
* |
> |
> |
< |
> |
< |
> |
( |
< |
< |
< |
= |
< |
X |
) |
> |
> |
X |
> |
X |
> |
Id |
> |
> |
X |
> |
X |
> |
$ |
< |
< |
< |
X |
< |
Accept |
Parsing Action :
- Both end of the given input string add the $ symbol.
- Now scan the input string from left right until the > is encountered.
- Scan towards left over all the equal precedence until the first left most < is encountered.
- Everything between left most < and right most > is a handle.
- $ on $ means parsing is successful.
Precedence Table For E -> E+E | E*E | E^E | id :
|
+ |
* |
^ |
id |
$ |
+ |
> |
< |
< |
< |
> |
* |
> |
> |
< |
< |
> |
^ |
> |
> |
< |
< |
> |
Id |
> |
> |
> |
X |
> |
$ |
< |
< |
< |
< |
Accept |
Follow Us