SLR(1) Parsing Table for the Expression Grammar E→E+T∣T,  T→T∗F∣F,  F→(E)∣idE \rightarrow E+T \mid T,\; T \rightarrow T*F \mid F,\; F \rightarrow (E)\mid id

SLR(1) Parsing Table for the Expression Grammar E→E+T∣T,  T→T∗F∣F,  F→(E)∣idE \rightarrow E+T \mid T,\; T \rightarrow T*F \mid F,\; F \rightarrow (E)\mid id

Verified Sources
Nov 4, 2026

We build an SLR(1) parsing table for the grammar:

E→E+T∣TT→T∗F∣FF→(E)∣id\begin{aligned} E &\rightarrow E + T \mid T\\ T &\rightarrow T * F \mid F\\ F &\rightarrow (E)\mid id \end{aligned}

using the standard SLR(1) method:

  • construct LR(0) item sets via closure and goto;
  • compute FOLLOW sets using FOLLOW;
  • add reduce actions only on terminals in FOLLOW of the reduced nonterminal, using SLR(1) rule.

Key symbols/terminals: \{id,+,*,(,),\}wherewhere$ $ is end-marker.

Note (Augmented grammar). For LR parsing we first add a new start production: S′→E.S' \rightarrow E. We then compute item sets for this augmented grammar.

SLR Parsing (LR(0) + FOLLOW) - Intuitive walkthrough

Important keyword definitions (used throughout)

  • LR(0) item
  • closure
  • goto
  • FOLLOW
  • SLR(1) parsing table

Compute FOLLOW sets

  1. 1
    Step 1

    Terminals: \{id,+,*,(,),\}.StartsymbolforFOLLOW:. Start symbol for FOLLOW: E(because(becauseS'\rightarrow E$).

  2. 2
    Step 2

    From E→E+TE\rightarrow E+T: add ++ to FOLLOW(E). From F→(E)F\rightarrow (E): add )) to FOLLOW(E). Also, since S′→ES'\rightarrow E, add \ to FOLLOW(E).

  3. 3
    Step 3

    From E→E+TE\rightarrow E+T: add FOLLOW(E) to FOLLOW(T). From T→T∗FT\rightarrow T*F: no direct FOLLOW(T) contribution there; instead, in E→TE\rightarrow T add no new terminals.

  4. 4
    Step 4

    From T→T∗FT\rightarrow T*F: add ∗* to FOLLOW(F). From T→FT\rightarrow F: add FOLLOW(T) to FOLLOW(F).

  5. 5
    Step 5

    "The resulting FOLLOW sets are: FOLLOW(E) = {),+),+,}; FOLLOW(T)= {$),+, }; FOLLOW(F)= {$),+,*,$$}."

    (Displayed neatly below.)

FOLLOW sets (final)

Let \ $ be end-marker.

FOLLOW(E)={ +,  ),  $ }FOLLOW(T)={ +,  ),  $ }FOLLOW(F)={ +,  ∗  ,  ),  $ }\begin{aligned} FOLLOW(E) &= \{\, +,\; ),\; \$ \,\}\\ FOLLOW(T) &= \{\, +,\; ),\; \$ \,\}\\ FOLLOW(F) &= \{\, +,\; *\; ,\; ),\; \$ \,\} \end{aligned}

Check intuition.

  • ++ and )) naturally follow expressions inside (E)(E) or after completing E+TE+T.
  • ∗* follows an FF because T→T∗FT \rightarrow T*F.
  • \ followsfollowsE$ at end of input (accept state).

Construct LR(0) item sets (states) for SLR(1)

  1. 1
    Step 1

    Use S′→ES'\rightarrow E as the start production.

  2. 2
    Step 2

    Place dot before EE then add items for productions of EE and further for symbols after dots.

  3. 3
    Step 3

    For each state IiI_i and each grammar symbol XX that appears right of a dot in some item of IiI_i, compute goto(Ii,X)goto(I_i,X) as the kernel moved one position right, then apply closure.

  4. 4
    Step 4

    This yields a finite number of LR(0) item sets for this grammar.

  5. 5
    Step 5

    These transitions become the GOTO entries and the shift parts of ACTION.

LR(0) states (canonical set enumeration)

We use item notation like A→α⋅βA\rightarrow \alpha\cdot\beta. Let the set of items for each state be:

I0I_0

S′→⋅EE→⋅E+TE→⋅TT→⋅T∗FT→⋅FF→⋅(E)F→⋅id\begin{aligned} S' &\rightarrow \cdot E\\ E &\rightarrow \cdot E + T\\ E &\rightarrow \cdot T\\ T &\rightarrow \cdot T * F\\ T &\rightarrow \cdot F\\ F &\rightarrow \cdot (E)\\ F &\rightarrow \cdot id \end{aligned}

