SlideShare a Scribd company logo
9
Most read
10
Most read
11
Most read
SHIFT REDUCE PARSER
SUBMITTED BY
TEJVEER SINGH
MCA 2nd Year
SUBMITTED TO
Dr. VANDANA RANA
DEFINITION AND EXPLANATION
Bottom-up parsing is based on the reverse process to top-down.
Instead of expanding successive non-terminals according to
production rules, a current string form is collapsed each time until
the start non-terminal is reached to predict the legal next symbol.
This can be regarded as a series of reductions. This approach is also
known as shift-reduce parsing.
This is the primary parsing method for many compilers, mainly
because of its speed and the tools which automatically generate a
parser based on the grammar.
Shift reduce parser requires mainly two
data structures:
1. A input buffer for storing the input string.
2. A stack for storing and accessing the production rules.
WORKING
Initially, shift-reduce parser is present in the following
configuration
1. Stack contains only the $ symbol.
2. Input buffer contains the input string with $ at its
end.
.
After achieving this configuration,
• The parser stops / halts.
• It reports the successful completion of parsing.
• An error is detected.
• Or stack is left with only the start symbol and the input buffer
becomes empty.
Basic Operations –
• Shift: This involves moving of symbols from input buffer onto the top of
the stack.
• Reduce: The handle appearing on the stack top is
replaced with the appropriate non-terminal symbol.
• Accept: If only start symbol is present in the stack and the
input buffer is empty then, the parsing action is called accept.
When accept action is obtained, it means successful parsing is
done.
• Error: In this situation parser becomes confused.
Since the parser can neither perform shift action nor reduce
action and not even accept action.
Rules To Remember
• If the priority of incoming operator is more than the priority of in stack
operator, then shift action is performed.
It is important to remember the following rules while performing the
shift-reduce action
• If the priority of in stack operator is same or less than the priority of in
stack operator, then reduce action is performed.
Problem-01 Consider the following grammar-
E → E – E
E → E * E
E → id
Parse the input string “ id – id * id “ using a shift-reduce parser.
Solution :- The priority order is: id > * > –
$ id – id * id $ Shift
$ id – id * id $ Reduce E →
id$ E – id * id $
Shift$ E – id * id $ Shift
$ E – id * id $ Reduce E → id
$ E – E * id $
Shift$ E – E * id $ Shift
$ E – E * id $ Reduce
E → id$ E – E * E $ Reduce
E → E * E
Problem 02: – Consider the grammar
S –> S + S
S –> S * S
S –> id
Perform Shift Reduce parsing for input string “id + id + id”.
SOLUTION:-
Problem 03: – Consider the grammar
E –> 2E2
E –> 3E3
E –> 4
Perform Shift Reduce parsing for input string “32423”.
Solution:-
THANK YOU

More Related Content

PPT
Regular expression with DFA
PDF
Operator precedence
PPTX
Stress detection using machine learning and iot
PPTX
Data types in C
PPT
Skin Cancer
PPTX
computer network OSI layer
PPTX
data analysis techniques and statistical softwares
PPT
Bottom - Up Parsing
Regular expression with DFA
Operator precedence
Stress detection using machine learning and iot
Data types in C
Skin Cancer
computer network OSI layer
data analysis techniques and statistical softwares
Bottom - Up Parsing

What's hot (20)

PDF
Bottom up parser
PPTX
Syntax Analysis in Compiler Design
PPTX
Types of Parser
PPTX
Top down parsing
PPTX
Input-Buffering
PPTX
Context free grammar
PPTX
Priority Queue in Data Structure
PPT
Ll(1) Parser in Compilers
PPTX
Operator precedance parsing
PPTX
Ambiguous & Unambiguous Grammar
DOCX
Nonrecursive predictive parsing
PPTX
Process scheduling
PDF
Lexical Analysis - Compiler design
PPTX
serializability in dbms
PPTX
Relationship Among Token, Lexeme & Pattern
PPTX
Stack organization
PDF
LR Parsing
PPT
Parsing
PPT
Chapter 5 -Syntax Directed Translation - Copy.ppt
PPTX
MULTILEVEL QUEUE SCHEDULING
Bottom up parser
Syntax Analysis in Compiler Design
Types of Parser
Top down parsing
Input-Buffering
Context free grammar
Priority Queue in Data Structure
Ll(1) Parser in Compilers
Operator precedance parsing
Ambiguous & Unambiguous Grammar
Nonrecursive predictive parsing
Process scheduling
Lexical Analysis - Compiler design
serializability in dbms
Relationship Among Token, Lexeme & Pattern
Stack organization
LR Parsing
Parsing
Chapter 5 -Syntax Directed Translation - Copy.ppt
MULTILEVEL QUEUE SCHEDULING
Ad

Similar to Shift reduce parser (20)

