Given the following grammar:
A -> A ; B
A -> B
B -> B , C
B -> C
C -> ( A )
C -> a
rewrite the grammar to avoid left recursion
For the rewritten grammar of question , Compute First, Follow, and nullable.
The given grammar is :
A -> A ; B
A -> B
B -> B , C
B -> C
C -> ( A )
C -> a
The given grammar is converted to the following equivalent grammar without left recursion :
A -> B A '
A ' -> ; B A ' | ε
B -> C B '
B ' -> , C B ' | ε
C -> ( A )
C -> a
The First of all the variables is computed as follows :
First(A) = { ( a }
First(A') = { ; ε }
First(B) = { ( a }
First(B') = { , ε }
First(C) = { ( a }
The Follow of all the variables is computed as follows :
Follow(A) = { $ ) }
Follow(A') = { $ ) }
Follow(B) = { ; $ ) }
Follow(B') = { ; $ ) }
Follow(C) = { , ; $ ) }
The nullable variables refer to the variables which yield ε on 0 or more steps.
The nullable variables are A ' and B ' .
4) Calculate Nullable, FIRST and FOLLOW for nonterminals A and B for the following grammar. A → BAa A → ε B → bBc B → AA please help ASAP
(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...
P2) Given grammar in BNF, answer the following questions (30 points) <stmt-list>→<stmt> | <stmt»; <stmt-list> (a) Rewrite the given grammar into a EBNF (b) Is the given grammar ambiguous? Support your answer to receive the full credit. (c) Given string A-B C-D: B-C-A-D, draw a parsing tree
P2) Given grammar in BNF, answer the following questions (30 points) → |
Question Set 2 1. Given the following grammar dactor>-> ( <expr> ) a) What is the associativity of each of the operators? What is precedence of the operators? Show a leftmost derivation and parse tree for the following sentence: b) c) A-A(B(C A)) d) Rewrite the BNF grammar above to give precedence over and force to be right associative.
Question Set 2 1. Given the following grammar dactor>-> ( <expr> ) a) What is the associativity of each of the operators? What is precedence of the operators? Show a leftmost derivation and parse tree for the following sentence: b) c) A-A(B(C A)) d) Rewrite the BNF grammar above to give precedence over and force to be right associative.
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.
Transform the following left recursive BNF grammar into an equivalent non-left recursive grammar (S and A are nonterminal symbols; S is the start symbol; a and b are terminal symbols): S -> aSb | bAS A -> AaA | bAA | AAa | bAb CAUTION: Make sure ALL left recursion is eliminated.
grammar to remove the indirect left recursion froma 9. Get the algorithm from Aho et al. (2006). Use this algorithm to remove all left recursion from the following grammar: S Aa Bb AAa | Abc c | Sb Bbb
grammar to remove the indirect left recursion froma 9. Get the algorithm from Aho et al. (2006). Use this algorithm to remove all left recursion from the following grammar: S Aa Bb AAa | Abc c | Sb Bbb
Consider the following grammar: A -> aB | b | cBB B -> aB | bA | aBb C -> aaA | b | caB Perform the pairwise disjoint test for the grammar. Rewrite the above grammar so that all grammar rules pass the pairwise disjoint test. Suppose lex() is the lexical analyzer which gets the next lexeme and puts its token code in the global variable nextToken. And suppose the token codes for terminals a, b, and c are...
Given the following grammar, which variables are “nullable”? Explain you answer. S --> abC S --> bbDE S --> GEAA A --> DCaaGb A --> bba A --> FFS B --> bGHS B --> C B --> KAESE C --> GG C --> abbDKaa C --> aabF D --> SGaFFbbb D --> GGCFF D --> HAKFH E --> bbSAAKG E --> KCG E --> H F --> bbbbab F --> SbbFE F --> AKKB G --> CDA G --> (lambda)...