cd
cd
ASSIGNMENT
The lexical analyzer (lexer) reads the source code and converts it into tokens like keywords,
identifiers, and symbols.
The syntax analyzer (parser) takes these tokens and checks if they follow the correct
grammar rules of the language.
The lexer checks spelling-level errors, while the parser checks sentence-level structure.
The start and accepting state is the one with even a and b mod 3 = 0.
For each input symbol, you move to a new state based on the current counts of a and b.
SLR (Simple LR) is the easiest and uses Follow sets to decide parsing actions. It may face
more conflicts.
CLR (Canonical LR) is the most powerful and uses detailed lookahead symbols. It’s bigger and
slower.
LALR (Lookahead LR) is a mix. It uses the same states as SLR but improves lookahead to
reduce conflicts.
It's widely used in tools like YACC.
When we declare variables like int x;, the parser uses rules to add x with type int to the
symbol table.
This way, variables and their types are stored during compilation.
if (a < b)
x = y + z;
else
x = y - z;
t1 = a < b
ifFalse t1 goto L1
t2 = y + z
x = t2
goto L2
L1:
t3 = y - z
x = t3
L2:
• Name equivalence: Two types are equal only if they have the same name.
Even if their structure is same, they are not equal unless declared with same name.
• Structure equivalence: Two types are equal if their components or layout are the
same, even if names are different.
• Unordered: No specific order. Searching is slow as you may need to check all entries.
• Ordered: Items are stored in sorted order. Searching is faster but inserting takes time.
• Binary Search Tree (BST): Uses a tree structure. Searching, inserting, and deleting are
efficient (if the tree is balanced).
• For example:
• a = b + c;
• d = b + c;
• Instead of computing b + c twice, DAG computes once and uses it for both a and d.
• Register assignment is giving those variables actual register names (like R1, R2).
• This improves the speed of the program because using registers is faster than
memory.