fpl - part 1 (sem - i 2013 )

75
Computer (data processor) is a machine which executes the instructions (given by the user) to processes the data (also given by the user) with a very high speed . Computer (Data Processor) Instruction s / Program Data (Raw input) Information (Processed Output) How to process ? What to process ? Program - A sequence of logically connected instructions coded in a particular language to perform a specific task Data : The material on which the program instructions operate Data processing - capturing input data, manipulating data & representing output information Computer

Upload: yogesh-deshpande

Post on 15-May-2015

679 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: FPL - Part 1  (Sem - I  2013 )

Computer (data processor) is a machine which executes the instructions (given by the user) to processes the data (also given by the user) with a very high speed .

Computer(Data Processor)

Instructions /Program

Data (Raw input)

Information (Processed Output)

How to process ?

What to process ?

Program - A sequence of logically connected instructions coded in a particular language to perform a specific task Data : The material on which the program instructions operate Data processing - capturing input data, manipulating data & representing output information

Computer

Page 2: FPL - Part 1  (Sem - I  2013 )

Characteristics of computer

•Automatic - works without human intervention once program and data is fed.

•Speed - High speed processor - billion( 109) or trillion(1012) instructions per seconds (BIPS)

•Accuracy - produces continues accurate results (errors in data / program garbage )

•Diligence - free from monotony , tiredness and lack of concentration

•Versatility - capable of performing any type of task depending on the program given

•Power of remembering - Can store/retain huge amount of program, data and information in a secondary memory and can recall it whenever required

• No IQ - Has no intelligence of its own - can not take its own decision

• NO feelings - Computers are devoid of emotions - judgments only made based on instructions

•Evolution of computer generations 1,2,3,4,5 (Home Work)

Page 3: FPL - Part 1  (Sem - I  2013 )

Input Device

OutputDevice

Processor

Memory

(01001110010101)

Instructions +Data Information

(1) Inputting

(3) Processing - arithmetic & logical operation)

(5) outputting

KeyboardMouse MicrophoneTouch Screen CameraScanner

ScreenPrinter Speaker

Organization

(2) storing (4) retrieving

Page 4: FPL - Part 1  (Sem - I  2013 )

Input Device

OutputDevice

Processor

Primary Memory fast but small in capacity

Organization

Secondary Memory slow but large in capacity

Book Shelf

processing

save load

working desk

Page 5: FPL - Part 1  (Sem - I  2013 )

Secondary memory

Primary Memory

Arithmetic Logic Unit (ALU)

Control Unit (CU)

Input Unit Output Unit

CENTRAL PROCESING UNIT (CPU)

STORAGE UNIT (SU)

encoding using input interfaces

decoding using output interfaces

Program Data

Program Data

calculation and comparisons

coordinates all components

Page 6: FPL - Part 1  (Sem - I  2013 )

Storage Unit

Characteristic Primary / Main Memory Secondary / Auxiliary

Usage Essential for a CPU and processing

Working memory

Not essential for CPU and processing

Non-working memory

Location Mother Board or main circuitry

Peripheral Unit

Speed High Low

Capacity Huge ( GB,TB) Limited (4GB , 8GB)

Storage Temporary Permanent

Storage Volatile Non Volatile

Cost High Cheap

Manufacturing technology Semiconductor devices

Page 7: FPL - Part 1  (Sem - I  2013 )

Binary Storage

0 1 0 1 1 1 1 0 0

1 1 1 0 0 0 0 0 0

1 1 0 0 0 0 0

byte = 8 bits (0)

word = 2 bytes = 16 bits (3,4)

double word = 2 words = 32bits (6,7,8,9)

0

1

2

3

4

5

6

78

9

A

B

Page 8: FPL - Part 1  (Sem - I  2013 )

Types of programming Languages

Machine Level / Code • Contains binary coded instructions from CPUs instruction set • Processor can process them directly without any transformation. - executable • Hardware dependent • Programmer needs to know processor architecture

8B542408 83FA0077 06B80000 0000C383 FA027706 B8010000 00C353BB 01000000 B9010000 008D0419 83FA0376 078BD98B C84AEBF1 5BC3

