Compiler-Design-Grammars
Question 1 |
Construct the LL(1) table for the following grammar.
1. Expr → _Expr 2. Expr → (Expr) 3. Expr → Var Expr Tail 4. ExprTail → _Expr 5. ExprTail → λ 6. Var → Id Var Tail 7. VarTail → (Expr) 8. VarTail → λ 9. Goal → Expr$
Theory Explanation. |
Question 2 |
Consider the CFG with {S,A,B} as the non-terminal alphabet, {a,b} as the terminal alphabet, S as the start symbol and the following set of production rules:
S → aB S → bA B → b A → a B → bS A → aS B → aBB A → bAA
Which of the following strings is generated by the grammar?
aaaabb | |
aabbbb | |
aabbab | |
abbbba |
Question 2 Explanation:
The string “aabbab” can be derived by following steps:
S -> aB [Using S --> aB]
-> aaBB [Using B --> aBB]
-> aabB [Using B --> b]
-> aabbS [Using B --> bS]
-> aabbaB [Using S --> aB]
-> aabbab [Using B --> b]
S -> aB [Using S --> aB]
-> aaBB [Using B --> aBB]
-> aabB [Using B --> b]
-> aabbS [Using B --> bS]
-> aabbaB [Using S --> aB]
-> aabbab [Using B --> b]