SPCC
SPCC
LCLC+L
Evaluate both,reglster
expresslons and Inser A
sinto 2nd byte
EVAL Prnt listing
Evaluateregister and PRINT
Indexexpressions and
Punch assambled insert into 2nd byte
Instruction
PUNCH
Caloulate effootlve
address (EA) of
operand
Print assombly tisting line Generate literale
PRINT Detomine appropnate for entries In
dlsplaoement and LIteral Table
base
Q6 Enlist The Different Types Of Errors That Are Handled By Pass I and Pass II Of Assembler.
Errors handled by Pass I:
Pass I detects syntax errors such as invalid mnemonics, missing operands, or incorrect usage of
assembler directives. Example: ADD AX, BX, CX (Invalid syntax due to too many operands for the ADD
instruction). Pass I detects references to symbols (labels, variables, constants) that are not defined in the
source code. Example: MOV AX, VAR (Where VAR is not defined anywhere in the source code).
Pass I detects duplicate label definitions within the same scope. Example:
LABEL: ; First occurrence of LABEL
LABEL: ; Second occurrence of LABEL
Incorrect Usage of Assembler Directives:
Pass I verifies the correct usage of assembler directives and flags errors if they are used incorrectly.
Example: ORG A (Where A is not a valid memory address).
Pass I calculates addresses and updates the location counter. It may detect errors related to
incorrect address calculations. Example: Miscalculating the memory address while processing ORG
Errors handled by Pass II:
Pass II revisits the source code and attempts to resolve previously undefined symbols using the symbol
table generated in Pass I. Example: MOV AX, VAR Pass II handles errors related to the processing of
literals, such as undefined or incorrectly formatted literals. Example: Undefined literals referenced in
the source code. Pass II resolves symbolic addresses using the symbol table. It may detect errors related
to incorrect address resolution. Example: Inaccurate address resolution resulting in incorrect machine
code generation. Pass II handles errors related to unresolved external symbols, typically encountered in
programs using external libraries or modules. Example: References to symbols defined in external
modules without proper linkage.
Q3 Short Note On Syntax Directed Translation.
Syntax-directed translation is a technique used in compiler design to associate semantic actions
with the production rules of a grammar. It integrates syntax analysis and semantic processing by
embedding translation rules directly into the grammar definition. These translation rules specify
how to generate intermediate representations or perform computations while parsing the input.
Key Aspects of Syntax-Directed Translation:
Integration of Syntax and Semantics:Syntax-directed translation tightly couples syntax analysis with
semantic actions.
Translation Schemes:Translation schemes are extended context-free grammars (CFGs) augmented
with semantic actions. They define the translation process by associating actions with grammar
productions.
Attributes:Attributes are variables associated with non-terminal symbols in the grammar. They
represent properties or values computed during parsing and used in semantic actions.
Syntax-Directed Definition:A syntax-directed definition (SDD) specifies the translation process using a
set of translation rules associated with grammar productions.
Advantages of Syntax-Directed Translation:
Modularity: Syntax-directed translation promotes modularity by separating semantic actions from the
parsing logic. Each production rule encapsulates a specific translation rule, facilitating code
organization and maintenance.
Flexibility: Semantic actions in syntax-directed translation provide flexibility to perform various
transformations or computations during parsing. This enables the integration of optimization
techniques and the generation of intermediate representations.
Ease of Implementation: Syntax-directed translation simplifies the implementation of compilers by
integrating syntax analysis and semantic processing into a unified framework. It provides a clear and
structured approach to specifying translation rules.
Q5 Compare Between Compiler And Interpreter.
Compiler Interpreter
The compiler saves the Machine Language in The Interpreter does not save the Machine
form of Machine Code on disks. Language.
Compiled codes run faster than Interpreter. Interpreted codes run slower than Compiler.
Linking-Loading Model is the basic working The Interpretation Model is the basic working
model of the Compiler. model of the Interpreter.
The compiler generates an output in the form The interpreter does not generate any output.
of (.exe).
Any change in the source program after the Any change in the source program during the
compilation requires recompiling the entire translation does not require retranslation of the
code. entire code.
Errors are displayed in Compiler after Errors are displayed in every single line.
Compiling together at the current time.
It does not require source code for later It requires source code for later execution.
execution.
CPU utilization is more in the case of a CPU utilization is less in the case of a Interpreter.
Compiler.
Object code is permanently saved for future No object code is saved for future use.
use.
C, C++, C#, etc are programming languages Python, Ruby, Perl, SNOBOL, MATLAB, etc are
that are compiler-based. programming languages that are interpreter-
based.
Q1 What Are The Different Ways Of Representing Intermediate Code, Explain With Example.
Intermediate code serves as an intermediate representation (IR) of a program during the
compilation process. It is a platform-independent representation that facilitates optimization and
code generation. There are several ways of representing intermediate code, each with its own
advantages and use cases. Here are some common methods:
Three-Address Code (TAC):
Description: Three-address code represents each operation with at most three operands. It is a linear
representation of code with explicit instructions for each operation. Example:
t1 = a + b t2 = c * t1
Advantages:
Simple and easy to understand. Supports common optimization techniques.
Quadruples:
Description: Quadruples are similar to TAC but use a tuple-like representation with four fields:
operator, operand1, operand2, and result. Example:
('+', 'a', 'b', 't1')
('*', 'c', 't1', 't2')
Advantages:Compact representation.Enables easy manipulation during optimization.
Static Single Assignment (SSA) Form:
Description: SSA form assigns a unique version number to each variable assignment. It
ensures that each variable is assigned only once per scope. Example:t1 = a + b t2 = c * t1
Advantages:Facilitates certain optimization techniques like common subexpression
elimination and constant propagation. Simplifies data-flow analysis.
Abstract Syntax Tree (AST):
Description: AST represents the hierarchical structure of a program's syntax. Each node
in the tree corresponds to a syntactic construct, and the edges represent the
relationships between them.
Advantages: Preserves the hierarchical structure of the program. Supports semantic
analysis and code generation. Example:
Flow Graph:
1 2 3 4 5 6 7
| | | | | | |
V V V V V V V
+----+ +----+ +----+ +----+ +----+ +----+ +----
+
| BB1 | -->| BB2| -->| BB3 | -->| BB4 | -->| BB5 | -->| BB6 | -->| BB7 |