Construct SLR (1) parsing table for the grammar
1. E → E + T
2. E → T
3. T → T * F
4. T → F
5.F → (E)
6.F → id
Solution
Steps to produce SLR Parsing Table
Computation of FOLLOW
By Rule (1) of FOLLOW
FOLLOW(E) = {$} (1)
Applying Rule (2) FOLLOW
i.e., comparing E → E + T with A → α B β
∴ A = E, α = ε, B = E, β = +T
∵ Since FIRST(β) = FIRST(+T) = {+}which does not contain ε.
∴ Rule (2b)of FOLLOW
FOLLOW(E) = {+} (2)
Applying Rule (3) of FOLLOW
FOLLOW(T) = {FOLLOW(E)} (3)
Rule (2) cannot be applied. As E → T cannot be compared with A → α B β. Applying Rule (3) of FOLLOW
FOLLOW(T) = {FOLLOW(E)} (4)
Applying Rule (2) of FOLLOW
∴ FIRST(β) = FIRST(∗ F) = {*}
Rule (2a)
∴ FOLLOW (T) = {*} (5)
Applying Rule (3) FOLLOW
∴ FOLLOW (F) = {FOLLOW(T)} (6)
Rule (2) cannot be applied. As T → F cannot be compared with A → α B β
Applying Rule (3)
FOLLOW (F) = {FOLLOW(T)} (7)
Applying Rule (2) FOLLOW
∴ FIRST(β) = FIRST()) = { )}
FOLLOW(E) = { )} (8)
Rule (3) cannot be applied.
Rule (2) and (3), both cannot be applied to this production. As they cannot be compared with F → id.
Combining (1) to (8)
FOLLOW(E) = {$} (1)
FOLLOW(E) = {+} (2)
FOLLOW(T) = {FOLLOW(E)} (3)
FOLLOW(T) = {FOLLOW(E)} (4)
FOLLOW (T) = {*} (5)
FOLLOW (F) = {FOLLOW(T)} (6)
FOLLOW (F) = {FOLLOW(T)} (7)
FOLLOW(E) = { )} (8)
∴ From (1), (2)and (8)
FOLLOW(E) = {$, +, )}
From (3), (4), (5), (8)
FOLLOW(T) = {$, +, ),*}
From (6) and (7)
FOLLOW(F) = {$, +, ) *}
Construct the structure of a table in the following way −
- Write down all states I0 to I11(i. e. , 0 to 11) Row-wise.
- Write down the terminal symbols in Action column-wise.
- Write down the non-terminals column-wise in goto column-wise.
Related Articles
- Find FIRST & FOLLOW for the following Grammar\nE → E + T|T\nT → T ∗ F|F\nF → (E)|id
- Find the canonical collection of sets of LR (0) items for Grammar -\nE → E + T\nE → T\nT → T * F\nT → F\nF → (E)\nF → id
- Verifying whether the string id * id + id is accepted by a given grammar using SLR parsing\nConsider the SLR parsing table for the Grammar\nE → E + T\nE → T\nT → T ∗ F\nT → F\nF → (E)\nF → id\nCheck whether the string id * id + id is accepted or not by using the SLR parsing table constructed in the example.
- Indicate whether the following statements are True (T) or False (F).(a) Unicellular organisms have one-celled body. (T/F)(b) Muscle cells branched. (T/F)(c) The basic living unit of an organism is an organ. (T/F)(d) Amoeba has irregular shape. (T/F)
- In the following statements, tick ‘T’ against those which are true, and ‘F’ against those which are false.$(a)$. Sound cannot travel in a vacuum. (T/F)$(b)$. The number of oscillations per second of a vibrating object is called its time period. (T/F)$(c)$. If the amplitude of the vibration is large, the sound is feeble. (T/F)$(d)$. For human ears, the audible range is 20 Hz to 20,000 Hz. (T/F)$(e)$. The lower the frequency of vibration, the higher the pitch. (T/F)$(f)$. An unwanted or unpleasant sound is termed music. (T/F)$(g)$. Noise pollution may cause partial hearing impairment. (T/F)
- Consider the ambiguous grammar.\nE → E + E\nE → E * E\nE → (E)\nE → id\n(a) Construct LR (0) items for above grammar.\n(b) Construct SLR parsing table for grammar.\n(c) Parse the input string id + id * id.
- Mark ‘T’ if the statement is true and ‘F’ if it is false:$(a)$. We can obtain an enlarged and erect image with a convex mirror. $(T/F)$$(b)$. A concave lens always forms a virtual image. $(T/F)$$(c)$. We can obtain a real, enlarged, and inverted image by a concave mirror. $(T/F)$$(d)$. A real image cannot be obtained on a screen. $(T/F)$$(e)$. A concave mirror always forms a real image. $(T/F)$
- Tick True/False against the following statements :Fossil fuels can be made in the laboratory. (T/F)CNG is more polluting fuel than petrol. (T/F)Coke is almost pure form of carbon. (T/F)Coal tar is a mixture of various substances. (T/F)Kerosene is not a fossil fuel. (T/F)
- Write T against true and F against false in the following statements.$(a)$. Like charges attract each other (T/F)$(b)$. A charged glass rod attract a charged plastic straw (T/F)$(c)$. Lightning conductor cannot protect a building from lightning (T/F)$(d)$. Earthquakes can be predicted in advance (T/F)
- Mark (T) If The Statement Is True and (F) If It Is False: (i) Carbon Dioxide Is Released During Photosynthesis. (T/F) (ii) Plants That Synthesize Their Food Are Called Saprotrophs. (T/F)
- Mark 'T' if the statement is true and 'F' if it is false:(a) Digestion of starch starts in the stomach. (T/F)(b) The tongue helps in mixing food with saliva. (T/F)(c) The gall bladder temporarily stores bile. (T/F)(d) The ruminants bring back swallowed grass into their mouths and chew it for some time. (T/F)
- Mark 'T' if the statement is true and 'F' if it is false:(i) During heavy exercise the breathing rate of a person slows down. (T/F)(ii) Plants carry out photosynthesis only during the day and respiration only at night. (T/F)(ii) Frogs breathe through their skins as well as their lungs. (T/F)(iv) The fishes have lungs for respiration. (T/F)(v) The size of the chest cavity increases during inhalation. (T/F)
- Mark ‘T’ if the statement is true and ‘F’ if it is false:(i) Nitric acid turns red litmus blue. (T/F)(ii) Sodium hydroxide turns blue litmus red. {T/F)(iii) Sodium hydroxide and hydrochloric acid neutralise each other and form salt and water. (T/F)(iv) Indicator is a substance which shows different colours in acidic and basic solutions. . (T/F)(v) Tooth decay is caused by the presence of a base. (T/F)
- Pick five objects from the word box given as Fig. 4.1 which are opaque and would sink in water.O S T P L EA T L E E RC O I N A AO N K C F SA E E I W EL L Y L R R
- $F\ +\ V\ -\ E\ =\ 2$ and if $F\ =\ 20$, $V\ =\ 12$,Then find the value of $E$.
Kickstart Your Career
Get certified by completing the course
Get Started