Assembly Level / Language • Mapping of human readable symbols of machine codes - mnemonics +operands• One to one correspondence between assembly statement and machine code • Is specific to hardware

Page 9: FPL - Part 1  (Sem - I  2013 )

Types of programming languages

High Level Language

• Machine (Processor) independent English like language with high level of abstraction • Closer to natural language , easier to use and more understandable• Non executable •

Page 10: FPL - Part 1  (Sem - I  2013 )

Types of programming Languages

Page 11: FPL - Part 1  (Sem - I  2013 )

Program Development Tools

Page 12: FPL - Part 1  (Sem - I  2013 )

Object Program

Executable Program

Compiling

Source Program

Linking

test.c

test.obj

test.exe

Standard Libraries

object code

Header Files

.LIB

.H

Editing

include

C Programming Development Environment

Page 13: FPL - Part 1  (Sem - I  2013 )

• A high-level programming language interpreted by another program at runtime

• Scripts are tasks written for environment & interpreted at runtime in a batch

• Script requires an interpreter or a virtual machine at run time

• Explicit compilation or linking phases are not needed

• Variables, functions, and methods typically do not require type declarations.

• Source code is present at run time and compiled into native object code.

•JavaScript, ASP, JSP, PHP, Perl, Python

Scripting Language

Page 14: FPL - Part 1  (Sem - I  2013 )

Natural Language

• Programming in terms of natural language sentences, e.g. English

• The smallest unit of statement in NLP is a sentence.

• In an NLP text every sentence compiles into a procedure call in the underlying high level programming language such as MATLAB, Octave, SciLab, Python, etc.

Advantages and limitations of different levels of languages - Home work

Examples - Mathematica. , Wolfram Alpha , Inform7 , Thinknowlogy,

Page 15: FPL - Part 1  (Sem - I  2013 )

Characteristics of a good programming language -1

1. Responsiveness• e.g. excel • Read-evaluation –print –loop (REPL)• there should be less steps between changing code and seeing results • More steps in REPLs destroyed program flow • Small-talk and LISP have powerful REPLs

2. Safety • provided by compilers so that even a smallest error can be detected before

a program is run • Languages data type system is often a source of programming error • Haskell has a powerful type system • Dynamic type setting is risky - you need to run the program

3. Speed • Sometimes we need the compile code that runs fast … • It depends on language and memory layout or structure • Best way to speed up code is to improve the algorithm• C is the fastest high level language

Page 16: FPL - Part 1  (Sem - I  2013 )

Characteristics of a good programming language -1

4. Completeness • A language rich with libraries is preferred

5. Expressiveness • Expressiveness is the ability to reshape the language until you can express your

program naturally.• Lisp and Scheme let you implement a new internal language for describing

your program concisely.• Smalltalk, Ruby and Haskell have basic building blocks and lightweight syntax

that makes it easy to define new language constructs for your particular problem.

• This property is very important because code is to be read by humans first and then computers

Page 17: FPL - Part 1  (Sem - I  2013 )

1. Readability: Should allow programs to be written in ways that

2. Portability: Should be able to develop portable software.

3. Generality: Writing of a wide variety of programs, thus relieving the programmer of the need

to become expert in many diverse languages.

4. Brevity: Ability to implement the algorithm with less amount of code.

5. Error checking:. Error checking both at compile-time and at run-time.

6. Familiar notation: A language should have familiar notation, so it can be understood by most

of the programmers.

7. Quick translation: It should admit quick translation.

8. Efficiency: It should permit the generation of efficient object code.

9. Modularity: It is desirable that programs can be developed in the language as a collection of

separately compiled modules, with appropriate mechanisms for ensuring self-consistency

between these modules.

10 Widely available: Language should be widely available and it should be possible to provide

translators for all the major machines and for all the major operating systems.

A good programming language -2

Page 18: FPL - Part 1  (Sem - I  2013 )

C Programming

Page 19: FPL - Part 1  (Sem - I  2013 )

C Programming Character set - is set of characters used to form constants, variables and expressions

Categories of C character set A. Letters B. DigitsC. Special Characters D. White-spaces

•Letters - A…Z , a…..z• Digits - 0….9• White spaces

