Question

In: Computer Science

Give the grammar following: E --> E + T | T T --> T* F |...

Give the grammar following:

E --> E + T | T

T --> T* F | F

F --> (E) | id

Eliminating the left recursion rules and getting a non-left recursive equivalent grammar.

Solutions

Expert Solution

Solution:

Given grammar,

E -> E + T | T

T -> T * F | F

F -> (E) | id

Explanation:

=>E, T and F are non terminals and (. ) and id are terminals in the given grammar.

=>Production rules E -> E + T and T -> T * F are left recursive because same non terminal exist on the left side of production rule and exactly left of the right side of production rule.

Removing left recursion:

=>If there is left recursive production rule A -> A | where A is non terminal, and are set of terminals and non terminals so we can write above production rule in non-left recursive form as A -> A', A' -> | A'

So the non-left recursive form of the given grammar is.

E -> TE'

E' -> | +TE'

T -> FT'

T' -> | *FT'

F -> (E) | id

I have explained each and every part with the help of statements attached to the answer above.


Related Solutions

E ::= E + T | T T ::= T * F | F F ::=...
E ::= E + T | T T ::= T * F | F F ::= num | (E) Num ::= 0 | 1 | 2 | 3 | 4 | 5 | . . . . . . . Question: 1 a. Show the Left-most derivation for the expression: 5 * 7 + 6 * (1 + 2). b. Show the Right-most derivation for the expression: 5 * 7 + 6 * (1 + 2).
Consider the following context-free grammar G: E ® T + E ® * T i E...
Consider the following context-free grammar G: E ® T + E ® * T i E ® f i E ® * f + T ® + Questions: (5 points) Compute the Canonical LR(1) Closure set for state I0 for grammar G. (10 points) Compute (draw) the DFA that recognizes the Canonical LR(1) sets of items for grammar G. (5 points) Construct the corresponding Canonical LR(1) parsing table. (10 points) Compute (draw) the DFA for LALR(1). (5 points) Construct LALR(1)...
#1 We are given the grammar rules A ➝ F B E B ➝ A C...
#1 We are given the grammar rules A ➝ F B E B ➝ A C These rules are only some of the rules of a larger grammar G, but we are not given the remaining rules of G. We are told that A is the start symbol of G and that the following holds: {ε, c, d} ⊆ FIRST(C) {ε, e} ⊆ FIRST(E) {ε, f, g} ⊆ FIRST(F) Recall that end of file is denoted EOF. The symbol ⊆...
The position vector F(t) of a moving particle at time t[s] is given by F(t)= e^t...
The position vector F(t) of a moving particle at time t[s] is given by F(t)= e^t sin(t)i-j+e^t cos(t)k a) Calculate the acceleration a(t). b) Find the distance traveled by the particle at time t = 3π/2, if the particle starts its motion at time t = π/2. c) Find the unit tangent vector of this particle at time t = 3π/2. d) Find the curvature of the path of this particle at time t = 3π/2.
Let f(t) =t^2−1 and g(t) =e^t. (a) Graph f(g(t)) and g(f(t)). (b) Which is larger,f(g(5)) or...
Let f(t) =t^2−1 and g(t) =e^t. (a) Graph f(g(t)) and g(f(t)). (b) Which is larger,f(g(5)) or g(f(5))? Justify your answer. (c) Which is larger, (f(g(5)))′or g(f(5))′? Justify your answer.
plot the double sided amplitude and phase spectrum for the following signal. f(t) = e^(-2|t| )
plot the double sided amplitude and phase spectrum for the following signal. f(t) = e^(-2|t| )
F is a position dependent force given by F(x) = -e^-x. Sketch the graphs showing F(t),...
F is a position dependent force given by F(x) = -e^-x. Sketch the graphs showing F(t), v(t), and x(t) for initial velocity of 10m/s, initial position of 100m, and mass = 1kg. Mention all salient points.
Problem 2 Find max, min, point of infliction for a. f(t)=c (e^(-bt)-e^at ) for t≥0 where...
Problem 2 Find max, min, point of infliction for a. f(t)=c (e^(-bt)-e^at ) for t≥0 where a>b>0, c>0 b. f(x)=2x^3+3x^2-12x-7 for -3≤x≤2 c. f(x)=(x+3)/(x^2+7) for -∞≤x≤+∞
What's the Fourier transform of the following equations: 1) f(t)=1/(t^2+a^2) a is a constant 2) e^[-absolute...
What's the Fourier transform of the following equations: 1) f(t)=1/(t^2+a^2) a is a constant 2) e^[-absolute value(t)/a]*cos(b*t) a and b are constants
The forward price of a currency is given by f(S, t) = S e^(r−rf ) (T...
The forward price of a currency is given by f(S, t) = S e^(r−rf ) (T −t) , a) Show that if f(S, t) < S e(r−rf ) (T −t) , then arbitrage profits can be made. Hint: because f(S, t) is “too low” and S is “too high,” today’s arbitrage trades are i) Enter a long position in the forward contract. (That is, agree to buy the foreign currency at time T at the price f(S, t) per unit...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT