A bottom-up parsing constructs the parse tree for an input string beginning from the bottom
(the leaves) and moves to work towards the top (the root).
Bottom-up parsing is a parser that reduces the string to the start symbol of the grammar.
CLASSIFICATION OF BOTTOM-UP PARSERS:
BOTTOM UP PARSERS
Shift-Reduce Parsing Operator Precedence Parsing Table Driven LR Parsing
Shift reduce parsing is a process to reduce a string to its grammar start symbol. It uses a stack
to hold the grammar and an input tape to hold the string. Shift reduce parsing performs the
two actions: shift and reduce. This is why it is known as shift-reduce parsing.
Example
Grammar:
1.S → S+S
2.S → S-S
3.S → (S)
4.S → a
Input string: a1-(a2+a3)
Operator precedence grammar is a category in the shift-reduce method of parsing. It is applied to
a class of grammars operators. Operator precedence grammar must have the following two
properties:
a) No RHS of any product has a∈.
b) Two non-terminals must not be adjacent.
c) Operator precedence can only be fixed
between the terminals of the grammar.
There are the three operator precedence relations:
a ⋗ b means that terminal "a" has higher precedence than terminal "b."
a ⋖ b means that terminal "a" has lower priority than terminal "b."
a ≐ b means that the terminal "a" and "b" both have the same precedence.
LR parsing is also a category of Bottom-up parsing. It is generally used to parse the
class of grammars whose size is large. In the LR parsing, "L" stands for scanning of
the input left-to-right, and "R" stands for constructing a rightmost derivation in a
reverse way.
"K“ - Stands for the count of input symbols of the look-ahead that
are used to make many parsing decisions.
“L” - stands for scan operations of Bottom-up parsing left-to-right
“R” - stands for scan right-to-left in Bottom-up parsing.
LR Parsers:
LR(0) SLR( 1 ) CLR ( 1 ) LALR( 1 )
❖LR(0) – It is an efficient bottom-up syntax analysis technique that can be used for a large class of
context-free grammar. This technique is also called LR(0) parsing. 0 stands for no. of input symbols of
lookahead.
❖SLR (1) – It refers to simple LR Parsing. It is same as LR(0) parsing. The only difference is in the
parsing table.To construct SLR (1) parsing table, we use canonical collection of LR (0) item.
❖CLR(0) - It refers to canonical lookahead. CLR parsing uses the canonical collection of LR (1) items to
construct the CLR (1) parsing table. CLR (1) parsing table make more number of states as compared
to the SLR (1) parsing.
❖LALR( 1 ) - It is a type of LR parser that has a similar structure to LR(1) parser but it uses a more
compact parse table. It constructs a table that combines the state transitions of LR(0) and lookaheads
items of LR(1).
compiler design.pdf

compiler design.pdf

  • 2.
    A bottom-up parsingconstructs the parse tree for an input string beginning from the bottom (the leaves) and moves to work towards the top (the root). Bottom-up parsing is a parser that reduces the string to the start symbol of the grammar.
  • 3.
    CLASSIFICATION OF BOTTOM-UPPARSERS: BOTTOM UP PARSERS Shift-Reduce Parsing Operator Precedence Parsing Table Driven LR Parsing
  • 4.
    Shift reduce parsingis a process to reduce a string to its grammar start symbol. It uses a stack to hold the grammar and an input tape to hold the string. Shift reduce parsing performs the two actions: shift and reduce. This is why it is known as shift-reduce parsing. Example Grammar: 1.S → S+S 2.S → S-S 3.S → (S) 4.S → a Input string: a1-(a2+a3)
  • 5.
    Operator precedence grammaris a category in the shift-reduce method of parsing. It is applied to a class of grammars operators. Operator precedence grammar must have the following two properties: a) No RHS of any product has a∈. b) Two non-terminals must not be adjacent. c) Operator precedence can only be fixed between the terminals of the grammar. There are the three operator precedence relations: a ⋗ b means that terminal "a" has higher precedence than terminal "b." a ⋖ b means that terminal "a" has lower priority than terminal "b." a ≐ b means that the terminal "a" and "b" both have the same precedence.
  • 6.
    LR parsing isalso a category of Bottom-up parsing. It is generally used to parse the class of grammars whose size is large. In the LR parsing, "L" stands for scanning of the input left-to-right, and "R" stands for constructing a rightmost derivation in a reverse way. "K“ - Stands for the count of input symbols of the look-ahead that are used to make many parsing decisions. “L” - stands for scan operations of Bottom-up parsing left-to-right “R” - stands for scan right-to-left in Bottom-up parsing.
  • 7.
    LR Parsers: LR(0) SLR(1 ) CLR ( 1 ) LALR( 1 )
  • 8.
    ❖LR(0) – Itis an efficient bottom-up syntax analysis technique that can be used for a large class of context-free grammar. This technique is also called LR(0) parsing. 0 stands for no. of input symbols of lookahead. ❖SLR (1) – It refers to simple LR Parsing. It is same as LR(0) parsing. The only difference is in the parsing table.To construct SLR (1) parsing table, we use canonical collection of LR (0) item. ❖CLR(0) - It refers to canonical lookahead. CLR parsing uses the canonical collection of LR (1) items to construct the CLR (1) parsing table. CLR (1) parsing table make more number of states as compared to the SLR (1) parsing. ❖LALR( 1 ) - It is a type of LR parser that has a similar structure to LR(1) parser but it uses a more compact parse table. It constructs a table that combines the state transitions of LR(0) and lookaheads items of LR(1).