• blank• horizontal tab • Carriage return• New line • Form feed

Page 20: FPL - Part 1  (Sem - I  2013 )

C Programming Special Characters

, Comma & Ampersand

. Period ^ Caret

; Semicolon * asterisk

: colon - Minus

? Question mark + Plus

‘ Apostrophe < Opening angle bracket

! Exclamation > Closing angle bracket

| Vertical bar ( left parenthesis

/ Slash ) Right parenthesis

“ Quotation mark \ Back slash

~ Tilde [ Left bracket

_ Underscore ] Right bracket

$ Dollar sign { Left brace

% Percentage sign } Right brace

# Number sign

Page 21: FPL - Part 1  (Sem - I  2013 )

C Tokens

• C language statements are made of tokens

•Tokens are smallest recognizable units of language

• Any C language statement consists of following six types of tokens

1. Keywords - language specific words with special meaning - float , if , int , while ,

2. Identifiers - user defined names of variables , functions etc - main , age , etc …

3. Constant or literals - 12, 57, 38.69, 99.6756,

4. String - ‘A’, ‘ Vishwakarma’

5. Operators - + , - , * , = , ++ , --

6. Special symbol - , [] , {} , %

Example - identify tokens

void main(void)

{

int age = 28 ; clrscr(); printf(“My age is %d”, age);

}

Page 22: FPL - Part 1  (Sem - I  2013 )

auto double int struct

break else long switch

case enum register typedef

char extern return union

const float short unsigned

continue for signed void

default goto sizeof volatile

do if static while

1. Keywords •All keywords have fixed meanings which can not be changed

•Key words are basic building blocks of a statement

Page 23: FPL - Part 1  (Sem - I  2013 )

2. Identifiers • These are names of variables and functions or arrays which are user defined • Contain sequence of letters, digits

Rules of naming identifiers

1. First character must be alphabet2. Must have letters , digits and underscore only 3. Length can be 31 maximum4. Cannot use a keyword5. Must not have any white spaces

Page 24: FPL - Part 1  (Sem - I  2013 )

3. Integer Constants • These are fixed values that do not change

• Integer constants - sequence of digits • Decimal integers - will have 0 to 9 with optional + or -

• 123,567, -45, 0 , 653456 • Octal integers - will have 0 to 7 with optional + or - and with leading zero

• 037 , 0 , 0435 , 0551 • Hexadecimal integers - will have 0 to A with optional + or - and with leading 0x

• 0x2 , 0x , 0xBCD , 0x3FFF

•Largest value that can be stored is machine dependant • 16 bit machine can store can store maximum integer = 32767 = 215 - 1 • 32 bit machine can store can store maximum integer = 2147483647 = 231 - 1

• Integer constant can be unsigned or signed or long • 56789U ( unsigned integer )• 89776788UL ( unsigned long integer )• 786756L ( long integer )

http://www.tutorialspoint.com/ansi_c/c_using_constants.htm

Page 25: FPL - Part 1  (Sem - I  2013 )

3. Floating point or real Constants• These are fixed values that do not change

• Real or floating point constants - numbers with fractional parts • 0.0083 , -0.75 , +247.45 , 215. . .95 , -.71 , +.5 (omit digit before after .)

• Scientific notation of real numbers

• mantissa e exponent

• mantissa can be real number but exponent is always an + or - integer

• exponent causes decimal point to float so called as floating point form

• 0.65e4 12e-2 , 1.5e+5 3.18E3 - 1.2E-1

• This notation is used to represent very large or very small numbers

• 750000000000 7.5E9

• -0.0000000000000000000000000368 -3.68E-26

Page 26: FPL - Part 1  (Sem - I  2013 )

3. Constants - Find naming errors

Number Valid ? Remarks

698345L

25,000

+5.0E3

3.5e-5

7.1e4

-4.5e-2

1.5E+2.5

$255

0X7B

Page 27: FPL - Part 1  (Sem - I  2013 )

3. Constants - Find naming errors

Number Valid ? Remarks

698345L Yes Long integer

25,000 No Comma not allowed

+5.0E3 Yes

3.5e-5 Yes

7.1e 4 No No white space permitted

-4.5e-2 Yes

