pcd 2 marks university
pcd 2 marks university
ini
CopyEdit
t1 = c * 60
t2 = b + t1
a = t2
7. State prefix, suffix, proper prefix, and proper suffix with an example.
▪ Proper Prefix: a, ab
▪ Proper Suffix: c, bc
• The parser sends token requests and may give feedback for error recovery.
11. State parse tree and construct parse tree for –(id + id).
CopyEdit
()
/\
id id
shell
CopyEdit
%{ Definitions %}
%%
Rules
%%
User code
bash
CopyEdit
19. Express the main idea of NFA and discuss with examples (a/b)*.
• Steps: Write lex program → run lex → compile with C compiler → execute scanner.
go
CopyEdit
:=
/ \
z +
/\
x *
/\
y 130
less
CopyEdit
S → Aa | b
A → Ac | Sd | ε
Solution:
Left recursion in A → Ac | Sd | ε
Remove by:
vbnet
CopyEdit
A → Sd A' | ε
A' → c A' | ε
less
CopyEdit
S → AS | b
A → SA | a
FIRST:
o FIRST(S) = {a, b}
o FIRST(A) = {a, b}
FOLLOW:
o FOLLOW(S) = {$, a, b}
o FOLLOW(A) = {a, b}
4. State the concepts of Predictive parsing.
o It is a top-down parser that does not backtrack and uses FIRST and FOLLOW
sets.
o Panic mode
o Error productions
o Global correction
scss
CopyEdit
less
CopyEdit
A → ab | ac → A → aB
B→b|c
• A grammar is LL(1) if it can be parsed left-to-right (L), with leftmost derivation (L),
using 1 lookahead token.
• LR parsing:
• Example:
o Original: S → aS | b
o Augmented: S' → S
• Canonical LR
nginx
CopyEdit
S → aSbS | bSaS | ε
• Occurs when a variable refers to memory that has been deallocated or changed.
• Direct: A → Aα
• Indirect: A → B, B → Aα
• Tail: A → αA | ε
shell
CopyEdit
%{ Declarations %}
%%
Grammar rules
%%
Supporting C code
•
•
1. List out the two rules for type checking.
o Type Compatibility Rule: Operands in an expression must be compatible.
o Type Conversion Rule: Implicit or explicit conversion must be valid.
15. Translate conditional statement if a < b then 1 else 0 into three-address code.
go
CopyEdit
if a < b goto L1
t := 0
goto L2
L1: t := 1
L2:
8. Liveness of a variable:
o A variable is live at a point if its value is used in the future.
o Calculated by backward analysis using use-def chains.
Finish he he he !!!