Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the following grammar and calculate the FIRST AND FOLLOW sets for this grammar. These are the Rules for the Calculate FIRST sets that you
Consider the following grammar and calculate the FIRST AND FOLLOW sets for this grammar.
These are the Rules for the Calculate FIRST sets that you should follow:
These are the Rules for calculating FOLLOW sets that you should follow:
Problem I. Parsing. Consider the grammar SAgBC (1) A a A A C B where S, A, B, and C are the non-terminals, S is the start symbol, and a, c, d, e, f, and g are the terninals 1. Calculate the FIRST and FOLLOW sets for this grammar For FIRST sets (a) Do an initialization pass by applying FIRST sets rules I and II (b) Do successive passes, on the grammar rules in the order they are listed and apply to each grammar rule FIRST set rules III, then FIRST set rule IV then FIRST set rule V In your answer, you should show the FIRST sets after each pass. You do not have to use the notation I used in class to indicate the order in which the elements are added to the sets For FOLLOW sets, you should do: (a) Do an initialization pass by applying FOLLOW sets rule I (b) Do one pass on all grammar rules, in the order they are listed, and apply to each grammar rule FOLLOW set rules IV and V (c) Do successive passes on all grammar rules in the order they are listed and apply to each grammar rule FOLLOW set rules II and III until there is no change In your answer, you should show the FOLLOW sets after each pass. You do not have to use the notation I used in class to indicate the order in which the elements are added to the sets Rules for Calculating FIRST sets We use the following 5 rules for calculating FIRST sets for terminals and non-terminals and epsilon I. FIRST(E)-{ } II. FIRST(a) - a for every terminal a 111. If A-> B is a grammar rule, where B is a terminal or non- terminal, then add FIRST(B)-{ } to FIRST(A) If A-> A1 A2 terminal or non-terminal and IV. Ak B is a grammar rule, where B is a FIRST(A1) and FIRST(A2) and FIRST(Ak), then add FIRST(B)-{ } to FIRST(A) V. IfA - A1 A2.. Ak is a grammar rule and FIRST(Al) and E FIRST(A2) and E FIRST(Ak), then add to FIRST(A) Rules for Calculating FOLLOW sets We use the following 5 rules for calculating FIRST sets for terminals and n-terminals and epsilon I. add $to FOLLOW(S) 11. If A-> B is a grammar rule, and B is a non-terminal, add FOLLOW(A) to FOLLOW(B) and B 111. If A-> B Al A2 Ak is a grammar rule, and B is a non-terminal, and 8 FISTAI) e Fi s P e FIRs and E FIRST(A1) and E FIRST(A2) and E FIRST(Ak), then add FOLLOW(A) to FOLLOW(B) iv. If A-> B A1 A2 Ak is a grammar rule, where B is non-terminal and add FIRST(Al)-{ } to FOLLOW(B) If A-) B Al A2 terminal and Ai Ai+1 Ak is a grammar rule, where B is non- FIRST(A1) and E FIRST(A2) and E FIRST(Ak), then add FIRST(Ai+1)-{ } to FOLLOw(B)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started