lec2
lec2
User Mode
Mode bit = 1 Resume process
User process System Call
Source
Translator Object
Linker
Loader
Executable
Programming Language Categories
• Machine Language
– Binary coded instructions
• Assembly Language
– Symbolic coded instructions
• Procedural Languages
– procedural statements or arithmetic notation
• Object-oriented Languages
– Combination of objects and procedures
Assembly Language
• When to use
– When speed or size of program is critical
– Hybrid approach
– Hardware Drivers
– Can use specialized instructions
• Disadvantages
– Inherently machine specific
– Architectures may become obsolete
– Lack of programming structure
Assembly …
• Assemblers like a compiler,
– a translator from source code to target code;
– it converts symbolic machine code to binary machine
code, and
– from symbolic data to binary data.
• Linker
– combines one or more program object files and probably some library
objects files into one executable file.
• Loader
– An integrated part of the operating system (which makes
it essentially invisible) which loads the content of an executable code
file into main memory.
Compilers
• Translates high-level language into low-level
instructions
• High-level language: Source code
• Machine-level: Object code
• Changes, including bug fixes, require
recompiling
Compilation Steps
• Preprocessing (#):- modify the source code before it is
compiled.
• translation (compiling):- The modified source code is
compiled into binary object code. This code is not yet
executable
• assembling mnemonics: A mnemonic is a term, symbol or
name used to define or specify a computing function.
• Linking:-the object code is combined with required
supporting code to make an executable program. This step
typically involves adding in any libraries that are required.
Language Components
• The lexical component
– All legal words in the language
– elementary expressions
– Meaning and type
• The syntactical component (Syntax)
– Syntax define the form and structures of legal expressions.
– grammar rules
– separate statements with a semi-colon
– enclose the conditional expression of an IF statement inside
parentheses
– data types and variables must be declared before the first
executable statement
Language components …
• Semantics
– deals with the meaning of the expressions.
– For the programming languages semantic component
defines a course of action to be performed, while
executing a particular (fragment of a) program.
Why semantic and syntax rule?
• The precise description of a programming language is needed
for the translator:
– to analyze of the (source) program, and
– to generate correct and unambiguous code
• Key part of the precise description of any Programming
language is the syntax rules that make up its grammar
• These rules are used in the parsing process.
• The parsing process consists of determining which rule applies
in a particular instance as one traces through the sentence.
Pre-processing.
• Pre-processing is a kind of translation from a
high-level code to some other high-level code.
• Sometime it is used for the translation of object-
oriented (fourth-generation) programming
languages:
– pre-processing translates a source code (say, in C+
+) into the code in some lower-level programming
language (e.g. in C)
– then the compilation of the result is performed
The Compilation Process
Lexical analysis (scanning)
• text of the program is broken down into the smallest
possible meaningful language components (tokens).
• These will consist e.g. number constants, identifiers
(labels, variable names), etc.
–symbol table will be build of the various tokens
used in the program, including the information on
the type of every token
(e.g. comparative token, variable token, etc.)
– Thus, the program text is reduced to the sequence
of tokens.
Lexical analysis … example
#include <stdio.h>
Lexeme Token
int maximum(int x, int y) { Int Keyword
// This will compare 2 maximum Identifier
numbers ( Operator
int Keyword
if (x > y) x Identifier
return x; , Operator
int Keyword
else
Y Identifier
{ ) Operator
return y; { Operator
If Keyword
}
}
Symbol Table
• Symbol table: is a data structure which holds
different information, whether that
information(variable is defined or not).
• Compiler create and maintains symbol table to
keep detail about the following:
• Variable names
• Function name
• Objects
• Classes
• Interfaces
Symbol table … function
• For analysis and synthesis, symbol table is used by
compiler
• It helps to determine the scope resolution
• It helps to determine whether a variable is defined
already or not.
• To add a new name to the table
• To access information associated with a given name
• To add new information with given name
• To delete a name or group of names from table
• Type checking for semantic correctness determination
Symbol table … example
Int var1;
Int prcA()
Var 1 var Int
{ procA Proc Int
Int var2,var3; procB proc int
-----
{int var 4, var 5;
---} Symbol table(procA Symbol table(procB
Int var 6; Var 2 var Int Var 9 var Int
---
Var 3 var Int Var 10 var Int
{--
Int var 7, var 8; Var 6 var int Var 13 var int
--}}
Int procB()
{int var9,var10;
----
Var4 var Int Var 11 var Int
{ Var 5 var Int Var 12 var Int
Int var 11, var 12;
---- Inner scope -1 Inner scope -3
}
Int var 13; Var7 var Int
} Var 8 var Int
Inner scope -2
Syntax analysis.
• Once lexical analysis is complete, the compiler moves to the
syntax analysis stage to parse the result of lexical analysis into
individual productions.
• Most difficult part of compilation process, especially
because of detecting possible syntactical mistakes in
programs.
• Semantic analysis is usually active at the same time.
– It is responsible in particularly for the detecting data types
inconsistencies.
Code generation.
• Memory locations and registers will be
assigned to the various data objects: variables,
arrays, etc.
• The code will be generated for each of the
productions identified during the syntax and
semantic steps
Optimization
• Compiler analyzes code in order to
– Reduce amount of code
– Eliminate repeated operations
– Reorganize parts of the program to execute faster and more efficiently
– Use computer resources more effectively
• Different compilers can produce different results!
Process of Parsing
• Lexical analysis
– Also known as scanning
– Divides the string of input characters into single
elements, tokens, based on strict computer
punctuation
• Syntactic analysis
– Checks for errors in grammar rules
• Semantic parsing
– Determines the meaning of the string
Linking
Object file
Object Executable
file or object Linker
file
module
C library
Linkers… function
• Searches program libraries to find library routines
used by the program
– Library: collection of pre-written functions and
subroutines made available to perform commonly required
activities
• Determines the memory locations that code from
each module will occupy and relocates instructions
by adjusting absolute references
• Resolves references among files
Why Link?
• Construct single executable program from multiple
object code files compiled at different times
• Program can be subdivided into components and
parceled out to different developers
• Example
– Main program and multiple subroutines written and
compiled by different programmers at different times
Loader
• Loads binary files that have been linked into main
memory
• Program is ready for execution
• Determines size of the text and data segments
• Creates a new address space for the program
• Copies program from the executable into the new
address space
• Copies arguments to the stack
• Initializes the machine registers
• Jumps to a startup routine and calls the main
Conclusion
• In this lecture we tried to discuss:
• System programing essential concepts, what is
System programing, what is the d/c b/n Syst
soft and app soft, why we have to learn
system programing? Corner stone of system
programing
• Little introduction to OS