PPTX
BOTTOM_UP_Parsing techniques_compiler design5.pptx
PPTX
Compiler Design PPT.pptx
PPTX
PL_SQL_1.pptx fvbxcfbhxdfgh .
PDF
Here upload the document SAP ABAP Basic Concepts
PDF
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
PPTX
C Language Part 1
PDF
InterestingUsefulFeaturesDeltaVPIDController.pdf
PPT
Interesting and Useful Features of the DeltaV PID Controller
PPT
intro to c
PPTX
Java chapter 2
PDF
R3 tosrm attach
PPT
C_chap02.ppt Introduction to C Programming Language
PDF
Multihomed Linux router
PPT
Pl sql guide
PDF
Tips Tricks and Little known features in SAP ASE
PDF
Shaping Optimizer's Search Space
PDF
Scaling MySQL Strategies for Developers
PPT
C Intro.ppt
BOTTOM_UP_Parsing techniques_compiler design5.pptx
Compiler Design PPT.pptx
PL_SQL_1.pptx fvbxcfbhxdfgh .
Here upload the document SAP ABAP Basic Concepts
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
C Language Part 1
InterestingUsefulFeaturesDeltaVPIDController.pdf
Interesting and Useful Features of the DeltaV PID Controller
intro to c
Java chapter 2
R3 tosrm attach
C_chap02.ppt Introduction to C Programming Language
Multihomed Linux router
Pl sql guide
Tips Tricks and Little known features in SAP ASE
Shaping Optimizer's Search Space
Scaling MySQL Strategies for Developers
C Intro.ppt
Ad

More from TEJVEER SINGH (13)

PDF
Software engineering lecture notes
PDF
Software testing lecture notes
PPTX
Introduction to cloud computing
PDF
HOW TO DOWNLOAD MICROSOFT WORD IN ANDROID, and How to convert doc file into ...
PDF
Computer graphics unit 4th
PDF
Most Important C language program
PDF
Multi Banking System
PDF
Design principle of pattern recognition system and STATISTICAL PATTERN RECOGN...
PDF
Computer network questions
PPTX
#How to install mongoDB and also setup path
PPTX
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracaleDriver
PPTX
Oracle 10g Installation Guide
PDF
Important dbms practical question
Software engineering lecture notes
Software testing lecture notes
Introduction to cloud computing
HOW TO DOWNLOAD MICROSOFT WORD IN ANDROID, and How to convert doc file into ...
Computer graphics unit 4th
Most Important C language program
Multi Banking System
Design principle of pattern recognition system and STATISTICAL PATTERN RECOGN...
Computer network questions
#How to install mongoDB and also setup path
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracaleDriver
Oracle 10g Installation Guide
Important dbms practical question

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Insiders guide to clinical Medicine.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Classroom Observation Tools for Teachers
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Complications of Minimal Access Surgery at WLH
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Microbial disease of the cardiovascular and lymphatic systems
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Insiders guide to clinical Medicine.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Renaissance Architecture: A Journey from Faith to Humanism
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Classroom Observation Tools for Teachers
STATICS OF THE RIGID BODIES Hibbelers.pdf
Anesthesia in Laparoscopic Surgery in India
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Complications of Minimal Access Surgery at WLH
TR - Agricultural Crops Production NC III.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf

Shift reduce parser

  • 1. SHIFT REDUCE PARSER SUBMITTED BY TEJVEER SINGH MCA 2nd Year SUBMITTED TO Dr. VANDANA RANA
  • 2. DEFINITION AND EXPLANATION Bottom-up parsing is based on the reverse process to top-down. Instead of expanding successive non-terminals according to production rules, a current string form is collapsed each time until the start non-terminal is reached to predict the legal next symbol. This can be regarded as a series of reductions. This approach is also known as shift-reduce parsing. This is the primary parsing method for many compilers, mainly because of its speed and the tools which automatically generate a parser based on the grammar.
  • 3. Shift reduce parser requires mainly two data structures: 1. A input buffer for storing the input string. 2. A stack for storing and accessing the production rules.
  • 4. WORKING Initially, shift-reduce parser is present in the following configuration 1. Stack contains only the $ symbol. 2. Input buffer contains the input string with $ at its end.
  • 5. . After achieving this configuration, • The parser stops / halts. • It reports the successful completion of parsing. • An error is detected. • Or stack is left with only the start symbol and the input buffer becomes empty.
  • 6. Basic Operations – • Shift: This involves moving of symbols from input buffer onto the top of the stack. • Reduce: The handle appearing on the stack top is replaced with the appropriate non-terminal symbol.
  • 7. • Accept: If only start symbol is present in the stack and the input buffer is empty then, the parsing action is called accept. When accept action is obtained, it means successful parsing is done. • Error: In this situation parser becomes confused. Since the parser can neither perform shift action nor reduce action and not even accept action.
  • 8. Rules To Remember • If the priority of incoming operator is more than the priority of in stack operator, then shift action is performed. It is important to remember the following rules while performing the shift-reduce action • If the priority of in stack operator is same or less than the priority of in stack operator, then reduce action is performed.
  • 9. Problem-01 Consider the following grammar- E → E – E E → E * E E → id Parse the input string “ id – id * id “ using a shift-reduce parser. Solution :- The priority order is: id > * > – $ id – id * id $ Shift $ id – id * id $ Reduce E → id$ E – id * id $ Shift$ E – id * id $ Shift $ E – id * id $ Reduce E → id $ E – E * id $ Shift$ E – E * id $ Shift $ E – E * id $ Reduce E → id$ E – E * E $ Reduce E → E * E
  • 10. Problem 02: – Consider the grammar S –> S + S S –> S * S S –> id Perform Shift Reduce parsing for input string “id + id + id”. SOLUTION:-
  • 11. Problem 03: – Consider the grammar E –> 2E2 E –> 3E3 E –> 4 Perform Shift Reduce parsing for input string “32423”. Solution:-