Transitions from I0I_0:

  • on EE to I1I_1
  • on TT to I2I_2
  • on FF to I3I_3
  • on (to( to I_4$
  • on idid to I5I_5

I1I_1

S′→E⋅E→E⋅+T\begin{aligned} S' &\rightarrow E\cdot\\ E &\rightarrow E\cdot + T \end{aligned}

Transitions:

  • on ++ to I6I_6

I2I_2

E→T⋅T→T⋅∗F\begin{aligned} E &\rightarrow T\cdot\\ T &\rightarrow T\cdot * F \end{aligned}

Transitions:

  • on ∗* to I7I_7

I3I_3

T→F⋅\begin{aligned} T &\rightarrow F\cdot \end{aligned}

(no outgoing transitions)

I4I_4

F→(⋅E)E→⋅E+TE→⋅TT→⋅T∗FT→⋅FF→⋅(E)F→⋅id\begin{aligned} F &\rightarrow ( \cdot E)\\ E &\rightarrow \cdot E + T\\ E &\rightarrow \cdot T\\ T &\rightarrow \cdot T * F\\ T &\rightarrow \cdot F\\ F &\rightarrow \cdot (E)\\ F &\rightarrow \cdot id \end{aligned}

Transitions:

  • on EE to I8I_8
  • on TT to I2I_2
  • on FF to I3I_3
  • on (to( to I_4$
  • on idid to I5I_5

I5I_5

F→id⋅\begin{aligned} F &\rightarrow id\cdot \end{aligned}

(no outgoing transitions)

I6I_6

E→E+⋅TT→⋅T∗FT→⋅FF→⋅(E)F→⋅id\begin{aligned} E &\rightarrow E + \cdot T\\ T &\rightarrow \cdot T * F\\ T &\rightarrow \cdot F\\ F &\rightarrow \cdot (E)\\ F &\rightarrow \cdot id \end{aligned}

Transitions:

  • on TT to I9I_9
  • on FF to I3I_3
  • on (to( to I_4$
  • on idid to I5I_5
  • on EE none (already progressed)

I7I_7

T→T∗⋅FF→⋅(E)F→⋅id\begin{aligned} T &\rightarrow T * \cdot F\\ F &\rightarrow \cdot (E)\\ F &\rightarrow \cdot id \end{aligned}

Transitions:

  • on FF to I10I_{10}
  • on (to( to I_4$
  • on idid to I5I_5

I8I_8

F→(E⋅)E→E⋅+T\begin{aligned} F &\rightarrow (E\cdot )\\ E &\rightarrow E\cdot + T \end{aligned}

Transitions:

  • on )) to I11I_{11}
  • on ++ to I6I_6

I9I_9

E→E+T⋅T→T⋅∗F\begin{aligned} E &\rightarrow E + T\cdot\\ T &\rightarrow T\cdot * F \end{aligned}

Transitions:

  • on ∗* to I7I_7

I10I_{10}

T→T∗F⋅\begin{aligned} T &\rightarrow T * F\cdot \end{aligned}

(no outgoing transitions)

I11I_{11}

F→(E)⋅\begin{aligned} F &\rightarrow (E)\cdot \end{aligned}

(no outgoing transitions)

How to place reduce actions in SLR(1)

If a state contains an item like A→α⋅A\rightarrow \alpha\cdot, then for SLR(1) you add reduce by A→αA\rightarrow\alpha on every terminal in FOLLOW(A)FOLLOW(A). This uses FOLLOW to prevent many shift/reduce conflicts that LR(0) would cause.

Fill ACTION and GOTO tables

We use the standard mapping:

  • If an item [a→α⋅aβ][a\rightarrow \alpha\cdot a\beta] exists and goto(Ii,a)=Ijgoto(I_i,a)=I_j (terminal aa), then ACTION[i,a] = shift j.
  • If an item [A→α⋅][A\rightarrow \alpha\cdot] exists and A≠S′A\neq S', then ACTION[i,a] = reduce A→αA\rightarrow\alpha for all a∈FOLLOW(A)a\in FOLLOW(A).
  • If an item [S′→E⋅][S'\rightarrow E\cdot] exists, then ACTION[i,$$$]=accept.

Production numbering (for reduce actions):

  1. E→E+TE\rightarrow E+T
  2. E→TE\rightarrow T
  3. T→T∗FT\rightarrow T*F
  4. T→FT\rightarrow F
  5. F→(E)F\rightarrow (E)
  6. F→idF\rightarrow id

ACTION table (entries: shift s, reduce r# , accept acc)

Terminals order: id,\; +,\; *,\; (,\; ),\; \.

StateACTION on idACTION on +ACTION on *ACTION on (ACTION on )ACTION on $
0s5s4
1s6acc
2r2s7r2r2
3r4r4r4r4
4s5s4
5r6r6r6r6
6s5s4
7s5s4
8s6s11
9r1s7r1r1
10r3r3r3r3
11r5r5r5r5

How to read rows (example).

  • In state I1I_1: item S′→E⋅S'\rightarrow E\cdot gives accept on \ .Also. Also E\rightarrow E\cdot + Tgivesshiftongives shift on+totoI_6$.
  • In state I2I_2: item E→T⋅E\rightarrow T\cdot implies reduce by (2) on terminals in FOLLOW(E)FOLLOW(E); plus we also have T→T⋅∗FT\rightarrow T\cdot * F so shift on ∗*.

GOTO table (nonterminals E,T,FE,T,F)

StateGOTO on EGOTO on TGOTO on F
0123
1
2
3
4823
5
693
710
8
9
10
11

SLR(1) construction workflow

Augment grammar

1

Add S′→ES'\rightarrow E."

Compute LR(0) states

2

Iterate closure+goto to enumerate I0,I1,…I_0, I_1,\dots."

Compute FOLLOW sets

3

Find FOLLOW(E),FOLLOW(T),FOLLOW(F)FOLLOW(E), FOLLOW(T), FOLLOW(F). "

Fill ACTION/GOTO

4

Shifts from transitions; reduces on FOLLOW; accept from S′→E⋅S'\rightarrow E\cdot."

Common pitfalls and edge cases

Knowledge Check

Question 1 of 4
Q1Single choice

In SLR(1), when a state contains an item A→α⋅A\rightarrow \alpha\cdot with A eqS′A\ eq S', where do we place the reduce action A→αA\rightarrow\alpha?