#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · STEP BY STEP

SLR(1) Parsing Table Generator: LR(0) Items, ACTION/GOTO and Parse Trace

Paste a grammar to get the canonical LR(0) collection and the SLR(1) table.

  • 📦 Canonical LR(0) items
  • 📋 ACTION and GOTO table
  • ⚠️ Shift/reduce conflicts

How to use the SLR(1) Parsing Table Generator

  1. 1. Type the grammarOne rule per line with | between alternatives. The first rule is the start; the tool adds S' → S.
  2. 2. Add an inputOptionally type a string like id * id + id. The tool adds $ at the end.
  3. 3. Read the resultSee item sets with goto moves, FOLLOW sets, the table with any conflicts and the stack trace.

How the SLR(1) table is built

  1. Augment the grammar with S' → S and build the canonical collection of LR(0) item sets using closure and goto.
  2. If A → α • a β is in Ii and goto(Ii, a) = Ij, set ACTION[i, a] = shift j.
  3. If A → α • is in Ii (A ≠ S'), set ACTION[i, b] = reduce A → α for every b in FOLLOW(A).
  4. If S' → S • is in Ii, set ACTION[i, $] = accept. GOTO entries come from goto on non-terminals.

A cell with two actions is a conflict, and the grammar is not SLR(1).

Worked example (Aho–Ullman expression grammar)

For E → E + T | T, T → T * F | F, F → ( E ) | id there are 12 item sets, I0 to I11. FOLLOW(E) = { +, ), $ } and FOLLOW(T) = FOLLOW(F) = { +, *, ), $ }.

I2 holds E → T • and T → T • * F. LR(0) would have a conflict here, but SLR puts the reduce only under FOLLOW(E), which has no *, so ACTION[2, *] = s7 and ACTION[2, +] = r2. Parsing id * id + id takes 14 steps, as in the Dragon Book.

A grammar that is not SLR(1)

S → L = R | R, L → * R | id, R → L. I2 holds S → L • = R and R → L •. Because = is in FOLLOW(R), ACTION[2, =] gets both shift and reduce. The grammar is not ambiguous; it needs the stronger LALR(1) or canonical LR(1) method.

Frequently asked questions

What is the difference between LR(0) and SLR(1)?

Both use the same LR(0) item sets. LR(0) reduces on every input, while SLR(1) reduces only on terminals in FOLLOW(A), which removes many conflicts.

What do s5 and r2 mean?

s5 means shift the token and go to state 5. r2 means reduce by production 2 of the numbered grammar.

How does the trace handle a conflict?

It prefers shift on a shift/reduce conflict, like yacc does, and says so above the trace.

Can I use ε-productions?

Yes. Write ε, eps or # for the empty string. A → • is a complete item, so it reduces on FOLLOW(A).

More free tools

See all free tools