1.5E+2.5 No Exponent must be integer

$255 No $ not permitted

0X7B Yes Hexadecimal integer

Page 28: FPL - Part 1  (Sem - I  2013 )

3. Single Character constants

• contains single character enclosed in single quotes • ‘5’ ‘X’ ‘;’ ‘ ‘ ‘\’ ‘Z’ • note 5 is integer but ‘5’ is character • each character constant is stored internally with an ASCII code

printf(“%d”, ‘a’) would display 97 printf(“%d”, ‘108’) would display l

Page 29: FPL - Part 1  (Sem - I  2013 )

4. String constants

• contains sequence of characters enclosed in double quotes

• “Hello” , “1987” , “5+3-2=?”

• it may have letters , digits and special characters

• string constant “A” or “8” does not have an integer value

• ‘5’ and “5” are different

• C compiler automatically store character ‘\0’ at the end of every defined

string constant

Page 30: FPL - Part 1  (Sem - I  2013 )

4. Escape Sequences - Single Character Constant

‘\a’ bell

‘\b’ back space

‘\f’ form feed

‘\n’ New line

‘\t’ Horizontal tab

‘\v’ Vertical tab

‘\’’ Single quotes

‘\\’ Double quotes

‘\0’ null

Special character constants - Escape sequences

Page 31: FPL - Part 1  (Sem - I  2013 )

Constants

Numeric Character

Integer Real Single character String

Page 32: FPL - Part 1  (Sem - I  2013 )

Variables

• Variable is a data name used to store a value that can change • variable can take different values during program execution • a variable should have a meaningful name

• average , sex , age , total , counter , lineno etc

Name Valid ? Remark

First_tag

char

Price$

group one

average _number

int_type

Page 33: FPL - Part 1  (Sem - I  2013 )

Variables

Name Valid ? Remark

First_tag Valid

char Not Valid char is keyword

Price$ Not Valid Dollar illegal

group one Not Valid Blank space

average _number Valid

int_type Valid

Page 34: FPL - Part 1  (Sem - I  2013 )

Data Types • Variety of data types allow programmer to select type appropriate to the needs and the processor • There are three 3 classes of data types in ANSI C

• Primary or primitive data types - int , char , float , void • Derived data types - arrays , structures , pointers , functions • User defined data types - typedef , enum

Primitive data types

Data type Size Range of values

Char 1 byte -128 to 127

Int 2 bytes - 32768 to 32767

Float 4 bytes 3.4e-38 to 3.e+e38

Double 8 Bytes 1.7e-308 to 1.7e+308

Page 35: FPL - Part 1  (Sem - I  2013 )

Data Types •Integer type

• whole numbers • range supported by a specific machine • occupy one word )• word size depends on processor - 16 or 32 • for 16 bit processor - integer values are -215 to 215-1• default is signed integer which stores sign of number in last bit • short int - half the word size• int - - word size• long int - double the word size • unsigned integers use all bits for magnitude • long and unsigned can increase range of values required to be stored

Type Size Type Size

char 8 long int 32

int or signed int 16 unsigned long int 32

unsigned int 16 float 32

short int 8 double 64

unsigned short int 8 long double 80

long intint

short int

Page 36: FPL - Part 1  (Sem - I  2013 )

Data Types • Floating point type

• Real numbers stored in 32 bit format • keyword - float , double used when higher accuracy required • double uses 64 bits storage space - known as double precision number • floating point describes a method of representing an approximation of a real number in a

way that can support a wide range of values. • It has fixed number of significant digits (the mantissa) and scaled using an exponent• Significant digits × baseexponent

• Void Type• void type has no values • used to specify function type• function is void if it does not return any value to calling function • it can also represent generic type

long doubledouble

float

Page 37: FPL - Part 1  (Sem - I  2013 )

Data Types

• Character types • Single character can be defined as character type data

• They are stored in 8 bits (one byte)

• unsingned char 0 to 255 values

• signed char -127 to 127

Page 38: FPL - Part 1  (Sem - I  2013 )

Variable declarations • tells compiler what the variable name is • tells compiler what type of data it will store • declaration must be done before they are used in program

<data type> <variable 1>, [<variable2> , ….]

Primary type declaration int count ;• int sum, total;• char choice;• float ratio,x,y;• short int row;• long int amount ;• double deviation ;• char c;• unsigned n; ( short , long , unsigned without data type is treated as integer)

• qualifiers signed , unsigned , short , long •

Page 39: FPL - Part 1  (Sem - I  2013 )

Constants

Integer constants +111 int -222 int 45678U unsigned int -56789L long int 987654UL unsigned long t

Real constants 0. double .0 double 12.0 double1.234 double-1.2f float1.234567L long double

Page 40: FPL - Part 1  (Sem - I  2013 )

Defining symbolic constants

• defining macro definitions

• use #define which is a preprocessor directive

• does not end with a semicolon

• placed before main

• used to define symbolic constants like pi etc

• #define pi 3.142

• #define name Yogesh

• #define VIIT Vishwakarma Institute of information technology

• # define STRENGTH 100

• # define PASS_MARK 50

• # define ASCII_A 65

• # define ASCII_Z 95

Page 41: FPL - Part 1  (Sem - I  2013 )

Defining symbolic constants

• #define X=2.5

• # define MAX 10 - white space

• #define N 25;

• #define N 5, M 10 - multiple not allowed

• #Define ARRAY 11

Page 42: FPL - Part 1  (Sem - I  2013 )

Comments

Comments are used for documentation purposeStatements enclosed in /* and */ are not compiled Multiple lines can be commented by puttiong /* at start and */ at the end.

/* Include function declarations */ #include<stdio.h>#include<conio.h>Void main(void){ /* Variables */ int x ; char y; int num[15]; printf(“\nEnter age : “); scanf(”%d”,&x);

}

Page 43: FPL - Part 1  (Sem - I  2013 )

Operators and expressions

• Arithmetic Operators

• + addition or nary plus

• - subtraction or us nary minus

• * multiplication

• / division

• % Modulo division

• Integer division truncates fractional part

• % can not be used on floating point numbers

• C does not have a operator for exponent

• During modulo division sign of first operand is sign of the result

• -14 % 3 = -2

• -14 % -3 = -2

• 14 % -3 = 2

Page 44: FPL - Part 1  (Sem - I  2013 )

Operators and expressions

• Relational Operators

• < , <= , > , >= , == ! =

• if expression is zero it is false else true.

• if expression1 operator expression2 - first expression is evaluated and then

the results are compared

• Arithmetic operator have higher priority over relational operators

• > complement of <=

• < complement of >=

• == complement of !=

• !(x<y) x<=y

• !(x==y) x!=y

• !(x<=y) x > y

Page 45: FPL - Part 1  (Sem - I  2013 )

Operators and expressions

• Logical Operators - combining multiple conditions

• && - logical AND

• || - logical OR

• ! - logical NOT

if (age > 55 && salary < 1000)

if ( number < 0 || number > 100)

Precedence

Highest !

> >= < <=

== !=

&&

Lowest ||

Page 46: FPL - Part 1  (Sem - I  2013 )

Operators and expressions

• Assignment Operator

• Used to assign result of an expression =

• Shorthand assignment += , -=

• x+=y+1 x=x+(y+1)

• x+=3 x=x+3

• a=a+1 a+=1

• a=a-1 -> a-=1

• a=a*(n+1) a*=(n+1)

• a = a / (n+1) a/= (n+1)

• a=a%b a%=b

Page 47: FPL - Part 1  (Sem - I  2013 )

Operators and expressions

• Increment and decrement Operator

• ++ m 0r m++ and --m or m—

• prefix ++ or -- increments or decrements variable & then uses in expression

• postfix ++ or -- uses current value in expression and then increments or

decrements variable

• eg. a=3 ; b=5 ; c=10 ; z=0

• z=a++;

• b=--c;

• a=z--; what are values in a, b, c and z at the end

• y=a++ -b-- +--c ;

• Can also be used in subscripted variables e.g. num[i++]=10 ;

• Rules :

Page 48: FPL - Part 1  (Sem - I  2013 )

Operators and expressions

• Conditional Operator

• Ternary operator

• exp1 ? exp2 : exp3 - exp1 is conditional statement

• if exp1 is non zero or true exp2 is evaluated else exp3 evaluated a=10 b=15 x= (a>b) ? a: b; if ( a>b) x=a; else x=b;

Page 49: FPL - Part 1  (Sem - I  2013 )

Operators and expressions

• Precedence of operators

• An expression without parenthesis will be evaluated left to right using

rules of precedence of operators

• Two levels of priority in arithmetic operators • High - * / %• Low - + -• first pass high priority operators are applied • second pass low priority operators are applied • x=a-b/3+c*2-1 a=9 b=12 c=3• First pass 9-(12/3)+(3*2)-1 and a-4+6-1• Second pass 5+6-1 , 11-1 , 10

• E.g. 9-12/(3+3)*(2-1)• 1st pass 9-12/6*(2-1) and 9-12/6*1• 2nd pass 9-2*1 and 9-2• 3rd pass 7

Page 50: FPL - Part 1  (Sem - I  2013 )

Operators and expressions

• Precedence of operators

• parenthesis may be nested --- in such cases evaluation of the expression

will proceed outward from the innermost set of parenthesis.

• 9-(12/(3+3) * 2) -1 = ?

• 9-((12/3)+3 *2)-1 = ?

• Rules

• First parenthesized sub-expressions from left to right are evaluated

• If nested parenthesis evaluation begins from innermost sub-expression

• Precedence rule of operators is then applied

• Associative rule applied if two operators of same level appear

• Arithmetic expressions are evaluated form left to right using rules of

precedence

• Expression within parenthesis assume highest priority

Page 51: FPL - Part 1  (Sem - I  2013 )

Operators and expressions

int a a= 5 <=8 && 6!=5 ; printf(“%d”, a); getch(); Answers =1

some computational problems

(A) Division of frictional numbers a= 1.0 / 3.0; b= a * 3.0 ; What is value of b ?

(B) Divide by zero

Page 52: FPL - Part 1  (Sem - I  2013 )

Operators and expressions

(B) Overflow or underflow - operand should be of correct type and size otherwise there will round-off errors introduced

float sum, n, term;int count = 1; sum=0 ; printf (“Enter value of n \n”); scanf(“%f”,&n);term= 1.0/n;while ( count <=n){

sum= sum + term; count++;} printf(“ Sum = %f\n”, sum);}

Output Enter value of n 99 Sum= 1.000001 Enter value of n 143 sum= 0.999999

Page 53: FPL - Part 1  (Sem - I  2013 )
Page 54: FPL - Part 1  (Sem - I  2013 )
Page 55: FPL - Part 1  (Sem - I  2013 )
Page 56: FPL - Part 1  (Sem - I  2013 )
Page 57: FPL - Part 1  (Sem - I  2013 )
Page 58: FPL - Part 1  (Sem - I  2013 )
Page 59: FPL - Part 1  (Sem - I  2013 )
Page 60: FPL - Part 1  (Sem - I  2013 )
Page 61: FPL - Part 1  (Sem - I  2013 )

String Handling

#include<stdio.h>

#include<conio.h>

void main(void)

{

/* Input a string */

char string[25];

clrscr();

printf("Input a string : ");

scanf("%s",string);

Page 62: FPL - Part 1  (Sem - I  2013 )

String Handling

/* Find length of string */

i=0;

slen=0;

while(string[i]!='\0')

{

slen++;

i++;

}

printf("\nString length : %d",slen);

Page 63: FPL - Part 1  (Sem - I  2013 )

String Handling

/* Dislay string in reverse order */

i=slen;

printf("\nReverse string : ");

while(i>=0)

{

printf("%c",string[i]);

i--;

}

Page 64: FPL - Part 1  (Sem - I  2013 )

String Handling

/* Find number of vowels in string */ i=slen; while(i>=0) { switch(string[i]) { case 'A' : case 'a' : case 'E' : case 'e' : case 'I' : case 'i' : case 'O' : case 'o' : case 'U' : case 'u' : Nvowels++;

break; } i--; } printf("\nNumber of vowels : %d",Nvowels);

Page 65: FPL - Part 1  (Sem - I  2013 )

String Handling

/* Find number of 'a' or 'A' in string */

Na=0;

for(i=0; i<slen; i++)

{

if(string[i] =='a' || string[i] == 'A')

Na++;

}

printf("\nTotal number of charater \'a\' or \'A\' : %d ",Na);

Page 66: FPL - Part 1  (Sem - I  2013 )

String Handling

/* Check is string is palindrome */ i=0; j=slen-1; while(string[i]==string[j]) { i++; j--; if(i>j)

break; } if(i>=j) printf("\nString is palindrome"); else printf("\nString is not a palindrome"); getch();

Page 67: FPL - Part 1  (Sem - I  2013 )

String Handling

Page 68: FPL - Part 1  (Sem - I  2013 )

String Handling

Page 69: FPL - Part 1  (Sem - I  2013 )

Extra

Page 70: FPL - Part 1  (Sem - I  2013 )

3. Constants - Find naming errors

Page 71: FPL - Part 1  (Sem - I  2013 )
Page 72: FPL - Part 1  (Sem - I  2013 )

• Binary code

• Assembly language Assembles

• Low-level programming languages (Like C, C++, B, D, fortain, objc, simula...)

•High-level languages (Like C++.NET, erlang) -> very high/goal level programming languages

• Low level interpreted languages (like Java, C#...) ->

• Mid level (Python, Ruby) ->

•high level (no bytecode) interpreted languages (Bash, PHP, Lua) -> "Structure interpeted"

Page 73: FPL - Part 1  (Sem - I  2013 )

• A high-level programming language that is interpreted by another program at runtime rather than

compiled by the computer's processor as other programming languages (such as C and C++)

•Programming language where scripts / programs written for a special runtime environment that will

interpret/automate tasks which could be executed one-by-one by a human

• For instance, one could put a series of editing commands in a file, and tell an editor to run that "script" as if

those commands had been typed interactively.

• Scripts are tasks written for runtime environment and interpreted at runtime in a batch

• Many programs can be together pipelined in script -- eg. Shell script in Linux

• The primary focus isn't primarily building your own apps so much as getting an existing app to act the way

you want,

• Scripting is used to configure web pages within browser , shells of OS

•Typically, a scripting language is characterized by the following properties• Ease of use. - very fast to learn has simple syntax and semantics. • OS facilities - Scripting is usually aimed at desktops, limiting the portability needs of the pre-built libraries.• Interpreted from source code - to give the fastest turnaround from script to execution. • Relatively loose structure. It would be difficult to use Java as a scripting language due to the rules about which classes exist in which files - contrast to Python, where it's possible to simply define some functions in a file.

• An interpreter or a virtual machine is required

• JavaScript, ASP, JSP, PHP, Perl, Python

Scripting Language

Page 74: FPL - Part 1  (Sem - I  2013 )

•Source code is present at run time in production system and compiled into native object code.

• Use of an interpreter or Virtual Machine is generally required; though the OS may arrange for the appropriate interpreter to be invoked automatically.

•Explicit compilation or linking phases are not needed

•Variables, functions, and methods typically do not require type declarations.. •Very powerful built-in types - typically a dictionary, a set, a literal type that can act as either numeric or strings.

•The ability to generate, load, and interpret source code at run time through an eval function. (Perl, Python, Tcl, JavaScript, shell scripts, REXX, APL;

•Interface to the underlying operating system, in order to run other programs and communicate with them.

•Rich I/O capabilities, including pipes, network sockets, file I/O, and file system operations.

Properties of a scripting language

Page 75: FPL - Part 1  (Sem - I  2013 )

Characteristics of a good programming language -1

• Vocabulary should resemble English (or some other human language).

• Programs should consist of instructions- tedious declarations should be kept to a minimum.

• The language , its classes or functions in libraries should be fully documented.

•There should be no need to manipulate pointers explicitly no means of doing so. They should

be managed by the language and not by the programmer.

•The language should provide arrays of unlimited size: there should be no need to declare array

bounds.

•Sorting facilities should be included as standard; we shouldn't have to write our own sort

routines.

•The language should provide full facilities for handling a graphical user interface. These

• Should be able to keep one project separate from another and projects should be separated

from libraries supplied with the language.