0% found this document useful (0 votes)
18 views38 pages

CAT Short Key Material

The document provides an overview of compiler design, focusing on key concepts such as the role of a compiler, lexical analysis, token specification, and regular expressions. It discusses the various phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, and code generation, along with their respective functions. Additionally, it covers topics like input buffering, finite automata, and the differentiation between tokens, patterns, and lexemes.

Uploaded by

surya.s2710153
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views38 pages

CAT Short Key Material

The document provides an overview of compiler design, focusing on key concepts such as the role of a compiler, lexical analysis, token specification, and regular expressions. It discusses the various phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, and code generation, along with their respective functions. Additionally, it covers topics like input buffering, finite automata, and the differentiation between tokens, patterns, and lexemes.

Uploaded by

surya.s2710153
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

CAT-1 Key Notes

UNIT I INTRODUCTION TO COMPILERS


Q.No Questions
PART A
What is a compiler?
A compiler is a software tool that translates source code written in a high-level
1. programming language into machine code or intermediate code. It processes the code
through several stages, including analysis and optimization, to produce an executable
file.
Point out why is buffering used in lexical analysis?
Buffering is used in lexical analysis to efficiently manage the input stream of
2.
characters from the source code. It allows the lexer to read and process multiple
characters at once, reducing the number of I/O operations and improving performance.
Illustrate diagrammatically how a language is processed.

3.

List out the issues in a lexical analyzer.


• Simpler design is perhaps the most important consideration.
• The separation of lexical analysis from syntax analysis often allows us to
4.
simplify one or the other of these phases.
• Compiler efficiency is improved.
• Compiler portability is enhanced.
Find the differentiate between tokens, patterns, lexeme.
Token – The category or classification of a lexeme (e.g., IDENTIFIER, NUMBER,
KEYWORD).
5. Pattern – The rule or regular expression that defines a token (e.g., [a-zA-Z_][a-zA-Z0-
9_]* for identifiers).
Lexeme – The actual sequence of characters in the source code that matches a pattern
(e.g., sum, x1, while).
List the operations on languages.
Union (L1 ∪ L2) – Combines strings from both languages.
Concatenation (L1 ⋅ L2) – Joins strings from L1 with strings from L2.
Kleene Star (L*) – Allows repetition (zero or more times) of strings in L.
6.
Intersection (L1 ∩ L2) – Common strings in both languages.
Difference (L1 - L2) – Strings in L1 but not in L2.
Complement (~L) – All strings not in L (within a universal set).
Reverse (Lᴿ) – Reverses all strings in L.
Perform regular expression for an identifier and number.
7. Identifier:
A valid identifier starts with a letter (a-z or A-Z) or an underscore (_), followed by
letters, digits (0-9), or underscores.
Regex: [a-zA-Z_][a-zA-Z0-9_]*
Number:
Integer: [-+]?[0-9]+ (Optional sign followed by digits)
Floating-Point: [-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? (Handles decimal and scientific
notation)
Show the various notational shorthands for representing regular expressions.
Union: A | B (Either A or B)
Concatenation: AB (A followed by B)
Kleene Star: A* (Zero or more A)
Kleene Plus: A+ (One or more A)
8.
Optional: A? (Zero or one A)
Character Set: [abc] (Matches a, b, or c)
Range: [a-z] (Matches a to z)
Negation: [^a-z] (Not a to z)
Grouping: (A|B)* (For precedence)
Perform the Regular expression for the language L= {w ε{a,b}/w ends in abb}
The language consists of strings over {a, b} that end with "abb".
Regular Expression:
(a|b)*abb
9.
Explanation:
• (a|b)* → Matches any combination of a and b (including empty string).
• abb → Ensures the string ends with "abb".
Examples of valid strings: abb, aabb, bababb, aaabb, bbabb.
Examine the variouos advantage of having sentinels at the end of each buffer
halves in buffer pairs.
Efficient End Detection – Eliminates explicit end-of-buffer checks.
10. Reduces Overhead – Minimizes boundary condition handling.
Simplifies Logic – Avoids complex buffer switching logic.
Enhances Performance – Speeds up lexical analysis.
Prevents Buffer Overflow – Ensures safe stopping points.
What are the various parts in LEX program?
Definition Section (%{ %}) – Includes header files and macros.
11.
Rules Section (%% between rules) – Contains pattern-action pairs.
User Code Section (%% after rules) – Additional C functions if needed.
Define Lexeme.
A lexeme is the smallest meaningful unit of a language that matches a pattern defined
12.
by a lexical analyzer. It is an actual sequence of characters in the source code that
corresponds to a token.
Write a regular expression to describe a language consist of strings made of
even numbers a and b.
((aa|bb)(aa|bb))|((ab|ba)(ab|ba))
Explanation:
- (aa|bb) matches either "aa" or "bb" (even number of 'a's or 'b's)
13.
- (aa|bb)* matches zero or more occurrences of "(aa|bb)"
- (ab|ba) matches either "ab" or "ba" (alternating 'a's and 'b's)
- (ab|ba)* matches zero or more occurrences of "(ab|ba)"
- | is the OR operator, allowing the language to consist of either even numbers of 'a's
and 'b's or alternating 'a's and 'b's.
Differentiate NFA and DFA.

14.

Draw a transition diagram to represent relational operators.

15.

Q.No Questions
PART-B
Illustrate the various phases of compiler and trace it with the program segment
(position: =initial rate*60)
1. Lexical Analysis (Scanner)
o Breaks source code into tokens (keywords, identifiers, literals, etc.).
o Removes whitespace/comments.
o Output: Token stream.
2. Syntax Analysis (Parser)
o Checks structure against grammar rules.
1. o Builds a parse/syntax tree.
o Detects syntax errors (e.g., missing semicolons).
3. Semantic Analysis
o Validates meaning (e.g., type checking, variable declaration).
o Uses a symbol table to track identifiers.
o Output: Annotated syntax tree.
4. Intermediate Code Generation
o Converts to platform-independent intermediate code (e.g., three-address
code, abstract syntax tree).
oPrepares for optimization.
5. Optimization
o Improves code efficiency (e.g., dead code elimination, loop
optimization).
o Works on intermediate code.
6. Code Generation
o Produces target machine/assembly code.
o Manages memory/registers and hardware-specific details.

• Symbol Table Management: Maintains identifier metadata across phases.


• Error Handling: Integrated throughout to report and recover from issues.
Summarize the concept of token specification.
Token specification defines lexeme patterns using three core concepts:
1. Strings
o Alphabet: Finite set of symbols (e.g., Σ = {a, b}).
o String: Sequence of symbols from an alphabet (e.g., "banana", length =
6).
o Empty String (ε): String of length 0.
2. o Operations:
▪ Prefix/Suffix: Include ε and the string itself (e.g., prefixes of
"abcd": ε, a, ab, abc, abcd).
▪ Proper Prefix/Suffix: Exclude ε and the string itself (e.g., proper
prefixes of "abcd": a, ab, abc).
▪ Substring: Obtained by deleting any prefix/suffix (e.g.,
substrings of "abcd": ε, "bcd", "abc").
2. Language
o A countable set of strings over an alphabet.
o Operations:
▪ Union (L ∪ M): Combines all strings from L or M.
▪ Concatenation (L ⋅ M): Links strings from L to M (e.g.,
{a,b}⋅{c,d} = {ac, ad, bc, bd}).
▪ *Kleene Closure (L)**: Zero or more repetitions of L (includes
ε).
▪ Positive Closure (L⁺): One or more repetitions of L (excludes ε
unless in L).
3. Regular Expression
o A pattern notation to describe languages using operators (union |,
concatenation, Kleene *, and +).
o Recursive Definition:
1. ε: Represents {ε}.
2. Symbol 'a': Represents {a}.
3. Combinations:
▪ r|s (union), rs (concatenation), r* (Kleene
closure), r+ (positive closure).
i) Outline how input buffering can be explained with an example.
Input buffering optimizes source code reading by minimizing disk access through
efficient memory use.
• Purpose: Speed up lexical analysis by reducing frequent disk reads.
• Mechanism: Reads large data blocks (buffers) into memory, allowing the
compiler to process characters from RAM, which is faster than disk.
Buffer Types
1. Single Buffer (Diagram)
o Process: Reads a block into memory; processing halts when the buffer
empties, waiting for the next block.
o Drawback: Inefficient due to intermittent pauses for refills.
2. Double Buffer (Diagram)
o Process: Uses two buffers (A and B). While one is processed, the other
is filled.
o Workflow:
▪ Fill Buffer A → Process A.
▪ When A is half-processed, start filling B.
▪ Seamlessly switch to B once A is exhausted, refilling A during
3.
B’s processing.
o Advantage: Overlaps I/O and processing, eliminating idle time.
Sentinels
• Role: Special markers (e.g., non-printable characters) at buffer ends to signal
termination without constant boundary checks.
• Benefit: Reduces loop overhead by replacing repeated buffer-end checks with a
single sentinel comparison.
ii) Assess the process of token recognition.
• Tokens obtained during lexical analysis are recognized by Finite Automata.
• Finite Automata (FA) is a simple idealized machine that can be used to
recognize patterns within input taken from a character set or alphabet (denoted
as C). The primary task of an FA is to accept or reject an input based on
whether the defined pattern occurs within the input.
• There are two notations for representing Finite Automata. They are:
1. Transition Table
2. Transition Diagram
1. Transition Table
It is a tabular representation that lists all possible transitions for each state and input
symbol combination.
Analyze the role of Lexical Analyzer in detail with necessary examples.
Lexical analysis is the starting phase of the compiler. It gathers modified source code
4. that is written in the form of sentences from the language preprocessor. The lexical
analyzer is responsible for breaking these syntaxes into a series of tokens, by removing
whitespace in the source code.
Terminologies
There are three terminologies-
• Token
• Pattern
• Lexeme
Token: It is a sequence of characters that represents a unit of information in the source
code.
Pattern: The description used by the token is known as a pattern.
Lexeme: A sequence of characters in the source code, as per the matching pattern of a
token, is known as lexeme. It is also called the instance of a token.
The lexical analyzer performs the following tasks-
• The lexical analyzer is responsible for removing the white spaces and
comments from the source program.
• It corresponds to the error messages with the source program.
• It helps to identify the tokens.
• The input characters are read by the lexical analyzer from the source code.
Summarize in detail about how the tokens are specified by the compiler with
suitable example.
Token specification defines lexeme patterns using three core concepts:
Strings
Alphabet: Finite set of symbols (e.g., Σ = {a, b}).
String: Sequence of symbols from an alphabet (e.g., "banana", length = 6).
Empty String (ε): String of length 0.
Operations:
Prefix/Suffix: Include ε and the string itself (e.g., prefixes of "abcd":
ε, a, ab, abc, abcd).
Proper Prefix/Suffix: Exclude ε and the string itself (e.g., proper
prefixes of "abcd": a, ab, abc).
Substring: Obtained by deleting any prefix/suffix (e.g., substrings of
"abcd": ε, "bcd", "abc").
5. Language
A countable set of strings over an alphabet.
Operations:
Union (L ∪ M): Combines all strings from L or M.
Concatenation (L ⋅ M): Links strings from L to M (e.g., {a,b}⋅{c,d}
= {ac, ad, bc, bd}).
*Kleene Closure (L)**: Zero or more repetitions of L (includes ε).
Positive Closure (L⁺): One or more repetitions of L (excludes ε
unless in L).
Regular Expression
o A pattern notation to describe languages using operators (union |,
concatenation, Kleene *, and +).
o Recursive Definition:
4. ε: Represents {ε}.
5. Symbol 'a': Represents {a}.
6. Combinations:
r|s (union), rs (concatenation), r* (Kleene closure), r+ (positive closure).
Construct the minimized DFA for the following expression.
(a | b)* abb.

NFA

6.

DFA
DFA Optimization
Infer how to convert the given NFA to a DFA.

For the given transition diagram we will first construct the transition table.
State 0 1

→q0 q0 q1

q1 {q1, q2} q1

*q2 q2 {q1, q2}


Now we will obtain δ' transition for state q0.
δ'([q0], 0) = [q0]
δ'([q0], 1) = [q1]
The δ' transition for state q1 is obtained as:
δ'([q1], 0) = [q1, q2] (new state generated)
δ'([q1], 1) = [q1]
The δ' transition for state q2 is obtained as:

δ'([q2], 0) = [q2]
7. δ'([q2], 1) = [q1, q2]
Now we will obtain δ' transition on [q1, q2].

δ'([q1, q2], 0) = δ(q1, 0) ∪ δ(q2, 0)


= {q1, q2} ∪ {q2}
= [q1, q2]
δ'([q1, q2], 1) = δ(q1, 1) ∪ δ(q2, 1)
= {q1} ∪ {q1, q2}
= {q1, q2}
= [q1, q2]
The state [q1, q2] is the final state as well because it contains a final state q2. The
transition table for the constructed DFA will be:
State 0 1

→[q0] [q0] [q1]

[q1] [q1, q2] [q1]

*[q2] [q2] [q1, q2]

*[q1, q2] [q1, q2] [q1, q2]

The Transition diagram will be:


Infer how Convert the following Non-Deterministic Finite Automata (NFA) to
Deterministic Finite Automata (DFA)

Transition table for the given Non-Deterministic Finite Automata (NFA) is-

8.

Step-01: Let Q’ be a new set of states of the Deterministic Finite Automata (DFA). Let
T’ be a new transition table of the DFA.
Step-02: Add transitions of start state q0 to the transition table T’

Step-03: New state present in state Q’ is {q0, q1}.


Step-04:
New state present in state Q’ is {q0, q1, q2}.
Add transitions for set of states {q0, q1, q2} to the transition table T’.

Step-05:
Since no new states are left to be added in the transition table T’, so we stop. States
containing q2 as its component are treated as final states of the DFA. Finally,
Transition table for Deterministic Finite Automata (DFA) is

Q.No Questions
PART C
1. Create a Deterministic Finite Automata for the given regular expression. (0+1)* 01
Build an NFA from a regular expression using Thompson's construction.
2.
i)(a/b)* abb (a/b)*.
ii)ab*/ab

UNIT II : SYNTAX ANALYSIS


Q.N
Questions
o
PART A
Define a context free grammar.
A Context-Free Grammar (CFG) is a formal grammar that consists of rules to generate
strings in a language.
A CFG is represented as G = (V, Σ, R, S), where:
1.
• V (Variables/Non-terminals): Symbols that can be replaced (e.g., S, A, B).
• Σ (Terminals): Actual symbols of the language (e.g., a, b, 0, 1).
• R (Rules/Productions): Rewrite rules (e.g., S → aSb | ε).
• S (Start Symbol): The initial symbol from which derivation begins.
Write the basic issues in parsing.
Ambiguity – Multiple parse trees for the same input.
Left Recursion – Causes infinite loops in top-down parsing.
Backtracking – Leads to inefficiency in some parsers.
2.
Efficiency – Optimizing time and space complexity.
Error Handling – Detecting and recovering from syntax errors.
Lookahead – Requires extra symbols to decide parsing steps.
Grammar Complexity – Complicated grammars make parsing difficult.
Explain ambiguous grammar.
A grammar that produces more than one parse tree for some sentence is said to be
3. ambiguous
An ambiguous grammar is one that produces more than one leftmost or rightmost
derivation for the same sentence.
Ex:
E E+E / E*E / id
Write the algorithm for FIRST and FOLLOW.
The FIRST(A) of a non-terminal A is the set of terminals that appear first in any string
4. derived from A.
The FOLLOW(A) of a non-terminal A is the set of terminals that can appear
immediately after A in some derivation.
Apply Elimination of left recursion from the following grammar.
A->Ac/Aad/bd
5. Answer:
A → bd A'
A' → c A' | ad A' | ε
Show the parse tree for the given expression -(id + id )

6.

Draw syntax tree for the expression a=b*-c+b*-c.

7.

Let Σ={ a, b}
Write down the language generated by the following
i) a/b
ii) a*
iii) (a/b)*
iv) (a/b)(a/b)

Given the alphabet Σ = {a, b}, let's analyze the languages generated by each regular
8. expression:
1. a / b
o This denotes either 'a' or 'b'.
o Language: {a, b}
2. a*
o This denotes zero or more occurrences of 'a'.
o Language: {ε, a, aa, aaa, aaaa, ...} (all possible repetitions of 'a',
including the empty string).
3. (a / b)*
o This denotes zero or more occurrences of 'a' or 'b', meaning any string
over {a, b}, including the empty string.
o Language: {ε, a, b, aa, ab, ba, bb, aaa, aab, ...} (all possible strings of any
length over {a, b}).
4. (a / b)(a / b)
o This denotes any two-character string, where each character is either 'a'
or 'b'.
o Language: {aa, ab, ba, bb}
What is meant by handle pruning?
• An Handle of a string is a sub string that matches the right side of production and
9. whose reduction to the nonterminal on the left side of the production represents one
step along the reverse of a rightmost derivation.
• The process of obtaining rightmost derivation in reverse is known as Handle Pruning.
Derive the string and construct a syntax tree for the input string ceaedae using the
grammar
S->SaA|A,
A->AbB|B,
B- >cSd|e

10.

