SPCC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Difference Between System Software and Application

Software

System Software Application 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.

It is general-purpose software. While it’s a specific purpose 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.

Example: System software is an operating system, Example: Application software is Photoshop,


etc. VLC player, etc.
System Software programming is more complex Application software programming is simpler
than application software. in comparison to system software.

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.

Application software is dependent on system


System software runs independently. software because they need a set platform
for its functioning.
Different Function of Loaders?
Loader is a system program that loads machine codes of a program into the system
memory. Loading a program involves reading the contents of executable file into memory.
Once loading is complete, the operating system starts the program by passing control to the
loaded program

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.

Different Phases of Compiler?

Phase 1: Lexical Analysis

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

Phase 2: Syntax Analysis

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

Phase 3: Semantic Analysis

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

Phase 4: Intermediate Code Generation

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

The next phase of is code optimization or Intermediate code. This phase


removes unnecessary code line and arranges the sequence of statements
to speed up the execution of the program without wasting resources. The
main goal of this phase is to improve on the intermediate code to
generate a code that runs faster and occupies less space.
The primary functions of this phase are:

It helps you to establish a trade-off between execution and compilation


speed

Improves the running time of the target program

Generates streamlined code still in intermediate representation

Removing unreachable code and getting rid of unused variables

Removing statements which are not altered from the loop

Phase 6: Target Code Generation

Code generation is the last and final phase of a compiler. It gets


inputs from code optimization phases and produces the object code
as a result.

The objective of this phase is to allocate storage and generate


relocatable machine code.

The target language is the machine code.

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

intermediate code, which performs efficient generation of machine code further.

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

this phase comes in between.

Example of Intermediate Code Generation −

​ Three Address Code− These are statements of form c = a op b, i.e., in

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 of three address code for the statement


​ Postfix Notation − In postfix notation, the operator comes after an

operand, i.e., the operator follows an operand.

Example

​ Postfix Notation for the expression (a+b) * (c+d) is ab + cd +*

​ Postfix Notation for the expression (a*b) - (c+d) is ab* + cd + - .

​ Syntax Trees − It is condensed form of parse tree in which leaves are

identifiers and interior node will be operators.

Example

​ Quadruples representation − Records with fields for the operators and

operands can be used to describe three address statements. It is

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

result. This representation of three addresses is called a quadruple

representation.
​ Triples representation − The contents of operand 1, operand 2, and result

fields are generally pointer to symbol records for the names defined by

these fields. Therefore, it is important to introduce temporary names into

the symbol table as they are generated.

Different types of Optimization?

Types of Optimization

Two techniques that falls under compile time evaluation are-

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

Area of circle = pi x radius x radius

Here,

This technique substitutes the value of variables ‘pi’ and ‘radius’ at compile time.

It then evaluates the expression 3.14 x 10 x 10.

The expression is then replaced with its result 314.

This saves the time at run time.

2. Common Sub-Expression Elimination-

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,

As the name suggests, it involves eliminating the common sub


expressions.

The redundant expressions are eliminated to avoid their


re-computation.

The already computed result is used in the further program when


required.
Example

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:

4. Dead Code Elimination-

In this technique,As the name suggests, it involves eliminating the


dead code.The statements of the code which either never
executes or are unreachable or their output is
never used are eliminated.
5. Strength Reduction-

In this technique,

As the name suggests, it involves reducing the strength of expressions.

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

S.NO Synthesized Attributes Inherited Attributes

An attribute is said to be Inherited


An attribute is said to be
attribute if its parse tree node
Synthesized attribute if its parse
1. value is determined by the
tree node value is determined by
attribute value at parent and/or
the attribute value at child nodes.
siblings node.

The production must have


The production must have
2. non-terminal as a symbol in its
non-terminal as its head.
body.

A synthesized attribute at node n A Inherited attribute at node n is


is defined only in terms of defined only in terms of attribute
3.
attribute values at the children of values of n’s parent, n itself, and
n itself. n’s siblings.

It can be evaluated during a single


