This document discusses shift reduce parsers. It defines a shift reduce parser as a type of bottom-up parser that generates the parse tree from leaves to root. It works by shifting input symbols onto a stack and reducing symbols on the stack according to production rules until reaching the start symbol with an empty input buffer. The basic operations are shift, reduce, accept, and error. Examples of parsing input strings using sample grammars are provided.
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
Compiler Design PPT.pptx
1. BIRLA INSTITUTE OF TECHNOLOGY
MESRA (JAIPUR CAMPUS)
Compiler Design(CA513)
Shift Reduce Parser
Submitted By –
Samyak Jain (MCA/25014/22)
Abhishek Ahlawat (MCA/25017/22)
Submitted To –
Madhvi Sinha Mam
2. What is Shift Reduce Parser?
• Shift Reduce Parser is a type of Bottom-Up Parser. It
generates the Parse Tree from Leaves to the Root.
• In Shift Reduce Parser, the input string will be reduced to the
starting symbol.
• This parser requires two data structure i.e
An input buffer for storing the input string.
A stack for storing and accessing the production rules.
3. Basic Operations
• Shift :- the current symbol in the input string is pushed to a
stack.
• Reduce :- the symbol in RHS of production rule is replaced by
non-terminal.
• Accept :- if only the start symbol is present in the stack and
input buffer is empty then , the parsing action is called accept.
• Error :- this is the situation in which the parser can neither
perform shift action nor reduce action and not even accept
action.
4. Working
Initially , shift reduce parser is present in the following configuration:
• Stack contain only the $ symbol.
• Input buffer contains the input string with $ at its end.
5. The parser keeps on repeating this cycle until-
•An error is detected.
•Or stack is left with only the start symbol and the input buffer becomes empty.
After achieving this configuration,
•The parser halts.
•It reports the successful completion of parsing.
6. Example 1
Consider the following grammar-
E → E + E
E → a
E → b
Parse the input string a+b
7. Example 2
Consider the following grammar-
E → E – E
E → E x E
E → id
Parse the input string id – id x id