Compute FIRST for all the non-terminals for the following grammar.
S→ (L) | a
L→ L, S | S
11.
Answer:
FIRST(S) = { (, a }
FIRST(L) = { (, a }
Draw the transition diagram for identifier and keyword

12.

Apply Elimination of left recursion for the following grammar


E-->E+T/T
T-->T*F/F
F-->(E)/id
13. Answer:
E → T E'
E' → + T E' | ε
T → F T'
T' → * F T' | ε
F → € | id
What do you mean by a syntax tree?
A syntax tree is a hierarchical tree representation of a program's grammatical structure,
14.
where each node represents a language construct. It is used in parsing to depict the
derivation of a string according to a given grammar.
Write the rules to construct the SLR parsing table.
Writing augmented grammar
LR(0) collection of items to be found
15.
Find FOLLOW of LHS of production
Defining 2 functions: goto[list of terminals] and action[list of non-terminals] in the
parsing table.

Q.N
Questions
o
PART B
Check whether the following grammar can be implemented using predictive parser.
Check whether the string “abfg” is accepted or not using predictive parsing.
A→A
A→aB|Ad
B→bBC|f
C→g

1.
Construct LR (0) parsing table for the grammar. Also assess whether the input
2. string “aabb” is accepted or not.
S→AA
A→aA|b
Analyze and evaluate the leftmost derivation, rightmost derivation, and derivation
tree for the string "aaabbabbba" with respect to the given grammar.
S→aB | bA
A→aS| bAA|a
B→bS | aBB | b

3.
Analyze and evaluate the predictive parsing table for the grammar:
S → (L) | a
L → L, S | S
Then, determine if the string "(a, (a, (a, a)))" will be accepted.
Given Grammar:
1. S → (L) | a
2. L → L, S | S
Step 1: Compute FIRST and FOLLOW Sets

FIRST Sets:
• FIRST(S): { '(', 'a' }
• FIRST(L): { '(', 'a' } (since L → S and FIRST(S) = { '(', 'a' })
4.
FOLLOW Sets:
• FOLLOW(S): { ')', ',', '$' }
• FOLLOW(L): { ')' }
Step 2: Construct the Predictive Parsing Table
Non-Terminal ( a ) , $

S S → (L) S→a - - -

L L→S L→S - L → L, S -
• The table is conflict-free, making it LL(1) valid.

Consider the following grammar


E→E+E
E→E*E
E→id
Perform shift reducing parser for the input string “id1+id2*id3”

5.

Construct stack implementation of shift reduce parsing for the grammar


6. E->E+S
E->E*E
E->( E )
E->id and the input string id1+id2*id3

Construct LR(0) items for this following grammar and draw the transition Representing
transition among CLR items
S→CC
C→cC
C→d

7
Generate SLR Parsing table for the following grammar.
S->Aa|bAc|Bc|bBa
A-> d
B->d

8
Q.N
Questions
o
PART- C
Create a Parsing table for the grammar and find states made by predictive parser on input
“id + id * id” and find FIRST and FOLLOW.
E -> E + T | T
T -> T * F | F
F -> (E)
F-> id
1.
Compose the analysis to determine if the following grammar is LL(1):
S → iEtS | iEtSeS | a
E→b
Additionally, formulate the FIRST and FOLLOW procedures.

2.
UNIT III : INTERMEDIATE CODE GENERATION
Q.N
Questions
o
PART A
Write SDT for Arithmetic and Boolean expressions
Arithmetic
E → E + T { E.val = E₁.val + T.val; }
E → E - T { E.val = E₁.val - T.val; }
E→T { E.val = T.val; }

T → T * F { T.val = T₁.val * F.val; }


T → T / F { T.val = T₁.val / F.val; }
T→F { T.val = F.val; }
1.
F → ( E ) { F.val = E.val; }
F → num { F.val = num.lexval; }

Boolean
E → id { E.val = lookup(id.lexeme); } // Fetch value from symbol table
E → num { E.val = num.lexval; }

B → E RELOP E { B.val = eval_relop(E₁.val, RELOP.op, E₂.val); }


B → ... (other boolean rules as above)
Draw the syntax tree for the assignment statement a := b * -c + b * -c

2.

What do you mean by syntax directed translation scheme?


A syntax-directed translation (SDT) scheme is a context-free grammar augmented with
3.
semantic actions (code snippets) attached to production rules, enabling computation of
attributes (e.g., values, code) during parsing based on the parse tree's structure.
4. Compare syntax tree and parse tree.
List three kinds of intermediate representation.

5.

Design a parse tree for -(id+id)

6.

Illustrate Annotated parse tree?


A parse tree with attributes (e.g., values, types) attached to nodes. Attributes are
computed via semantic rules during parsing.
Example:
For expression 3 + 5 * 2:
7.

8. Examine the difference between synthesized attributes and inherited attributes.


Q.N
Questions
o
PART – B
Classify the types of Syntax Directed Definitions.
Syntax-Directed Definitions (SDDs) in compiler design are classified into two primary
types based on attribute dependencies and evaluation order:
1. S-Attributed Definitions
o Attributes: Use only synthesized attributes (computed from children →
parent).
o Evaluation: Bottom-up (e.g., during LR parsing).
o Example: Arithmetic expressions (e.g., E.val = E₁.val + T.val).
2. L-Attributed Definitions
o Attributes: Use inherited attributes (passed parent → child/siblings) and
synthesized attributes.
o Dependency: Attributes depend only on left siblings or parent (left-to-
right flow).
o Evaluation: Compatible with top-down (LL) and bottom-up (LR)
1. parsing.
o Example: Type checking (decl.inh_type = type; passed to variables).

2. Illustrate Synthesized attributes and inherited attributes.


Produce quadruple, triples and indirect triples for following expression: (x + y) * (y
+ z) + (x + y + z)

3.

Critique the different types of intermediate code representations.


The following are commonly used intermediate representations:
• Postfix notation
• Syntax tree
• Three-address code
1.Postfix notation
• In postfix notation, the operator follows the operand. For example, in the
expression ( a ˆ’ b ) * ( c + d ) + ( a ˆ’ b ), the postfix representation is: Ab – Cd *
Ab - +
2.Syntax tree
• The syntax tree is nothing more than a condensed form of the parse tree. The
4. operator and keyword nodes of the parse tree are moved to their parent, and a
chain of single productions is replaced by single link.
3.Three-address code
• Three address code is a sequence of statements of the form x = y op z. Since a
statement involves no more than three references, it is called a "three-address
statement," and a sequence of such statements is referred to as three-address
code.
• For example, the three-address code for the expression a + b * c + d is:
**T1 = B * C
T2 = A + T2
T3 = T3 + D**
• Sometimes a statement might contain less than three references; but it is still called a
three-address statement.
Implementation:
Quadruples: An intermediate code representation where each instruction is structured as
(operator, operand1, operand2, result), explicitly naming temporary variables for clarity.
Triples: A compact form where instructions are stored as (operator, operand1, operand2),
referencing results by their position (no explicit temporaries).
Indirect Triples: A hybrid approach combining triples with an indirection table (index
list) to enable flexible code reordering during optimization.
Q.N
Questions
o
PART C
Evaluate the representation of Three Address Codes with suitable examples.
There are three different ways to express three address codes:
• Quadruple
• Triples
• Indirect Triples
Quadruple
It is a structure that has four fields: op, arg1, arg2, and result. The operator is denoted by
op, arg1, and arg2 denote the operands, and the result is used to record the outcome of
the expression.
These quadruples play a crucial role in breaking down high-level language statements
into more digestible parts, facilitating compilation-stage analysis and optimization
1. procedures.
Benefits of Quadrule
• For global optimization, it's simple to restructure code.
Drawbacks of Quadrule
• There are a lot of temporary items.
Triples
Instead of using an additional temporary variable to represent a single action, a pointer to
the triple is utilized when a reference to another triple's value is required. As a result, it
only has three fields: op, arg1, and arg2.
Benefits of Triples
• Triples make it easier to analyze and optimize code by disassembling difficult
high-level language constructs into smaller, more manageable parts
Drawbacks of Triples
• Temporaries are difficult to rearrange since they are implicit.
Indirect Triples
This approach employs a pointer to a list of all references to computations that are
created and kept separately. Its usefulness is comparable to quadruple representation,
however, it takes up less space. Temporaries are easy to rearrange since they are implicit.
Benefits of Indirect Triples
• For languages that use dynamic memory allocation and pointer manipulation,
indirect triples are essential for representing complex pointer operations and
memory accesses
Drawbacks of Indirect Triples
• Indirect triples can increase the complexity of the intermediate representation and
optimization phases of the compiler, complicating the design and implementation
of the compiler.

You might also like