It can be evaluated during a single
4. top-down and sideways traversal
bottom-up traversal of parse tree.
of parse tree.

Synthesized attributes can be Inherited attributes can’t be


5. contained by both the terminals or contained by both, It is only
non-terminals. contained by non-terminals.
Synthesized attribute is used by
Inherited attribute is used by only
6. both S-attributed SDT and
L-attributed SDT.
L-attributed SDT.

7.

Issues in the design of code generator

In the code generation phase, various issues can arises:

1. Input to the code generator


2. Target program
3. Memory management
4. Instruction selection
5. Register allocation
6. Evaluation order

1. Input to the code generator

○ The input to the code generator contains the intermediate representation of


the source program and the information of the symbol table. The source
program is produced by the front end.
○ Intermediate representation has the several choices:
a) Postfix notation
b) Syntax tree
c) Three address code

○ We assume front end produces low-level intermediate representation i.e.


values of names in it can directly manipulated by the machine instructions.

○ The code generation phase needs complete error-free intermediate code as


an input requires.

2. Target program:
The target program is the output of the code generator. The output can be:

a) Assembly language: It allows subprogram to be separately compiled.

b) Relocatable machine language: It makes the process of code generation easier.

c) Absolute machine language: It can be placed in a fixed location in memory and


can be executed immediately.

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.

○ Mapping name in the source program to address of data is co-operating done


by the front end and code generator.

○ Local variables are stack allocation in the activation record while global
variables are in static area.

4. Instruction selection:

○ Nature of instruction set of the target machine should be complete and


uniform.
○ When you consider the efficiency of target machine then the instruction speed
and machine idioms are important factors.

○ The quality of the generated code can be determined by its speed and size.

Example:

The Three address code is:

1. a:= b + c
2. d:= a + e

Inefficient assembly code is:

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.

The following sub problems arise when we use registers:

Register allocation: In register allocation, we select the set of variables that will
reside in register.

Register assignment: In Register assignment, we pick the register that contains


variable.

Certain machine requires even-odd pairs of registers for some operands and result.

For example:

Consider the following division instruction of the form:


1. D x, y

Where,

x is the dividend even register in even/odd register pair

y is the divisor

Even register is used to hold the reminder.

Old register is used to hold the quotient.

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.

Differentiate between top down parsing and bottom up


parsing

Top-Down Parsing Bottom-Up Parsing

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.

Bottom-up parsing can be defined as an


Top-down parsing attempts to find the left
attempt to reduce the input string to the
most derivations for an input string.
start symbol of a grammar.
In this parsing technique we start
In this parsing technique we start parsing
parsing from the bottom (leaf node of
from the top (start symbol of parse tree) to
the parse tree) to up (the start symbol
down (the leaf node of parse tree) in a
of the parse tree) in a bottom-up
top-down manner.
manner.

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.

Example: Recursive Descent parser. Example: ItsShift Reduce parser.


YACC
○ YACC stands for Yet Another Compiler Compiler.

○ YACC provides a tool to produce a parser for a given grammar.

○ YACC is a program designed to compile a LALR (1) grammar.

○ 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.

These are some points about YACC:

Input: A CFG- file.y

Output: A parser y.tab.c (yacc)

○ The output file "file.output" contains the parsing tables.

○ The file "file.tab.h" contains declarations.

○ The parser called the yyparse ().

○ Parser expects to use a function called yylex () to get tokens


Difference 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
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.

Errors are displayed in Compiler after


Errors are displayed in every single line.
Compiling together at the current time.
The compiler can see code upfront which The Interpreter works by line working of
helps in running the code faster because of Code, that’s why Optimization is a little
performing Optimization. slower compared to Compilers.

It does not require source code for later


It requires source code for later execution.
execution.

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.

The use of Compilers is mostly in


The use of Compilers mostly happens in
Programming and Development
Production Environment.
Environments.

Object code is permanently saved for future


No object code is saved for future use.
use.
Python, Ruby, Perl, SNOBOL, MATLAB, etc
C, C++, C#, etc are programming languages
are programming languages that are
that are compiler-based.
interpreter-based.

You might also like