Académique Documents
Professionnel Documents
Culture Documents
INTRODUCTION TO SYSTEM
PROGRAMMING
By
A.C.Bhosale
Semantic Gap
Application Execution
Domain Domain
Application PL Execution
Domain Domain Domain
Errors
Interpreter Domain
Application PL Executio
Domain Domain n
Domain
12 SBPCOE ,TE E&TC SPOS 1/1/2018
Language Processing Activities
Program Generation Activities
Program Execution Activities
Specification Gap
m/c
Source Translator language Target
Program Program
program
15 1/1/2018
SBPCOE ,TE E&TC SPOS
A program must be translated before it can be executed.
The translated program may be saved in a file. The saved program may be
executed repeatedly.
PC Mac hine
PC Source
Language
Program
Program
+
Errors +
Data
Data
Language Processor
Errors Errors
i : integer; 1 i int
2 a real
a, b : real; 3 b real
a := b + i; 4 i* real
5 temp real
Note that int i first needed to be converted into real, that is why 4thentry is
added into the table.
Addition of entry 3 and 4, gives entry 5 (temp), which is value b + (i *).
real :=
a b a +
a, b : real b i
24 SBPCOE ,TE E&TC SPOS 1/1/2018
a := b + i
:= := :=
Lexica
l Scanning
Errors Tokens
Symbol Table
Syntax Parsing
Errors
Constants Table
Trees Other tables
Semantic Semantic
Errors Analysis
IC
Memory Allocation
The memory requirement of an identifier is computed from its type,
length and dimensionality and memory is allocated to it.
The address of the memory area is entered in the symbol table.
IC Memory
Allocation
Symbol Table
Constants Table
Other tables
Code
Generation
Target
30 SBPCOE ,TE E&TC SPOS
Progra 1/1/2018
m
Fundamentals of Language Specifica tion
PL Grammars
The lexical and syntactic features of a programming
language are specified by its grammar.
A language L can be considered to be a collection of
valid sentences.
Each sentence can be looked upon as a sequence of
words, and eac h word as a sequence of letters or
graphic symbols acceptable in L.
A language specified in this manner is known as a
formal language.
Example
α= ab, β=axy
L.H.S. R.H.S.
e.g. <article> ::= a | an | the
<Noun> ::= boy | apple
<Noun Phrase> ::= <article> <Noun>
37 SBPCOE ,TE E&TC SPOS 1/1/2018
Derivation, Reduction and Parse
Trees
A grammar G is used for two purposes, to generate
valid strings of LGand to „recognize‟ valid strings of
LG.
The derivation operation helps to generate valid
strings while the reduction operation helps to
recognize valid strings.
A parse tree is used to depict the syntactic structure
of a valid string as it emerges during a sequence of
derivations or reductions.
42 the
SBPCOE ,TE E&TC boy
SPOS ate an apple
1/1/2018
Classification of Grammars
Type-0 grammar (Phrase Structure Grammar)
α ::= β, where both can be strings of Ts and NTs.
But it is not relevant to specification of Prog. Lang.
Type-1 grammar (Context Sensitive Grammar)
α A β ::= α π β,
But it is not relevant to specification of Prog. Lang.
Type-2 grammar (Context Free Grammar)
A ::= π, which can be applied independent of its context.
CFGs are ideally suited for PL specifications.
Type-3 grammar (Linear or Regular Grammar)
A ::= t B | t OR A ::= B t | t
Nesting of constructs or matching of parentheses cannot be
specified using such productions.
43 SBPCOE ,TE E&TC SPOS 1/1/2018
Ambiguity in Grammatic Specification
Assembler Language
Machine Language
Micro - Firmware
programming
Hardware
51 SBPCOE ,TE E&TC SPOS 1/1/2018
Machine code
Machine code:
Use of Constants
The DC statement does not really implement constants
it just initializes memory words to given values.
The values are not protected by the assembler and can
be changed by moving a new value into the memory
word.
In the above example, the value of ONE can be changed
by executing an instruction
MOVEM BREG, ONE
Use of Constants
An Assembly Program can use constants just like HLL, in
two ways – as immediate operands, and as literals.
Use of Constants
2) A literal is an operand with the syntax = '<value>'.
• It differs from a constant because its location cannot be
specified in the assembly program.
• Its value does not change during the execution of the
program.
• It differs from an immediate operand because no
architectural provision is needed to support its use.
Symbol Address
N 103
Symb Addre
ol ss Data Access
-- > Control
N 104
Access
AGAI 113
Symbol Table
N
• Symbol Table:
– This is created during pass 1
– All the labels of the instructions are symbols
– Table has entry for symbol name, address value.
• Forward reference:
– Symbols that are defined in the later part of the
program are called forward referencing.
89
– There
SBPCOE will SPOS
,TE E&TC not be any address value for such symbols
1/1/2018
in the symbol table in pass 1.
Assembler Design
• First pass:
– Scan the code by separating the symbol, mnemonic
op code and operand fields
– Build the symbol table
– Perform LC processing
– Construct intermediate representation
• Second Pass:
– Solves forward references
– Converts the code to the machine code
91 SBPCOE ,TE E&TC SPOS 1/1/2018
Two Pass Assembler
Read from input line
LABEL, OPCODE, OPERAND
Source
program
Intermediate Object
Pass 1 Pass 2
file codes