أصول لغات2
-
Upload
khadar-daahir -
Category
Documents
-
view
278 -
download
7
description
Transcript of أصول لغات2
Concepts of Programming Languages :
3
Fundamental of Concept of Programming Languages)4
Evolution of the Major Programming Languages11
Describing Syntax and Semantics17
Names ,Binding,Type Checking and Scopes23
Data Types29
Subprograms40
Arithmetic Expressions 53
Data Abstraction63
Object Oriented Programming70
Logic Programming81
.
. .
. . . . . . . .
:1- .2- .3- ,4- .5- .6- . : . : : : "arrays " "loop " . "high level -Languages " "Fortran" "ALGOL 60" . : : "1940" "COBOL" :1- .2- .3- . : : . "linked list" .
"lisp" (). : : ( ) . : : "sh (for shell)" . : : "PRG" (GPSS) . (language Evaluation Criteria) :1- readability
2- writability
3- reliability
4- cost : readability : . (factors) :/ simplicity :
C C++ :M=m+1;
M+=1;
M++; ++m;/ orthogonality : . / control statements : ./ data types and structure : . : writability : .
(factors) : / simplicity and orthogonally / support for abstraction class . . / : Expressivity
. reliability : . :1- type checking : . : ( ).2- Exception handling : . C++ , java , ada .3- : Aliasing "Aliase" : .4- : . : cost : () :1- .2- .3- .4- .5- ( ).6- .7- . : : (computer architecture) (language methodologies) . : 35 (Von Neumann) (CPU) . " " . (C++,C,Pascal,Algol). Von Neumann .Memory (stores both data and program )
Instruction and data Result of operation
Input and output Devices Centerl processing Von Neumann architecture
: language methodologies :
:1- (compilation) : (compiler) .2- (interpretation) : .(Interpreter)3- (hybrid) ./ : :1- "lexical analyzer " (lexical unit) .2- "syntax analyzer" ( )(parse tree) .3- .
/ : . . :
/ : :
Lexical units
Parse tree
Intermediate code Input data Results Evaluation the major Programming Language : Fortran IF : If (arithmetic expression) n1,n2,n3 n1,n2,n3 (statement labels) n1 n2 n3 .
Fortran I :Do N1 variable = First.value, last.value
Fortran I n,m,k,l,j,i integer floating point . Fortran II 1958 Fortran IV Fortran II :1- .2- logical IF construct .3- . Fortran 77 Fortran IV : 1- (character string handling ) .2- (logical loop control statement) .3- if then .else . Fortran Fortran 90 :1- Dynamic Array.2- Pointers.3- Recursion.4- Case statement.5- Parameter type checking. LISP(1959) (List Processing) McCarthy (AI) LISP : 1/ lists .2/ Atoms . : : : (A B C D) :
A B C D : (((F G)D(E(B C)A) :
D A B C E F GALGOL 58 : () ((IAL) International Algorithmic language) ALGOL 58 . () . ALGOL 58 : (names) . . (begin end) . (;) semicolon . =: . if else if clause .ALGOL 60: ALGOL 58 : Block structure (local scope) . Two parameters passing methods
Subprogram recursion . Stack dynamic arrays
ALGOL 60 : 20 . 60 . (BNF) Backus Norm Form . Basic 1964 : Beginner's All purpose Symbolic Instruction Code : 1963 John kemeny kurt2 Dartmouth . Buick Basic Visual Basic . PL/I 1965 : IBM Share Fortran VI 1964 NPL new programming language 1965 PL/I Programming Language PL/I :1- .2- .3- . APL : A programming language (1962) IBM ken I verson . (1964) SNOBOL : Farber, Grijwold , Polensky bell . SIMULA 67 (1967) :
(Nygaard and Dahl) ALGOL 60 SIMULA I .:1- (Coroutines) .2- class .3- class . 1971 : Wirth turbo pascal Borland . 1970 1990 . ADA : Ada (Department Of Defense) 1970 1980 Ada ( Ada) . Ada multitasking . C : Bell Dennis Ritchie B BCPL 1969 . C . C system software . C++ . java : www . Sun Microsystems c++ . (Describing Syntax and Semantic)
: Asentence. Alanguage. A lexeme : I identifiers . Literals . Operators . special words
A token A lexemes . C :
index = 2*count + 17 ; lexeme token :Lexeme token
Index indentifier
= equal _sign
2 int _ literal* Mult _ operator
Count identifier
+ plus operator
17 int literal
; semicolon
:
1- Recognizers compilers .2- Generators .3- Context free grammars : class context free language .4- Backus Norm form (1959) : John Backus ALGOL 58 .BNF context free language class .
: while ()
rule () while (LHS) (RHS) terminal & non terminal symbols . :
| begin end
:
if then
if then else
Or
if then
| if then else
(LHS) (RHS) .
: ident
| ident ,
derivation : () start symbol (terminal symbols) . : .Ambiguous : .Ametalanguage : .Grammars and Derivation:
A grammar is a generative device for defining languages the sentence of the languages are generated through a sequence of applications of the rule , begin with special non terminal of grammar called the start symbol . A sentence generation is called a derivation.
Example 1:
A grammar for a small language:
begin end
|;
= A|B|C|D
+
| -
|
A derivation of a program in this language follows :
> begin end > begin ; end > begin = ; end
> begin A = ; end
> begin A = + ; end
> begin A = B + ; end
> begin A = B + C ; end
> begin A = B + C ; end
> begin A = B + C ; = end
> begin A = B + C ; B = end
> begin A = B + C ; B = end
> begin A = B + C ; B = C end sentence
A grammar for simple assignment statement: :=
A|B|C
+
| *
| ()
|
A derivation? A := B*(A+C)
Parse tree?
> :=
> A :=
> A := *
> A := B *
> A := B * ()
> A := B * ( + )
> A := B * ( A + )
> A := B * ( A + )
> A := B * ( A + C) sentencParse tree :
:=
A *
B ( )
+ A C A := A * ( B + (C * A))Derivation ?
> := > A :=
> A := ()
> A := ( + )
> A := (B + )
> A := (B + ())
> A := (B + ( * ))
> A := (B + (C * ))
> A := (B + (C * ))
> A := (B + (C * A)) sentence
Parse tree :
:= A *
A ( )
+ B ( )
*
C A(RHS) :
> := > := * > := * () > := * ( + ) > := * ( + ) > := * ( + C)
> := * (A + C) > := B * (A + C)
> A := B * (A + C) names , bindings , type checking. scopes
name : Design Issues for names : : Name forms : Fortran I Fortran 77 6 Fortran 90 31 . C C++ java , Ada (_) underscore . special words : reserved words key words . variables : . : name , address , value , type , lifetime , scope .
: name : ( _ ) . : address : . sub1 sub2 sub1 sub2 . : data type : . integer 758 32- 767 32 . : value : . r-value . L-value . : : (allocation) deallocation . : Variable Scope .
:
.
: . .
:
Begin }sub1{
end sub1..
End , }main{ sub1 sub1 main sub1 .
:
C C++ . C++ (::) scope operator .
Type Checking
(Compatible).
:
.
Type Error Oprands
:
.
.: APL SNOBOL4 . Pascal , Ada , C+ + C .
- Type Compatibility:-
.
.
:
1-
-
:
:
.
Pascal
Type index type = 1 100
Var
Count : integer
Index: index type
Count index .
:
:
:
Type degree = real,
Grade =real,
degree grade . Primitive Data Type .
: integer , floating point character Boolean .1. Numeric Types
integer . integer short integer long integer unsigned short integer unsigned long integer " integer " ( + - ) (-) .2. Floating point Data Type
.
:
. 4 .
52 8
23 11
()
: IEEE 754 Decimal Decimal .
.
Character Type ASCII (American Standard Code for Information Interchange ) 127.0 128
(Unicode ) . . Boolean Type . ( True) ( false) . Character String Type . . . Concatenation Ada. Ada (cf) . Name Name 2 :
Name 2 : = Nane1 + Name 2
Ahmed Name 2 , "Mohamed" Name
Name : = Mohamed Ahmed C , C + + :
- : trcpy- : strcat Strlen : Strrcmp. Fortran fortran 90 Basic . Design Issues :
.
Defined Ordinal Type . integer , char , Boolean :
- : Enumeration Type.- : subrange Type.1.2. Enumeration ( ) .
: Ada:
Type Days is (Mon , Tue , Wed , Thu , Fri , Sat , Sun );
Enumeration : Enum . enum Ada :
12.14 integer . :
Type
uper case A ..Z ;
index = 1..100;
:
Upper case :
Index :
- Ada sub Type
sub type week day is day range man Mon.. Fri;
Sub type index is integer range 1..100 ;
:
Week day:
Index : 1 100
2- . Array Type
:
: ( integer) .
.
:
Int array_Name ]index[ :
Array Name: int[index] : .
. . Fortran Ada .
1- Fortan :
Integ list (3) .
Data list /0,1,2/
list / /
2/ C C+ + :
Int list ] [ = } 4,5,7,12{ pascal Ada
(+) (_)() . .
: Ada (+) :
A+B Slide of Array
A :
A
: (A)
:
A (1:3) (3.3) :
: (A) : (A (1:3,2
Record Type
.
:
.... . .
1- Fortran 902- .
3- . .
4 .
COBOL:
0I Employee Record
02 Employee Name
05 First
Picture is (20)
05 MIDDLE Picture is (10)
05 LAST
Picture is (20)
20 HOURLY RATE Picture is 99799.
:
1- Employee Employee Name Hourly Rate
2- 05,02,10 .3- Picture : (20) 20 99799 . Ada :
Employee Record :
record :
Employee Name :
First : string : (1..20) ;
Middle : string (1..10);
Last : string (1..20);
end record ;
Hourly rate : Float ;
end Record ;
:
- : Employee Employee Name : - : First , Middle Last Hourly rate Float.
(.) Middle :
Employee Record Employee Name. Middle Pointers Type
: nil :
.
- C+ + Java ( Refences) .
- dangler : , .
1- pascal new dispose .2- C C+ + :
- (*) .
- (&) .
:
int * ptr ;
int count , init ;
..
ptr = & init ;
count = * ptr ;
:
*ptr : int
Int , count : int
&int : ptr (Subprograms)
:
1-
2- 3- .
. subprogram call
.
Subprogram Header :
1- .
2- - :
Sub routine Adder (parameters) ; :
subroutine :
Adder : Parameter : C , Function :
(parameters) void adder. :
void : .
adder : . Parameters .() Parameters
:
- ( ).- .
. :1- Parameters Formal 2- Parametrs Actual :
. - . .
- C+ + FORTRAN 90 Ada Default Vslues
. Ada.Function compute - pay (income : Float ;
EXEMPTION : integer : = 1;
Tax RATE : Float) return float ;
:
Compute pay :
Mac rate , income :
Excemption 1 compute pay Excemption :
Pay : = compate pay ( 2000.0,Tax Rate = > 0.15 ;
:
- C++
Procedure and Function : .
. :
- .
- .
- .- ..
:
1-
2- - . power C:
Float power (float base, float exp);
power :
Result = 3.4 * power (10.0.x);
:
Result = 3.4*10.0**X;
, . .
. .
. :1- . 2- . :
/ :
1- . 2- . 3- . 4- . 5- . / :1- .
2- . 3- . 4- . :- .
- .
- . AlGOL 60 C C++ static .
C C+ + sum count adder .
int add ( int list ] [ int listlen)
}Static int sum = 0 ;
int count ;
for (count = 0 ; count