ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3149Slr1 Automaton Parsing…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3149

    Compiler Construction

    Progress0 / 32 done
    Topics32
    1Introduction to interpreter and compiler2Structure of a Compiler and its Phases3Lexical Analyzer and Input Buffering4Specifications and Recognitions of Tokens5Regular Expressions and Finite Automata6Transition Table and Transition Graph7Definitions of Grammars, Derivations, and Parse Trees8Ambiguity, Associativity, and Precedence of Operators9Syntax Analysis and Role of the Parser10Eliminating Ambiguity, Left Recursion, and Left Factoring11Top-Down Parsing and Recursive-Descent Parsing12First and Follow Sets13LL(1) Grammars and Non-recursive Predictive Parsing
    14Reductions and Shift-Reduce Parsing15LR Parsing and LR(0) Parsers16LR(0) Automaton and Parsing Table17Shift-Reduce Conflicts
    18Automaton and Parsing Table
    19Automaton and Parsing Table
    20Automaton and Parsing Table21Semantic Analysis and Intermediate Code Generation22Three Address Code23Tasks of Semantic Analyzer and Types of Errors24Type Checking and Environments
    25Implicit vs Explicit26Back Patching and Switch Statements27Storage Organization and Stack Allocation of Space28Heap Management and Optimization
    29Design of a Code Generator30Target Language and Addresses in Target Code31Basic Blocks and Flow Graphs32Optimization of Basic Blocks
    4 min read
    Topic 18 of 32
    Topic Study Note Illustration
    18

    SLR(1) Parsers: Automaton and Parsing Table

    (Exam-ready, simple explanation with steps, diagrams, and examples)

    πŸ“˜ SLR(1) Parsers: Automaton and Parsing Table

    (Exam-ready, simple explanation with steps, diagrams, and examples)


    🧠 1. What is SLR(1) Parser?

    βœ… Definition

    An SLR(1) (Simple LR) parser is a bottom-up parser that uses:

    • LR(0) automaton
    • FOLLOW sets (1-symbol lookahead indirectly)
    • ACTION + GOTO parsing table

    πŸ‘‰ Full form:

    Simple LR (1 lookahead via FOLLOW sets)


    ⭐ Key Idea

    SLR(1) = LR(0) automaton + FOLLOW sets to resolve reduce decisions.


    πŸ“Š 2. Why SLR(1) is Needed?

    LR(0) has problems: ❌ Too many shift-reduce conflicts ❌ No lookahead information

    πŸ‘‰ SLR fixes this using: βœ” FOLLOW sets βœ” Better reduce decisions


    🧠 3. SLR(1) Parser Components

    1. LR(0) Automaton
    2. FOLLOW sets
    3. Parsing Table (ACTION + GOTO)
    4. Stack + Input buffer

    πŸ”§ 4. Construction Steps of SLR(1) Parser


    πŸ”Ή STEP 1: Augment Grammar

    Add new start symbol:

    S' β†’ S
    

    πŸ”Ή STEP 2: Build LR(0) Items

    Create items using:

    • Closure
    • GOTO

    πŸ‘‰ This forms LR(0) automaton


    πŸ”Ή STEP 3: Compute FOLLOW Sets

    Used for reduce decisions


    πŸ”Ή STEP 4: Construct Parsing Table

    Fill ACTION and GOTO tables


    πŸ“Œ 5. Grammar Example

    S β†’ CC
    C β†’ cC | d
    

    πŸ”Ή Step 1: Augmented Grammar

    S' β†’ S
    S β†’ CC
    C β†’ cC | d
    

    πŸ”Ή Step 2: FOLLOW Sets

    FOLLOW(S) = { $ }
    FOLLOW(C) = { c, d, $ }
    

    🧠 6. SLR(1) Parsing Table Rules


    πŸ”Ή 1. SHIFT

    If:

    A β†’ Ξ± β€’ a Ξ²
    

    Then:

    ACTION[i, a] = SHIFT j
    

    πŸ”Ή 2. REDUCE (Important SLR rule)

    If:

    A β†’ Ξ± β€’
    

    Then:

    ACTION[i, a] = REDUCE A β†’ Ξ±
    for all a ∈ FOLLOW(A)
    

    πŸ‘‰ This is the main difference from LR(0)


    πŸ”Ή 3. ACCEPT

    If:

    S' β†’ S β€’
    

    Then:

    ACTION[i, $] = ACCEPT
    

    πŸ”Ή 4. GOTO

    If:

    GOTO(I, A) = j
    

    Then:

    GOTO[i, A] = j
    

    🌳 7. LR(0) Automaton (Used in SLR)

    States are built using:

    • Items
    • Closure
    • GOTO

    πŸ‘‰ Example transitions:

    I0 --c--> I1
    I0 --d--> I2
    I0 --C--> I3
    

    πŸ“Š 8. SLR(1) Parsing Table (Example Format)

    State c d $ S C
    0 S1 S2 3 4
    1 S1 S2 5
    2 R C→d R C→d R C→d
    3 ACC

    Legend:

    • S = Shift
    • R = Reduce
    • ACC = Accept

    πŸ”„ 9. How SLR(1) Parsing Works


    Steps:

    1. Push state 0 on stack

    2. Read input

    3. Use ACTION table:

      • SHIFT β†’ push state
      • REDUCE β†’ pop symbols, push LHS
      • ACCEPT β†’ stop
    4. Use GOTO for transitions


    ⚠️ 10. Advantages of SLR(1)

    βœ” Simple to construct βœ” Uses LR(0) automaton βœ” More powerful than LR(0) βœ” Reduces many conflicts


    ❌ 11. Limitations

    ❌ Still has conflicts in complex grammars ❌ Not as powerful as CLR(1) ❌ Uses FOLLOW sets β†’ sometimes too broad


    βš–οΈ 12. LR(0) vs SLR(1)

    Feature LR(0) SLR(1)
    Lookahead None FOLLOW set
    Conflicts Many Reduced
    Power Weak Medium
    Table Simple Better
    Use Theory Basic parsing

    🎯 13. Important Exam Questions

    πŸ‘‰ Very frequently asked:

    • Define SLR(1) parser
    • Construct SLR parsing table
    • Difference between LR(0) and SLR(1)
    • Why SLR is better than LR(0)
    • Role of FOLLOW in SLR
    • Build LR(0) automaton for SLR

    πŸ“ 14. Short Notes (Quick Revision)

    πŸ”΅ SLR(1)

    • Simple LR parser
    • Uses FOLLOW sets
    • Uses LR(0) automaton

    πŸ”΅ Key Idea

    • Reduce only when next input ∈ FOLLOW(A)

    πŸ”΅ Components

    • LR(0) automaton
    • ACTION table
    • GOTO table

    πŸ“Š 15. Final Summary Table

    Aspect SLR(1) Parser
    Full form Simple LR (1)
    Type Bottom-up
    Basis LR(0) + FOLLOW
    Lookahead 1 (indirect)
    Strength Medium
    Tables ACTION + GOTO
    Conflicts Reduced vs LR(0)
    Use Syntax analysis

    βœ… Final Conclusion

    • SLR(1) parser improves LR(0) using FOLLOW sets
    • It reduces shift-reduce conflicts
    • It is simple but not the most powerful LR method
    • Forms the foundation for understanding CLR and LALR parsing

    ← Previous topic 17
    Shift-Reduce Conflicts
    Next topic 19 β†’
    LR(1) Parsers: Automaton and Parsing Table

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    4mremaining
    611words
    Beginnerlevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Compiler Construction