ACD key points
ACD key points
Interpreter Compiler
Interpreters usually take less amount of Compilers usually take a large amount
time to analyze the source code. of time to analyze the source code.
However, the overall execution time is However, the overall execution time is
comparatively slower than compilers. comparatively faster than interpreters.
First and Follow sets are needed so that the parser can properly apply the needed production
rule at the correct position.
Rule-02:
Rule-03:
For a production rule X → Y1Y2Y3,
Calculating First(X)
If ∈ ∉ First(Y1), then First(X) = First(Y1)
If ∈ ∈ First(Y1), then First(X) = { First(Y1) – ∈ } ∪ First(Y2Y3)
Calculating First(Y2Y3)
If ∈ ∉ First(Y2), then First(Y2Y3) = First(Y2)
If ∈ ∈ First(Y2), then First(Y2Y3) = { First(Y2) – ∈ } ∪ First(Y3)
Similarly, we can make expansion for any production rule X → Y1Y2Y3…..Yn.
Follow Function-
Follow(α) is a set of terminal symbols that appear immediately to the right of α.
Rule-02:
Rule-03:
Calculate the first and follow functions for the given grammar-
S → aBDh
B → cC
C → bC / ∈
D → EF
E→g/∈
F→f/∈
First Functions-
First(S) = { a }
First(B) = { c }
First(C) = { b , ∈ }
First(E) = { g , ∈ }
First(F) = { f , ∈ }
Follow Functions-
Follow(S) = { $ }
Follow(B) = { First(D) – ∈ } ∪ First(h) = { g , f , h }
Follow(C) = Follow(B) = { g , f , h }
Follow(D) = First(h) = { h }
Follow(E) = { First(F) – ∈ } ∪ Follow(D) = { f , h }
Follow(F) = Follow(D) = { h }
3.Differentiate between SLR, LALR and CLR parsers
It is very easy and cheap It is also easy and cheap to It is expensive and
to implement. implement. difficult to implement.
1. Final State
2. Empty Stack
n-tuples
A)7
7. Single-pass Compiler :
Advantage:
More effective than multi-pass compilers in the compiler point of
view.
Disadvantage:
It compiles less efficient programs.
a)Syntax Errors
To left factor a grammar, you can eliminate any common prefixes of symbols on
the right-hand side of the production for each nonterminal. Here's an example:
Before left factoring: S ⇒ aX, S ⇒ aY, and S ⇒ aZ
After left factoring: S ⇒ aA', A' ⇒ AB / Bc / Ac
In this example, the productions S ⇒ aX, S ⇒ aY, and S ⇒ aZ have the same non-
Problem-01:
S → iEtS / iEtSeS / a
E→b
Solution-
Problem-02:
Solution-
Step-01:
S → bSS’ / a
S’ → SaaS / SaSb / b
Again, this is a grammar with common prefixes.
Step-02:
S → bSS’ / a
S’ → SaA / b
A → aS / Sb
This is a left factored grammar.