Question

Cansider following sramam2. No that s de terminal E t T T Compute the first set for all symbas in the slammar Compte the follow set 2th non-taminats in the trammar. plezre sin haw t 9 t follow set? T
1 0
Add a comment Improve this question Transcribed image text
Answer #1

Removed Left Recursive and Left-Factoring from the grammer:-

New Non-Terminals Added are E', T' & X'

Note: e0 used as null production.

Eleminating Left Recursion

E->T+E'

E'->T+E' | e0

Eliminating Left Factoring:-

T->idT'

T'->[X'] | e0

X'->X| e0

X->E , E | E

Symbol First Follow
E id , id $
E' id e0 , id $
T id +
T' [ e0 +
X id ]
X' id e0 ]

Compute First:-

  1. If X is a terminal then First(X) is just X!
  2. If there is a Production X → ε then add ε to first(X)
  3. If there is a Production X → Y1Y2..Yk then add first(Y1Y2..Yk) to first(X)
  4. First(Y1Y2..Yk) is either
    1. First(Y1) (if First(Y1) doesn't contain ε)
    2. OR (if First(Y1) does contain ε) then First (Y1Y2..Yk) is everything in First(Y1) <except for ε > as well as everything in First(Y2..Yk)
    3. If First(Y1) First(Y2)..First(Yk) all contain ε then add ε to First(Y1Y2..Yk) as well.F

Follow

  1. First put $ (the end of input marker) in Follow(S) (S is the start symbol)
  2. If there is a production A → aBb, (where a can be a whole string) then everything in FIRST(b) except for ε is placed in FOLLOW(B).
  3. If there is a production A → aB, then everything in FOLLOW(A) is in FOLLOW(B)
  4. If there is a production A → aBb, where FIRST(b) contains ε, then everything in FOLLOW(A) is in FOLLOW(B)
Add a comment
Know the answer?
Add Answer to:
Consider following note that are terminals. E rightarrow e + t | t t rightarrow ID...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Consider the following context free grammar with terminals (), +, id, num, and starting symbol...

    2. Consider the following context free grammar with terminals (), +, id, num, and starting symbol S. S (ST) F-id Fnum a. Compute the first and follow set of all non-terminals (use recursion or iteration, show all the steps) Show step-by-step (the parsing tree) how the following program is parsed: (num+num+id)) b.

  • Consider the following LL(1) grammar with terminals (, ), +, id, num, and starting symbol S....

    Consider the following LL(1) grammar with terminals (, ), +, id, num, and starting symbol S. Compute the first and follow set of all the nonterminals. S → (ST) F→id

  • (10] Eliminate left recursion from the grammar A Ba |Aa c B Bb | Ab 1...

    (10] Eliminate left recursion from the grammar A Ba |Aa c B Bb | Ab 1 d A Ad IB A BA ASJAE Consider the following grammar G: S'S S (S)S|e fa) (10] Construct the collection of the sets of LR(0) items (b) [5] When constructing the action table of SLR parser of G what are the rules to determine the parsing actions? That is, what is the rule for a shift action at state /? What is the rule...

  • 10 pt) Consider the following grammar where S is the start variable » terminals: x, y,...

    10 pt) Consider the following grammar where S is the start variable » terminals: x, y, z,t,,* non-terminals: El T, F, V * start symbol: E production rules (a) (4 pt) What is the associativity of the operators+,, * and/ explain why. (b) (3 pt) What is the precedence of , and / explain why (c) (3 pt) Given a parse tree F * T 2 2 Explain how the value of the string is generated

  • for compiler design Compster Science epene CS 347 Compiler Design Assiznment 2 Due Date: October 28,...

    for compiler design Compster Science epene CS 347 Compiler Design Assiznment 2 Due Date: October 28, 2018 Exercise 1 Consider the following grammar: cassign expr l <id> a) Show that this grammar is ambiguous. b) Do the necessary changes to make it unambiguous (you should consider that has more priority than -). Exercise 2 Consider the following BNF Grammar: A [B, A] | B B: CI(A; C) D::= a | b | c For each of the strings listed below,...

  • KITES DE INSTALA (2) Given the following grammar, E ::= E + F E ::= F:...

    KITES DE INSTALA (2) Given the following grammar, E ::= E + F E ::= F: := E.id F ::= id in which E and F are non-terminal symbols, a. Fill in the following blanks to construct two leftmost derivations for the sentence id+id.id. (5 points) 80p pgitech E -> E -> b. Is this grammar ambiguous ? (1 point) N v B c iz X

  • Q5: (20 points) Consider the following grammars T → int | float L → L,id I...

    Q5: (20 points) Consider the following grammars T → int | float L → L,id I id a) Perform the pairwise disjointness test for grammar (I). b) Is grammar (I) LL1 grammar? Why? Consider the grammar (II) and the input string "int id, id; ", show the content of the Stack of the Shift-Reduce algorithm. Is it conflict-free and why? c)

  • Question 1. (15 points) Consider the following LL (1) grammar with starting symbol S s→(ST) F...

    Question 1. (15 points) Consider the following LL (1) grammar with starting symbol S s→(ST) F → id F → num a) Compute the First and Follow sets of all non-terminals (5 points) b) Construct the LL (1) parsing table for the grammar (5 points) c) Show step-by-step (content of stack and input string, as well as the production taken) how the following string is parsed: ((20+30 + a)) (5 points)

  • Consider the following BNF grammar that we saw in class:        EXP    ::= EXP + TERM  ...

    Consider the following BNF grammar that we saw in class:        EXP    ::= EXP + TERM   | EXP - TERM    | TERM        TERM   ::= TERM * FACTOR | TERM / FACTOR | FACTOR        FACTOR ::= ( EXP ) | DIGIT        DIGIT ::= 0 | 1 | 2 | 3    (a) Translate into EBNF.    (b) Draw syntax diagrams.    (c) What are the two requirements on a grammar for a predictive parser to be able to...

  • 2. To find a Chomsky normal form for the following grammar (10 points) STR T -...

    2. To find a Chomsky normal form for the following grammar (10 points) STR T - aTbab R RIA first note that we don't need to add a new production S' Sto the grammar because s does not appear on the right hand side of any productions in the grammar. Next, since we have a A-production in the grammar R - A, so we use the technique in question #6 to remove the production. Afterward the grammar becomes SLT TR...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT