SPCC
SPCC
SPCC
Software
System Software maintains the system resources Application software is built for specific
and gives the path for application software to run. tasks.
Low-level languages are used to write the system While high-level languages are used to
software. write the application software.
Without system software, the system stops and While Without application software system
can’t run. always runs.
System software runs when the system is turned While application software runs as per the
on and stops when the system is turned off. user’s request.
A system software operates the system in the Application software runs in the front end
background until the shutdown of the computer. according to the user’s request.
The system software has no interaction with users. Application software connects an
It serves as an interface between hardware and intermediary between the user and the
the end user. computer.
LOADING -allocates memory location and brings the object program into memory for
execution done by Loader.
LINKING - combines two or more separate object programs and supplies the information
needed to allow references between them – done by Linker.
RELOCATION - modifies the object program so that it can be loaded at an address different
from the location originally specified – by Linking Loader.
Lexical Analysis is the first phase when compiler scans the source code. This process can
be left to right, character by character, and group these characters into tokens. Here, the
character stream from the source program is grouped in meaningful sequences by
identifying the tokens. It makes the entry of the corresponding tickets into the symbol table
and passes that token to next phase.
The primary functions of this phase are:
● Identify the lexical units in a source code.
● Classify lexical units into classes like constants, reserved words, and enter them in
different tables. It will Ignore comments in the source program
● Identify token which is not a part of the language
Syntax analysis is all about discovering structure in code. It determines whether or not a text
follows the expected format. The main aim of this phase is to make sure that the source
code was written by the programmer is correct or not. Syntax analysis is based on the rules
based on the specific programing language by constructing the parse tree with the help of
tokens. It also determines the structure of source language and grammar or syntax of
the language.
Here, is a list of tasks performed in this phase:
● Obtain tokens from the lexical analyzer
● Checks if the expression is syntactically correct or not
● Report all syntax errors
● Construct a hierarchical structure which is known as a parse tree
Semantic analysis checks the semantic consistency of the code. It uses the syntax tree of
the previous phase along with the symbol table to verify that the given source code is
semantically consistent. It also checks whether the code is conveying an appropriate
meaning. Semantic Analyzer will check for Type mismatches, incompatible operands, a
function called with improper arguments, an undeclared variable, etc.
Functions of Semantic analyses phase are:
● Helps you to store type information gathered and save it in symbol table or
syntax tree
● Allows you to perform type checking In the case of type mismatch, where there are
no exact type correction rules which satisfy the desired operation a semantic error is
shown
● Collects type information and checks for type compatibility
● Checks if the source language permits the operands or not
Once the semantic analysis phase is over the compiler, generates intermediate code for the
target machine. It represents a program for some abstract machine. Intermediate code is
between the high-level and machine level language. This intermediate code needs to be
generated in such a manner that makes it easy to translate it into the target machine code.
Functions on Intermediate Code generation:
● It should be generated from the semantic representation of the source program
● Holds the values computed during the process of translation
● Helps you to translate the intermediate code into target language
● Allows you to maintain precedence ordering of the source language
● It holds the correct number of operands of the instruction
Phase 5: Code Optimization
Therefore, all the memory locations and registers are also selected
and allotted during this phase. The code generated by this phase is
executed to take inputs
Types of Intermediate Code Generation?
Intermediate code can translate the source program into the machine program.
Intermediate code is generated because the compiler can’t generate machine code
directly in one pass. Therefore, first, it converts the source program into
The intermediate code can be represented in the form of postfix notation, syntax
tree, directed acyclic graph, three address codes, Quadruples, and triples.
If it can divide the compiler stages into two parts, i.e., Front end & Back end, then
which there will be at most three addresses, i.e., two for operands & one
for Result. Each instruction has at most one operator on the right-hand
side.
Example
Example
applicable to use a record structure with fields, first hold the operator ‘op’,
next two hold operands 1 and 2 respectively, and the last one holds the
representation.
Triples representation − The contents of operand 1, operand 2, and result
fields are generally pointer to symbol records for the names defined by
Types of Optimization
A) Constant Folding
In this technique, As the name suggests, it involves folding the constants. The expressions
that contain the operands having constant values at compile time are evaluated.
Those expressions are then replaced with their respective results.
Example-
Circumference of Circle = (22/7) x Diameter
Here, This technique evaluates the expression 22/7 at compile time. The expression is then
replaced with its result 3.14. This saves the time at run time.
Constant Propagation- In this technique, If some variable has been assigned some
constant value, then it replaces that variable with its constant value in the further program
during compilation.
The condition is that the value of variable must not get alter in between.
Example-
pi = 3.14
radius = 10
Here,
This technique substitutes the value of variables ‘pi’ and ‘radius’ at compile time.
The expression that has been already computed before and appears
again in the code for computation is called as Common
Sub-Expression.
In this technique,
3. Code Movement-
In this technique, As the name suggests, it involves movement of the code. The code
present inside the loop is moved out if it does not matter whether it is present inside or
outside.
Such a code unnecessarily gets execute again and again with each iteration of the loop. This
leads to the wastage of time at run time.
Example:
In this technique,
This technique replaces the expensive and costly operators with the
simple and cheaper ones.
pass1
Pass2
DLL(Direct linking ,loader)
Differentiate between Synthesized Attributes and inherited Attributes
7.
2. Target program:
The target program is the output of the code generator. The output can be:
3. Memory management
○ During code generation process the symbol table entries have to be mapped
to actual p addresses and levels have to be mapped to instruction address.
○ Local variables are stack allocation in the activation record while global
variables are in static area.
4. Instruction selection:
○ The quality of the generated code can be determined by its speed and size.
Example:
1. a:= b + c
2. d:= a + e
1. MOV b, R0 R0→b
2. ADD c, R0 R0 c + R0
3. MOV R0, a a → R0
4. MOV a, R0 R0→ a
5. ADD e, R0 R0 → e + R0
6. MOV R0, d d → R0
5. Register allocation
Register can be accessed faster than memory. The instructions involving operands in
register are shorter and faster than those involving in memory operand.
Register allocation: In register allocation, we select the set of variables that will
reside in register.
Certain machine requires even-odd pairs of registers for some operands and result.
For example:
Where,
y is the divisor
6. Evaluation order
The efficiency of the target code can be affected by the order in which the
computations are performed. Some computation orders need fewer registers to hold
results of intermediate than others.
It is a parsing strategy that first looks at It is a parsing strategy that first looks at
the highest level of the parse tree and the lowest level of the parse tree and
works down the parse tree by using the works up the parse tree by using the
rules of grammar. rules of grammar.
This parsing technique uses Left Most This parsing technique uses Right Most
Derivation. Derivation.
The main leftmost decision is to select The main decision is to select when to
what production rule to use in order to use a production rule to reduce the
construct the string. string to get the starting symbol.
○ It is used to produce the source code of the syntactic analyzer of the language
produced by LALR (1) grammar.
○ The input of YACC is the rule or grammar and the output is a C program.
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
of (.exe). output.
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
code. the entire code.
Execution of the program takes place only Execution of the program happens after
after the whole program is compiled. every line is checked or evaluated.
Compilers more often take a large amount of In comparison, Interpreters take less time for
time for analyzing the source code. analyzing the source code.
CPU utilization is more in the case of a CPU utilization is less in the case of a
Compiler. Compiler.