LR(0) vs SLR(1) in Compiler
We discuss LR(0) vs SLR(1) in Compiler in this class.
For Complete YouTube Video: Click Here
The reader should know LR(0) and SLR(1). Click Here.
To know the difference between LR(0) and SLR(1). the reader should understand the follow symbols.
The below parse tree is an example derivation tree for expression grammar.
After completing E * T., we reduce E * T to E.
The symbol that encounters after completion of E is ‘)’.
The symbols encountered after completion of a non-terminal are Follow symbols.
The below diagram shows both LR(0) and SLR(1) parsing tables.
In LR(0), whenever we need to reduce action, we place reduce at all the terminal symbols.
In SLR(1), whenever we need to reduce action, we place only at follow symbols of the reduced non-terminal.
LR(0) blindly placing reduce action without being bothered about the next input symbol.
So we say LR(0) is considering zero lookahead symbols.
In SLR(1), we consider one lookahead symbol.
We reduce action only at follow symbols of the reduced non-terminal.