Вы находитесь на странице: 1из 127

..

I-40 02 01
,

2007

1.

, . . . . , , , , . .

1. .. . . 2- . ., , 2005.
2. . . , , 2004.
3. .., .. . . . ., - , 2004.
4. . , 4- . ., . , 2004.
UNIX
5. . UNIX . , , 2003.
6. . UNIX, 2- . , -, 2005.
7. .., .., .. UNIX. , -, 2005.
Windows
8. ., . Microsoft Windows: Windows Server 2003, Windows XP Windows
2000. -. ., .-. , ., , 2005.
9. . Windows, 3- . ., . , 2005.

10. ., . . OS/2 Warp . .2. ., , 1996.
11. . QNX Neutrino2. . ., , 2005.
12. QNX. ., ., . . ., . , 2004.

13. .., .. . . ., , 2003.
-
14. .., .., .. . . ., , 2000.
15. .., .., ..
10.03.00 , . ., , 2001.
16. .., .. . . ., , 2001.
17. .., .., .. : .-. .
. . I-40 02 01 ,
. : , 2007


. :
, ,

,
.

,
.

,
, (, , ) , , , . , . . :
- ;

, , ;
;
();
;
, ;
;
-;
;
;
;
;
;
;
.

.
, . ,
. .. , , . .
, . . .
. .
.
X Windows UNIX, Explorer Windows. . , Linux Windows. ,
.
, , , .
. , , , -.
,
, , ..
. XIX . . , , (Ada
Lovelace), . , .
4 .
1. 1945-1955. ,
. .
, . , :
, .. ,
, . .
2. 1955-. 60. 50- 60- . , . . (, ). .
. , IBM 701 50- GM. 1955 IBM 704.
. FSM (Fortran Monitor
System) IBSYS ( IBM). 50- :
1. .
2. -.
3. .
4. , , .
5. , .
, ..

3. . 60-1980. 60-
. , . . , :
1. , .. ( ) ;
2. .
3. , .. -.
:
- :
- :
-
-
-
- .
60 70 :
, .
. IBM , IBM/360.
, , OS/360. . OS/360 2-3 FSM, , . . , .. . , , . CTSS (Compatible Tme Sharing
System ). . ,
.
, . MULTICS (MULTiplex
Information and Computing Service - ).
PL/1, . , 80 . 30 , 90 .
PDP-1 -. PDP-1 4 18-
120 . $ , 5% IBM7094, . PDP-11. ,
MULTICS, PDP-7 MULTICS. , UNIX PDP-11/20 , . , ,
, . . , , . UNIX , ,
, UNIX .
PDP-11 , UNIX .
, . UNIX.
UNIX System V BSD. , UNIX, IEEE
POSIX, .
4. 1980 . . 1974 Intel Intel 8080.
. , .
. CP/M (Control Programm for Microcomputers).
5 CP/M . 80 IBM
. BASIC,
. . , , .
IBM . (DOS)
. , , MS-DOS
(Microsoft Disc Operation System), . , , ,
.
60 (GUI).
Xerox PERC, Apple . ,
. Microsoft GUI MS-DOS
(Windows 3.11). 1995 Windows 95 Microsoft. UNIX -

X Windows. 80 , . , , , . ,
, ,
. ,
, , ,
.
, - ( ),
. .
: . ,
. - . ,
. - .
.
, , .. , , .
: .
. , "", .. () , . , .
: .
( ) , . .
, , .. .
- , , - .
: , .
,
.
. ,
- . ,
. , ,
, .
: . ,
. . , , , . ( , ).
: .
. ,
.
.
: . .
, .
. , , . - ,
.
. "",
- , "". "",
. , "". , ( ) ,
" ".
: , .
.
,
. .
, - : , , .
--, .
. ,

, ,
.
: --, ,
, (, -). , , . - .
: , . () . , , , "--" - ,
, . ,
, . , ..
, ,
. - (
).
: . "" ,
. "". . "" ""
- . "" : . "" - - , . ( , , ..). "" ,
, . : , , , . ( , ) . ,
, .
.
. , , . ,
. , -.
,
, , .
, , . . , , ,
. ,
. ,
, .
.
, . . .
- .
. , .
, .
. . , , , , .
. , , . . , , .
. , . , . ,
.


. . . . . ,
, -, , .
. . . .
POSIX. Win32 API.
.
, . ,
. , . ,
50- . -,
.
, .
. .

. .
, -, , , . ,
. , .
- - .
. - . -.
,
, . , . , , , .. , .
, .

. . .
.
. ,
. UNIX
. .
, . UNIX
, .
mount () . UNIX . -,
.
:

,

,
, . ,


: , , , , ,
, -.
-, .
-

. , : , ( )
. . , . , , .. , .
.
. OS/390.
, . , , . Web- . UNIX, Windows 2000, Linux .
, , , . . , , .. Windows, Linux.
, , , , , . , , , , . VxWorks QNX.
, ,
(, , ) . , , , . PalmOS
Windows CE. - , .
- . - Java-,
Java- (JVM). -
, , . , , , -.
. - . , , .
, . . , . , . , . .
: , .
, . , .
. THE,
1968 . 6 . 0 , 1 , 2 -, 3 , 4 , 5 . 0 , .
,
, . .. 0 . 1 . ,
. . , . 2
. . 3 . 3 , .
MULTICS. ,
, . ,
. . , , . . , , .
. , .
, , . , .
: 1.
, 2. , . VM/370. , , . , -

, , , , .. . ,
, VM/370. ,
. , , , . , .
. , .
VDM- (Virtual DOS machine) , MS-DOS . VDM-. 8086, Pentium. Java-. Java
JVM. , JVM.
, , . , , .
, , . ,
, .
,
, .. . , , , . , , -, . -
. , ()
(), .

,

. .
, .. , , . , , , . , (, ), ,
. - , . , , , , : .
,
.
, . ,
. , Linux .
/ .
Windows NT. , ,
, .
.
, 4.4BSD MkLinux, Mach.
, .
:
. ,
. , , , . . .
. , , .
. , .
. -

. , . ,
, . .
. , . - . . , , , .
. , .
. , , . ,
, , ,
. , , ..
. , , . , .
- .
, . . Linux, , , .. . .
. . , , ..
,
.
. , , . , , , , , ,
, .
, . , .
. ,
. , . , , , . .
. (), . .
, .
, , .
. .
,
. ,
, , , . , , :
- ;
- , ;
- , , . .
, , , .. -
, . . . , .

.

: , , . : ,
. ():
1. .
2. .
, .
3. , . , , .
4. , ( ).
5. .
6. , , .
7. , .
8. .
9. .
10. , .
. , , . , . .
. , . . .
, . , ,
.
.
.
, .
. - .
-. ,
.
().
. : , , . , , . . , , . -
.
. ,
, .
, .
, . ,
, .
. , .
. , ,
(.. ), .
. . () () .
. ,
. :
- . ,
. .. .
*-. ,
. .. , .
( ). 4 : A, B, C, D. 1 2, 1, 2, 3.
. 2. :
- , ;

- , ,
;
- (), , ;
- , .
, .
, ,
. , .
90% . Common Criteria, Controlled Access Protection Profile 2.
. , .. , , . ,
,
, . . . , . , . . , . . . .
, .
, ,
.
, , . ,
, . .
, . UNIX libc - . .
(API - Application Program Interface) ,
.
. , API , , , RTL. , API , , MFC, VCL.
, POSIX (Portable Operating System Interface for Computer Environments) ,
UNIX . , UNIX , .
POSIX 100 .
UNIX, Windows
. Win32 API. WinAPI , , . , UNIX
GUI , WinAPI , , .. Windows , ,
. Win32API , ,
. WinAPI Windows NT 5.x (Windows 2000, Windows XP, Windows Server 2003) POSIX, POSIX.1, .
:
POSIX

fork
,
waitpid

execve

exit

open

close

read

write

lseek

stat

mkdir

Win32 API
CreateProcess (fork+execve)
WaitForSingleObject
ExitProcess
CreateFile
CloseHandle
ReadFile
WriteFile
SetFilePointer
GetFileAttributesEx
CreateDirectory

rmdir
link
unlink
mount
umount
chdir
chmod
kill
time


RemoveDirectory
,
DeleteFile



SetCurrentDirectory



GetLocalTime


. . . .
. . -. .
Windows UNIX. . . . . . Windows UNIX. . . . . UNIX. Windows
. , , , .. / . . :
() -, .
,
,
. ..
,
,
.
,
,
,
,
.
, , .
, . ,
( ), , , /, .. ,
( , , ).
, . , :
-
-
- ( )
, , , ,
, . , ,
- . .
, . , , .
.

.

, ,
,
.
3 :
- .


,
, -.

. , . .
, .. , , , .
.
:
- . , ,

- ( )

( , , , )

.

, , ( ), . , .
:
- , . , . ,
-

- -, - ,
. (
-, .. .
.
, , .
. , .
, , web-, , , .
, .., . , - . .
. :
- PID process identificator
- / ,
- .
- , ,
- ( ), . .
- , ( ,
/)
- ()
- ( )
- , , .
, , .
, . , . ,
.
. . i80x86 80286
TR (task register), TSS,
.
UNIX 2 : u proc. proc, .
, . u
, .. , ,
.
UNIX : fork. , .. . , ,
. fork , ,
, . , fork 0 PID , 1 . fork :
- -
- PID proc
- proc . , 0,
-
- u u
- u
- , , .



- , ,
-
-
- 0
- PID
, fork exec, . . .
, , .
, , , , , , .
, . vfork, .
, exec exit,
.
execve.
, . ,
: . ,
cp file1 file2 : fork , exec
cp ( ), , . :
-
- ,
- ,
- UID GID
- ,
-
-
- ,
-
-
-
-
waitpid. pid , 1, . , . wait , . Wait PID , proc, .
, . :
if (fork()!=0)
{waitpid(-1,&status,0); }
//
else execve (command, parameters,0);
//
exit . :
-
-
-
-
- proc
- SZOMB, proc -
- init
- , u,
- SIGCHLD
-
- swtch
. proc,
. . . , init. .
, wait, proc, - . ps, , . ,
proc, , .

Windows CreateProcess.
, . Windows , . GetCurrentProcess GetCurrentProcessId . ExitProcess.
WaitForSingleObject WaitForMultipleObject. . .
CreateProcess :
-
- Windows-, ()
-
- ,
- Windows
-
-
.
. , , , ..
. . . (thread) ,
, , , , .
. .
, . , . , ,
.

.
. .., ,
, .
,
.
. . ,
-. ,
. ,
.
,
, ,
.
, ,
,
.

.
, , .
,
, -. , , ,
. , , ..,
. . , . , ,
. Windows .
, .
, . UNIX . (LWP, lightweight process). , LWP . LWP ,
, , ,
LWP, . ,
, , .
, , . . Windows ,
. .. , .

, . -,
, . . , , . . . . , ?
? ..
Windows CreateThread. ExitThread,
. GetCurrentThread
GetCurrentThreadId , OpenThread
. SuspendThread ResumeThread . WaitForSingleObjects WaitForMultipleObjects. CreateRemoteThread .
POSIX pthreads . UNIX
Linux. pthread_create pthread_exit,
pthread_join.
. .
, , .
(Task), . ,
.
. . .
, , . , . .
- . :
-
- . , , .
- . , .
- ,
-
-
-
, .
.
, . . , , .
, , :
-
- -
-
-
-
, :
- ( ,
)
- ( )
-
-
- .

. . , , ,
. .
, , . . , .
, .
: , .., . , . :
- . , . . , .
- . . . .
- . . .
. ,
. . : ( ),
, . , , , . , ,
, . ..
.
,
. ,
- . .
, ( ) .
. .
UNIX . . - . . . POSIX
. , , . :
- abort. , ,
..
- exit.
- ignore.
- stop.
- continue.
, ..
. . SIGKILL SIGSTOP , , . :
- ,
-
- ,
- , , ;
- ,
- , , /
- .
u :
u_signal[]
u_sigmask[] ,
u_sigaltstack
u_sigonstack ,
u_oldsig
proc :

p_cursig ,
p_sig
p_hold
p_ignore
:


SIGABRT

abort
SIGALRM

exit
SIGCHLD

ignore
SIGCONT

ignore
SIGFPE

abort
SIGILL

abort
SIGINT

exit
SIGKILL

exit
SIGPIPE
exit
SIGQUIT

abort
SIGSEGV

abort
SIGSTOP

stop
SIGSYS

exit
SIGTERM

exit
SIGUSR1

exit
SIGUSR2

exit
Windows - . 900 . . ,
, , ..
WM_COMMAND WM_NOTIFY. .
Win32 API PostMessage PostThreadMessage, ,
, . , . , , .
GetMessage. 0 WM_USER 1
Windows, WM_USER 0x7FFF, 0x8000 0xBFFF
Windows, 0xC000 0xFFFF , 0xFFFF Windows.


. . . . . . . .
, -
. .
() . .
, . , , , . , , -, , . , . . , , .
, . , : , , ( ), ,
.
2 : , ,
- ( ), , - ( /). ,
, .
:
1. . , .
2. . .
3. . , . . , ,
, .
4. /. , , , .
,
. :
- , .
-
- .
, . 2 : .
,
. , . , , .
. .
- . ,
, . , . , , ..
, .
( ) ,
.
Windows 3.x.
:
- . 2-3%,
20-40%
- .
- . .
, , ,
.
- .

- . . ,
.
, .
:
- . , ,
.
- . . 100%.
-
-
- .
, , :
- .
- , .. , ..
-
- , .. .
:
: , , .

FCFS (First Come First Served) . ,


( ). , . ,
. , , ()
, . , .
, . , . ,
. , . , , 13, 4, 1 . : 0, 13, 13+4=17 , 0+13=13, 13+4=17, 17+1=18 , 0+13+17=30/3=10 , 13+17+18=48/3=16 . ..
,
.. .
SJN (shortest job next) .
. , , JCL (job control language). ,
, .
, , , . . . :
0, 1, 1+4=5, 0+1=1, 1+4=5, 5+13=18,
0+1+5=6/3=2, 1+5+18=24/3=8.
SRT (shortest remaining time) .
, ,
.
, , , . .
. .
, .

. , ,
. . , . . .
RR (Round Robin). . , (). ( ),
. . , , 4.
0(13) +
+
+
+
+
+
+
+
+
+
+
+
+
1(4)
+
+
+
+
2(1)
+
5, 4, 8. 5+13=18, 4+4=8, 8+1=9. 5+4+8=17/3=5.67.
18+8+9=35/3=11.67. .
1:
0(13) +
+
+
+
+
+
+
+
+
+
+
+
+
1(4)
+
+
+
+
2(1)
+
5, 5, 2. 5+13=18, 5+4=9, 2+1=3. 5+5+2=12/3=4. 18+9+3=30/3=10. ,
. . , ,
, . ,
.
. , OS/2 TIMESLICE, . - , , , .
. .
.
.
, () . , ,
, . , . .
.
, , ,
, . , , , , . , , , . , , . , , ..
, 1/f, f , .. 1/10 , 10, 1/25, 25.
, , .
, . ,
. .
. , . . ,
, 8. 16, 32, , . . , ,
, . . ,
, , ,
. (, /)
.
. , .
. , .. . , , . , . -

, .
. , ,
, . , , .
. , . .., , , , .
.
. , , . ,
( ), . , . m , i Pi, Ci , :
, , .
, . . m
Ci / Pi 1
. .

i =1

, , , .
, .
:
- ,

- ,
- ,
-
. , ,
, . :
- , :
- . ,

- , .
. 2 , . , , . . , ,
, . .
.. : 1, 2, 3, 1, 2, 3
, , , , . : 1, 1, 2, 2, 3, 3, . , . ,
, . , , , , .
UNIX. UNIX . ,
. p_nice p_cpu.
. , . , , . , 0-65, 66-95, 96-127 . , ,
,
. , . , , . 1. , . , 4 . ,
.

WIN NT 5.. , +/-2 . . , . . 16 31 .


, . , . , , 0. 1-15. , 1
. .
2 , Server 12. Hkey_Local_Machine\System\CurrentControlSet\Control\Priority
Control\Win32PrioritySeparation . , (2 12 1 2 ), 0 3 .
, . 1 , 2 , 0 3
(, Server - ).
0,1,2. 3 2. ( ) :


0
1
2
0
1
2

6
6
6
12
12
12

2
4
6
4
8
12
OS/2. 4 . 0-31. . . , , , .. . , . , . . . ; , . .
. 1. ,
, 2. 3.
.
MAXWAIT, 1 , ,
. , MAXWAIT 1 .


. . . . . . . . .
, . :
- ;
- , ;
- : , , ,
.
. ,
. , , . ,
, . . , 2 , 3. , 3. , , , .
, 3. , 1.
. , 3, 4, ,
. , , , . ,
. ,
, , , .
. 1965 .
. , . . . , , ,
, - . , , , : . . () ( ). . . , .
, , , . , , , , :
, , , , .
, , , , .
, . .
,
(.. ). N :
Ri i, Wi . N , :
- Wi Wj = , i,j=1,2,,N; ij
- Wi Rj = , i,j=1,2,,N; ij
. : x=u+v; y=x*w; : a=b*c; z=x+a;
Wa = {x,y}, Ra = {u,v,x,w}; Wb = {a,z}; Rb = {b,c,x,a}.
Wa Wb = , Wa Rb ={x}, Wb Ra = . .
, ,
. . .
, , . ,
, .

-
,

,
.


, .
-. , , .
, ,

. ,
. , , , .. , . , , , , . :
4 :
- ( );
- , , , , .. ; , , ,
( )
- , , ; ( )
- .
, , , ,
.
.
. .
, , .
. , . ,
, .
. ,
0. , , 0, 1 . 1, , 0.
.
. , , :
int turn;

// , ,

void process1 (void)


{while (TRUE)
{while(turn!=1);
critical_section1();
turn=2;
non_critical_section1();}}

// ,
//
//
// ,

void process2 (void)


{while (TRUE)
{while(turn!=2);
critical_section2();
turn=1;
non_critical_section2();}}
.
. , , . . , 2 ,
1. 1 . .
. , . . . , , . ,
, , .
. , , . , . .., , : , , . , , .
. , . , . 3 :

switch[0], switch[1], turn, , , . -.


// , 0
int turn;
// , ,
int switch[2];
//
#define PROC_NUM 0
// 0 1 , 1
void process (void)
{while (1)
{switch[PROC_NUM]=1;
L: if (switch[1-PROC_NUM]==1)
{if(turn==PROC_NUM) {goto L;}
else
{switch[PROC_NUM]=0;
while (turn==1-PROC_NUM);}}
else
{critical_section();
turn=1-PROC_NUM;
switch[PROC_NUM]=0;}
non_critical_section();}}

//
// ,
// ,
// ,
// ,
// ,
//
//
// ,

0,
1,
0 , ,
. ,
, .
.

.
, .
N
.
. 1981
.
.
, - .
// , 0
int turn;
// , ,
int switch[2];
//
#define PROC_NUM 0

// 0 1 , 1

void process(void)
{while (1)
{switch[PROC_NUM]=1; //
turn=PROC_NUM;
//
while (turn==PROC_NUM && switch[1-PROC_NUM]==1);}// .,
// . .,
critical_section();
//
switch[PROC_NUM]=0; //
non_critical_section();}}
// ,
//
. 0 , , 0 ( 0). 1 , 0 , , , .
, . 0 ,
(0). 1
(1). : 0 . 1 . 0 :
1 , 1. , ,
. . 1
, , .


Test & Set. TS . .
. . -. Windows UNIX.
. . .
. IBM360
TS (Test & Set). . , . ,
, .. . , . 1, - . , , 1, . TS :
1.
int common=0;

//

#define PROC_NUM 0

// 0 1 , 1

void process(void)
{int proc;
while(1)
{proc=1;
while(proc==1) TS(proc, common);
critical_section();
common=0;
non_critical_section();}}

//
//
// , TS
//
//,
//

. , . 0.
. . TS proc=common, common=1, .. common 0, , ,
. , 2 . , TS
proc=common, common=1. Common 1, .. , ,
. 2 . 1 . 2 TS, common=0, , ,
.
, TS: BTC, BTS, BTR. BTS (bit
test & set) : BTS Op, B. Op CF (carry ), B Op 1. , . 32, .. 5 ,
0 31, 4- .
L: BTS m, 1
; 1 m
JC L
; , ;
CALL critical_section
AND m, 0fffffffeh ;
, , ..
, . , , ,
, , , . ,
, , .
R Op, B , 0. BTC Op, B . .
TS . .
2 : L , .
, . , L
. . ,
L, H . L , .. , .
. . S , : P(S) V(S).

, . :
, . .
.
, ,
, . , .
. , ,
, 1. , N-. . ,
S 1. P V :
void P (int *S)
{(*S)--;
if (*S<0) block_process();}

//
// ,

void V (int *S)


{if (*S<0) activate_process();
(*S)++;}

// ,
//

:
void process(void)
{while(1)
{P(&S);
critical_section();
V(&S);
non_critical_section();}}

//
//
//

P(S), . 0
. 1 P(S). 1, . 2 , V(S). <0, .. ,
1 . 2 0.
: , .
. P V
. ,
- . TS.
mutex (mutual exclusion ). , ,
. 1 , int, 0 , 1 . 2 . , , mutex_lock. , . , ,
, , , , ,
mutex_unlock. - mutex, , , . :
mutex_lock:
bts mutex, 1
jnc OK
call thread_yield
jmp mutex_lock
OK: ret;

;
; ,
; ,
;

mutex_unlock:
move mutex, 0
ret;

TS : . , , . ( , ) , . . ? 2 . 1: , , , . 2:
. , .

-.
. - , . , , ,
. , , . , , , . , . , .
count. N - :
#define N 100
int count=0;

//
//

void producer(void)
{int item;
while (TRUE)
{item=produce_item();
if (count==N) sleep();
insert_item(item);
count++;
if (count==1) wakeup(consumer);}}

//
// ,
//
// -
// ,

void consumer(void)
{int item;
while (TRUE)
{if (count==0) sleep();
item=remove_item();
count--;
if(count==N-1) wakeup(producer);
consume_item(item);}}

// ,
//
// -
// ,
//

count
N
N
N
N
N-1
N-1
N-1
N-1
N-1
0
0

produce_item()
if (count==N) //true

if (count==0) //false
remove_item()
count-if(count==N-1) // true
wakeup(producer)
consume_item(item)
sleep() //###

if (count==0) //true
sleep() // ###

. ,
(count=N). , , , , . , , , ,
. . , ,
, , ,
. . , .
, ,
. .
, , .
, . , ,
, . N M , .
.
#define N 100
typedef int semaphore;
semaphore mutex=1;
//
semaphore empty=N;
//
semaphore full=0;
//
void producer(void)
{int item;

while (1)
{item=produce_item();
P(&empty);
P(&mutex);
insert_item(item);
V(&mutex);
V(&full);}}
void consumer (void)
{int item;
while (1)
{P(&full);
P(&mutex);
item=remove_item();
V(&mutex);
V(&empty);
consume_item(item);}}

//
//
//
//
//
//

//
//
//
//
//
//

N
N
N-1
N-1
N-1
N-1
N-1
N-1
N-1
N-2
N-2
N-2
N-2
N-1

mutex

full

empty

3 : , , .
, .

0
-1
-1
-1
-1
-1
0
0
0
0
0
0
0
0

1
1
1
0
0
1
1
0
0
0
-1
0
0
0

P(&full) // ###

P(&empty)
P(&mutex)
KC
V(&mutex)
V(&full)
P(&empty)
P(&mutex) // ###
=>
KC

=>
P(&mutex)
KC
V(&mutex)
V(&empty)

Windows. : , , , .
void InitializeCriticalSection (LPCRITICAL_SECTION lpCriticalSection)
void DeleteCriticalSection (LPCRITICAL_SECTION lpCriticalSection)
CRITICAL_SECTION.
, . :
void EnterCriticalSection (LPCRITICAL_SECTION lpCriticalSection)
void LeaveCriticalSection (LPCRITICAL_SECTION lpCriticalSection)
, .
EnterCriticalSection, . , .
.
, , .
.
HANDLE CreateMutex (
LPSECURITY_ATTRIBUTES lpsa,
BOOL bInitialOwner,
LPCTSTR lpName)
lpsa ,
. NULL . BInitialOwner ,
. TRUE , FALSE . LpName -, .
HANDLE . , NULL. -

. , .
HANDLE OpenMutex (
DWORD dwDesiredAccess,
BOOL bInheritHandle,
LPCTSTR lpName)
. MUTEX_ALL_ACCESS . .
.
BOOL CloseHandle (HANDLE hObject)
. ,
. .
, , . . :
DWORD WaitForSingleObject (
HANDLE hHandle,
DWORD dwMilliseconds)
hHandle , ,
. 0 . INFINITE - . WAIT_FAILED.
WAIT_ABANDONED, , ,
Release. , .
WAIT_OBJECT_0, , WAIT_TIMEOUT, -.
, , .. , , , , .
DWORD WaitForMultipleObjects (
DWORD nCount,

CONST HANDLE *lpHandles,

BOOL bWaitAll,
TRUE, , FALSE
DWORD dwMilliseconds)
-
, , bWaitAll=FALSE, WAIT_OBJECT_0
( WAIT_ABANDONED) , . bWaitAll=TRUE , , .. , .
DWORD MsgWaitForMultipleObjects(
DWORD nCount,
LPHANDLE pHandles,
BOOL fWaitAll,
DWORD dwMilliseconds,
DWORD dwWakeMask)
,
, , , . . WakeMask: QS_ALLINPUT , QS_HOTKEY - WM_HOTKEY, QS_INPUT , QS_KEY WM_KEYUP, WM_KEYDOWN,
WM_SYSKEYUP, WM_SYSKEYDOWN, QS_MOUSE - WM_MOUSEMOVE
(WM_LBUTTONUP, WM_RBUTTONDOWN, .), QS_MOUSEBUTTON (WM_LBUTTONUP,
WM_RBUTTONDOWN, .), QS_MOUSEMOVE - WM_MOUSEMOVE, QS_PAINT - WM_PAINT,
QS_POSTMESSAGE , , QS_SENDMESSAGE
, QS_TIMER - WM_TIMER. ,
WAIT_OBJECT_0 + nCount , .
DWORD SignalObjectAndWait(
HANDLE hObjectToSignal,
,
HANDLE hObjectToWaitOn,
,
DWORD dwMilliseconds,
-
BOOL bAlertaible)
, . Windows . (APC queue). . ,
. bAlertaible , , .
WaitForSingleObject.
BOOL ReleaseMutex (HANDLE hMutex)
. , TRUE, , FALSE, .
, 0, .
. :
HANDLE CreateSemaphore (
LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
-
LONG lInitialCount,
-
LONG lMaximumCount,
-

LPCTSTR lpName)
-
CloseHandle . , .
HANDLE OpenSemaphore (
DWORD dwDesiredAccess,
BOOL bInheritHandle,
LPCTSTR lpName)
OpenMutex. WaitForSingleObject, WaitForMultipleObjects . ( V)
BOOL ReleaseSemaphore (
HANDLE hSemaphore,

LONG lReleaseCount,
, , 0
LPLONG lpPreviousCount)
,
- . () , , . :
HANDLE CreateEvent (
LPSECURITY_ATTRIBUTES lpEventAttributes,

BOOL bManualReset,
TRUE
BOOL bInitialState,
, TRUE -
LPCTSTR lpName)
.
BOOL ResetEvent (HANDLE hEvent). OpenEvent . BOOL SetEvent (HANDLE hEvent)
. BOOL PulseEvent (HANDLE hEvent) ,
, .
OpenFileMapping, MapViewOfFile, UnmapViewOfFile, CloseHandle. , .
,
.
CreateXXX
, . GetLastError
ERROR_ALREADY_EXISTS, 0.
UNIX. POSIX pthreads , , : pthread_mutex_init, pthread_mutex_destroy,
pthread_mutex_lock, pthread_mutex_unlock. System V, .. Linux
. :
int semget (key_t key, int nsems, int semflg);
key 32 -, , nsems , semflg IPC_CREAT , , .
, , , IPC_EXCL. . 9 root, , . 1 . :
struct semid_ds{
struct ipc_rerm sem_perm; ,
struct sem* sem_base;
-
ushort sem_nsems;

time_t sem_otime;
(P V)
time_t sem_ctime;

}
sem_perm, sem_otime 0, sem_ctime .
:
struct sem{
ushort semval;

pid_t sempid;
,
ushort semncnt; -
ushort semzcnt;} -
key , .
( 100%)
key_t ftok(char* pathname, int proj_id);
, (/), (./). . int, 8 . . -1, - .


int semop (int semid, struct sembuf *sops, unsigned nsops)
semid , sosp sembuf, , ,
nsosp . . , .. ,
. sembuf :
struct sembuf {
unsigned sort sem_num;
short sem_op;
shot sem_flg}
sem_mun . sem_op = 0, ,
, sem_op>0, sem_op ,
, . sem_op<0, ,
, sem_op,
sem_op. sem_flg = IPC_NOWAIT,
. , ,
. , SEM_UNDO.
.
. ,
. , .
int semctl (int semid, int semnum, int cmd, )
3 4 . , , , , arg :
union semun {
int val;
struct semid_ds *buf;
unsigned short *array;
struct seminfo *__buf;}
:
IPC_STAT , arg.buf. semnum .
IPC_SET semid_ds , arg.buf. sem_ctime. semnum .
IPC_RMID , . semnum .
GETALL semval arg.array. semnum .
GETVAL semval semnum semid.
GETNCNT semncnt ( , ) semnum.
GETZCNT semzcnt ( , 0) semnum.
GETPID sempid (.. pid , ) semnum
SETALL semval arg.array. sem_ctime .
. semnum . .
SETVAL semval semnum. sem_ctime .
. .
. , ,

. 1, 0 ( GETNCNT, GETZCNT, GETVAL, GETPID).
UNIX .
int shmget (key_t key, int size, int shmflg)
size , .
void * shmat (int shmid, const void *shmaddr, int shmflg)
shmid , shmaddr , , NULL , . shmflg SHM_RDONLY
. , .
1.
int shmdt (const void *shmaddr)
shmaddr , shmat.
int shmctl (int shmid, int cmd, struct shmid_ds *buf)
, . Shmid , cmd , buf . IPC_RMID
, , . 1, 0.

Windows
4

UNIX
,




-

P(S)
1

V(S)


- P(S)


V(S)







. ,
, .. . 1974 . .
, , . , .
, , . , . .
,
. : . , , , . , , . ,
. . . , . , wait signal. ,
, wait - .
. ,
signal , . ,
. . , , signal, . .. signal
. signal , ,
. : , signal,
, . . . , signal , , . .. wait , signal.
Java. synchronized ,
, .
.. , C. Java:
public class ProducerConsumer
{static final int N=100;
static producer p=new producer();
static consumer c=new consumer();
static pc_monitor mon=new pc_monitor();
public static void main (String args[])
{p.start();
c.start();}
static class producer extends Thread
{public void run()
{int item;
while (true)
{item=produce_item();
mon.insert(item);}}

//
//
//
//
//
//
//
//
//

private int produce_item()


{}}
static class consumer extends Thread
{public void run()
int item;
while (true)
{item = mon.remove();
consume_item(item);}}
private void comsume_item(int item)
{}}
static class pc_monitor
{private int buffer[]=new int[N];
private int count=0, lo=0, hi=0;

//
//
//
//
//
//
//
//
//

public synchronized void insert (int val)


{if (count==N) go_to_sleep();
buffer[hi]=val;
hi=(hi+1)%N;
count=count+1;
if (count==1) notify();}

//
// ,
//
//
//
// ,

public synchronized int remove()


{int val;
if (count==0) go_to_sleep();
val=buffer[lo];
lo=(lo+1)%N;
count=count-1;
if (count==N-1) notify();
return val;}

//
// ,
//
//
//
// ,

private void go_to_sleep()


//
{try
{wait();}
//
catch (InterruptedException exc) {};}}}
ProducerConsumer . , . , . Count , lo , , hi .
lo=hi, , , count. Java , .
wait notify.
, . , , . :
-
-
- ,
- , ,
.
Volatile. , ,
. , , .
ANSI C volatile , .
. :
#define N 5
#define LEFT (i+N)%N
#define RIGHT (I+1)%N

//
// i
// i

#define THINKING 0
#define HUNGRY 1
#define EATING 2

//
//
//

typedef int semaphore;


int state[N];
semaphore mutex=1;
semaphore s[N];

//
// . .
//

void philosopher(int i)
{while(1)
{think();
take_forks(i);
eat();
put_forks();}}

//
//
//
//
//

void take_forks(int i)
{P(&mutex);
state[i]=HUNGRY;
test(i);
V(&mutex);
P(&s[i]);}

//
//
//
//
// ,
//

void put_forks(int i)
{P(&mutex);
state[i]=THINKING;
test(LEFT);
test(RIGHT);
V(&mutex);}

//
//
// ,
//
//
//

void test(int i)
//
{if(state[i]==HUNGRY && state[LEFT]!=EATING && state[RIGHT]!=EATING)
{state[i]=EATING;
//
V(&s[i]);}}
//
-. . , . -, - , , .
, , . .. , .
:
typedef int semaphore;
semaphore mutex = 1;
semaphore db=1;
int rc=0;
void reader(void)
{while(1)
{P(&mutex);
rc++;
if (rc==1) P(&db);
V(&mutex);
read_database();
P(&mutex);
rc=rc-1;
if (rc==0) V(&db);
V(&mutex);
use_read_data();}}
void writer(void)
{while(1)
{make_data();
P(&db);
write_database();
V(&db); }}

// rc
//
// -
//
//
//
// ,
//
//
//
//
// ( )
//
//
//
//
//
//
//

. . , . ,

.. , , . .

Rc

Db

Mutex

2 1 . 2 rc,
. 1 rc. 2 , . 1 . . . 1 , .
rc=2, , . 1 , ,
, rc=1. 2 , , . . , , db. 2 db, 1 mutex. db , 2 ,
, mutex, 1 . , . .

1
0
-1
-1
-1
-1
0
0
0
1
1
0
0
0
1

1
1
1
1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

0
0
0
1
1
1
1
2
2
2
2
2
1
1
1

0
0
0
1
1

-1
0
0
0
1

0
0
0
0
0

P(&mutex)
P(&mutex) // ###
rc++
if (rc==1) P(&db) // (true)
P(&db) // ###
=>
rc++
if (rc==1) // (false)
V(&mutex)
KC
P(&mutex)
rc-if(rc==0) // (false)
V(&mutex)

V(&mutex)

KC

if(rc==0) V(&db) // (true)

=>
KC

V(&mutex)
V(&db)

. , , n .
, , . , . , , , , , . . :
#define CHAIRS 5
// -
typedef int semaphore;
semaphore customers=0; // -
semaphore barbers=0;
// - ,
semaphore mutex=1;
//
int waiting=0;
//
void barber(void)
{while(1)
{P(&customers);
P(&mutex);
waiting--;
V(&barbers);
V(&mutex);
cut_hair();}}
void customer(void)
{P(&mutex);
if(waiting<CHAIRS)
{waiting++;
V(&customers);
V(&mutex);

//
//
//
//
//
//
//
//
//
//
//
// ,
//

P(barbers);
get_haircut();}
else {V(&mutex);}}

//
//
//

customers, .
Barbers, - . Waiting customers, , , ,
.
. , , =0.
, , , ,
, . customer , ,
, , burber, . . 2 . , , customers, . , . ,
, , , .
. .
. , .


. . . . . . . . . . .
UNIX Windows
( ). . ,
, , .
, , .
,
. , .
, , , .
, . ,
() . . , . ,
. , .
. , . . , ,
, . , .
, , .
: send , receive . , , , . . , send receive, receive,

. , , ,
. send receive ,
. , ,
.
.
:
- FIFO ().
- FILO ()
-
-
, , , . ,
. ,
. , , ( ).
. ,
.
- :
#define N 100
void producer (void)
{int item;
message m;
while (1)
{item=produce_item();
receive(consumer, &m);
build_message(&m, item);
send(consumer, &m);}}
void consumer (void)
{int item, i;
message m;
for (i=0; i<N; i++) send(producer, &m);
while (1)
{receive(producer, &m);
item=extract_item(&m);
send(producer,&m);
consume_item(item);}}

//
//

//
//
//
//
//
//
//
//
//
//

UNIX :
int msgget(key_t key, int msgflg); - ,
int msgsnd (int msqid, struct msgbuf* msgp, size_t msgsz, int msgflg)
ssize_t msqrcv (int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int msgflg)
int msqctl (int msqid, int cmd, struct msqid_ds *buf); -
Windows ( ). . ( ) CreateMailSlot,
ReadFile. ( ) CreateFile c WriteFile. , .
.
: ( , ). , . , . . , . . .
, . , ( ). ( , , ).
(pipe). / UNIX. , , , , , . - .
, , (FIFO). , . , . , 0, .. . , . . . , ,
.
UNIX pipe. 2 , . read write . ( |
). , :
- ;
- ;
- , .
(), named pipe.
. , , , .. .
.
Windows . CreateNamedPipe.
.
ConnectNamedPipe. CreateFile. ReadFile WriteFile . ,
PeekNamedPipe.
CreatePipe.
. .
, ,
, .
. , ,
, . -
D ,
barrier, .
, . B, , .
, , .


. . . . ,
. .
. . . .
, ,
, , . : , , . , . down(), up(). , 2 :
typedef int semaphore
semaphore rc1, rc2;
void process_A(void)
{down(&rc1);
down(&rc2);
use_2_resources();
up(&rc2);
up(&rc1);}

void process_B(void)
{down(&rc1);
down(&rc2);
use_2_resources();
up(&rc2);
up(&rc1);}

void process_C(void)
{down(&rc2);
down(&rc1);
use_2_resources();
up(&rc1);
up(&rc2);}

2 . . ,
1, . 1
, , , . ,
: 1, , 2. 2, 1. . .., . ,
, .
, 4 :
- . ,
- . , ,
- - . . - .
- . ,
,
.
:
, , ,
, .
, . ,

. :
, , ,
. . , , . , , .
4 :
- .
- : , - .
- ,

-
-. ,
. 100. 10 ,
12 . , 10 , . .
.

. .
.
, .
F ,
2, , ,
. ,

.
.
L.
, ,
, ,
.
, .
- ,
. ,

.
- .

() ,
, ,

,
, .
,
, ,
, .
,
.
,
. ,
D ,
3, .

.
. n P1Pn, m , Ei i, 1<=i<=m, {E1,Em} . . {A1Am} , i i, , .. . C ,
Cij j, i. , i , Pi. R , Rij j, Pi.

C11C12 C13 ...C1m


R11 R12 R13 ...R1m

C = C 21C 22 C 23 ...C 2 m R = R 21 R 22 R 23 ...R 2 m


C n1C n 2 C n3 ...C nm
R n1 R n 2 R n 3 ...R nm
j, ,
, ..
n

C
i =1

ij

+ Aj = E j

. ,
A<=B Ai<=Bi, 1<=i<=m.
.
, , ,
.. .
.
, .
.
.

. , , .

E={
A={

4
2

2
1

-
0
0
1
=
2
0
0
0
1
2

3
0
0
1
0

CD
1}
0}

2
0
R=
1
0
2
1

-
-
0
1
0

1
0
0

3 4 : , , , CD.
CD. CD , , R1>A. . , R3=A. , {2 2 2 0}.
2, 1.
R3 2 1 0 0 , 2 1 0 1, , 1
3 CD, 2. ,
1 3 .
, . . : .
. . .
, , , , . . , , .
. , . , .
, , .. . , .
, . , - , . ,
, . ,
. , ,
.
. , . , . , .
, . , , . , ,
, , . , , .
. ,
, .
. , , ,
. , , .
2 2 .
. .
I1 1, I2 .. I3 I4
. 2 I5 I7,
I6 I8 1. PQRST
. .
,
Q, ,
R, .
. . I1, 1. S. . I5,

2. ,
. , , . I1I2I5I6, . . , I4. .
.
, R -
. , , , .

9
4
7
10

3
2
2
3

3
4
2
1

3
0
2
5

3
0
7
0

3
0
0
7

3
2
2
3

4
2
2
2

4
4
2
0

4
0
2
4

, 3 , 10 . 9 , 4, 7. - 3,2,2 . 2 , , , 5 . 5 , , . 7 ,
. . .
2 . 2 , . 4
, . ,
.
. , , ,
. .. . , , .. .
:
- ;
- ;
- ;
- .
. , 1965
, . , . , (), (). , ,
, . , . . , , , . ,
. , . , , .
, .
, . , , , .
.

. . ,
, . . ,
. , , . , . , . . , .
. , , . ,
. ,
, . , , . , .
. , .
. . 1.
. , .
. 2. . -

, .
. . . (
, , , ), .
. , () . , . . , - . , ,
. . - .. . ,
.
. . , - .
. ,
. . , .


. . . .
. . .
. . . . .
TLB. . . - Pentium.
. . . .
, . Windows NT, UNIX
. , , -. - , , , - , , .
. , . ,
, ,
, .
, ..
.
.
, .
,
.
,

.

-
. .
.
: , , , , .
, . , . , .
.
, , . , , MS-DOS.
.
. , .
. .
, .
, ,
. , , . , . , , , , , .
, .
. , , , .
. . .

: ,
,
, .

. 1 . ,

, . 2 .
.
,
.
,
.
.

, .
: , ,
, , .. .
. .
. , , .
, ,
. ,
.
, . -
,
,
.
, .
.

.
? ,
, .
, ,
,
. : ,
.
.
.
, ,

. .
,
.
, . ,
. , . . , ,
. .
CDC6600. .

:

.

1,
0, .

N N . .
, , , , ,
. . .
, . ,
, . , , .
. .
, .
. , , . . . , , . . . ,
. ,
, .. . . .
. . , . ,
. . .

,
. .
. .
.
. . , . ,

.
: ,

,
, ( ),
,
,

.



. , , .
. , .
- , . ,
.
, . ,
, ( ).
. ,
.
. OS/2
v.1.
.
.
.
, , (-).
UNIX
. .
,
. 2.
,
. ,

,
. . , ,
, .
-. , .
. : ,
, . , , , .
. .

. , .
, 4, 32- .
. . . .
.
, . , 4 , 4 ,
1048576*4+1024+4.


4 .
, N
, (1

4 ). 32
. :
, ,
, ,
. ,

.
, -
.
,
.
,
. ,
. .
. , , .
, , .
, , . 2
Intel, 3 Sun SPARC, DECAlpha, Motorola. , , MIPS R2000
(RISC) , .
TLB. . , . ,
. , 64 . , .
TLB . TLB . , TLB. , . RISC- (SPARC, MIPS, Alpha, HP PA) . TLB . , ,
, . , TLB . ,
. ,
, . .. PowerPC, IBM HP.
, ,
. .
.
, , . , -
, . ,
.
. , , .
, . . .
.

, , ,
.
.
:
1. , .
.
2. , , . .
3. , , . . , , , , , ,
.
4. , , , , . , . , . , .
5. , ,
, . , .
6. , , , . , , , , .
7. , , , , .
8. , , ( ) , .
9. , , .
10.
, .
, , .
, , .
, .
, .
. . , ,
. , , , -. ,
, , .
, , , . .
- Pentium.
Pentium 16 ,
1 . 32 .
: LDT GDT. LDT
, GDT , . LDT
, , , .. GDT
, .
,

6
.
CS
, DS
- .

16
. ,

. 13
,
8 . 8 . 0
. , , .
, . , , , 0.

, . ,
48h 9 , 48h (9*8=72=48h) . GDT LDT , .
8 .
.
, ,
,
. ( 0),

,
, , . Limit 20 .
G (granularity ) =0, Limit 1 . 1
. 4 ,
232 . 32- Base , .. . Base Limit , , Base i80286
24 .
, . , .
, . 32 4 , 1 ,
. : 10 , 10
12 . , , 1024 32 , . ( ).
, 1024 32- . .
, .
4 . ,
TLB, - .
, , , Base=0 Limit . . , .. . OS/2.
Win32 32 :
( )
U P Cw Gl L D A Cd Wt O W V
31 12
11 10 9 8 7 6 5 4 3 2 1 0
2 ( ) . :
U , ,
P
Cw
Gl Global
L Large page , , 4 (2) Mb
D Dirty
A Accessed
Cd Cashe disabled
Wt Write through ,
O Owner ,
W Write , , ( )
V Valid ,
, , .. = 0, .
Windows PAE (Physical Address Extension). , 64 1024
64. Widows 128 - .
3- . 4 : 2 , 10 , 8
, 12 . 64 4 . 64 , 48 : 9,9,9,9 12 .

. Windows PFN (Page Frame Number),


. :
- ()(Active/valid). ,
, (PTE Page Table Entry).
- (Transition). , . -.
- (stand by) , .
. PTE ,
.
- (Modified). , .
. PTE , . .
- , (Modified no-write). , . .
- (free). , - . , .
- (Zeroed) .
- (ROM). (Windows XP)
- (Bad) . .
PFN , . , , , ; PTE,
, , , , , PTE, , , , .
4 , 2 (PSW). . , 3 , 2 , 1 0 . . .
, , CALL . , .. (call gate), . .., .
.
. ,
, . , .
Win 9x. 32 , . . MS DOS 7.X. , MSDOS.SYS BootGUI = 0, . MS-DOS
DOS. GUI Win 9x
, .. , , , . 32 , , 4 .
0-64
32- , , 16- .
64 - 4
. .
, 16 Win.
4 2
Win32. . .
, .
2 - 4
. API . .
2 3
dll, Win16, dll. 16 Win .
3 4
32 i8086 () . 0 . : windows, , , .
, Win9 -4 M, - , .

Windows, . , . .
SYSTEM.INI 386Enh.
PagingDrive = C:
PagingFile = C:\PageFile.sys
// // Win386.swp
MinPagingFileSize = 65536
//
MaxPagingFileSize = 262144
Win NT. . 0 . , , , .
0 64

64 2
Win32 .
, (clipboard),
DDE (Dynamic Data Exchange ) OLE (Object Linking and Embedding) .
2 dll 3 ,
, .
, -, ,
. , - .
2 - 4 .
(0 ). , .. , .
16 Win WOW (Windows on Windows),
16 , . OLE.
DOS.
. . . , . . VMM (virtual memory manager).
.
, , .
, VMM
, 2. FIFO, . + 12 .
, , .
. . , ,
, .


. . NRU, LRU, FIFO, NFU.
. . . Windows
2 : . .
, , . , ,
.
.
, .
.
, , ,
.
.
NRU . .
, , .
. , , ,
, , .
, . 4 :
0
1 ,
2 ,
3 .
NRU (not recently used) . , , , ,
.
FIFO. , , . . , , . .
. . 0, , ,
, , , . .. , . , FIFO. - .
,
FIFO 3 4:
0 1 2 3

0 1 2 3
0 1 2

0 1

1
1
0

0
0
3
2

1
1
0
3

4
4
1
0

0
4
1
0

1
4
1
0

2
2
4
1

3
3
2
4

4
3
2
4
9

3 0 1 4 0 1 2 3 4
3 3 3 4 0 1 2 3 4
2 2 2 3 4 0 1 2 3
1 1 1 2 3 4 0 1 2

0 0 0 1 2 3 4 0 1


10
,
, , .. . .
, : (m,r)M(m+1,r), m-
, r- , M . .. , r , , m , , m+1 . . , LRU .

0
0

, . -

2
2
1
0

. , .
, . 0, ,
. 1 , .

LRU last recently used- . ,


. ,
, .
. , . . NxN, N
. . i, i 1,
i 0. , , .
NFU. not frequently used . . , . ( )
. . , -
, ,
, , .
. : , ,
.
R 0-5
101011
110010
110101
100010
011000

10000000
11000000
11100000
11110000
01111000
00000000
10000000
11000000
01100000
10110000
10000000
01000000
00100000
00010000
10001000
00000000
00000000
10000000
01000000
00100000
10000000
11000000
01100000
10110000
01011000
10000000
01000000
10100000
01010000
00101000
. ,
. , , .
, - .
, ,
. ,
. . , , . ,
: ,
. , k . , , . ,
.
WSClock. , .
. . , ,
. , R M, . R 1, , , .
R 0, , , . , . , , ( )
:
?
, . .
Windows , .
: , , . , .. . 2 : LRU FIFO. 50 345 . SetProcessWorkingSetSize Increase Scheduling Priority. Windows Server 2003,
, . 1984 8192 Windows .

-
-. . . . . . . . -. UNIX. . .
. Windows. . .
-
, , . , . :
.
, . :
- ., ,
- , ,
- , , ,

-
- ,
-
: 1. . : ,
, . 2. - . : , , , , . 3. . , . 4. . . 5. . .
: , - , , , , - , . .
. ,
, ,
. , ,
.
, , .. , . 2 . 1.
, IN REG, PORT OUT PORT, REG. , . 2. , .. , (,
Motorola 680x0). , , x86 0
64, 640 1 . : IN OUT; ,
,
; . : , ,
; ,
; , , . x86 PCI .
, -, PCI.
, DMA (direct memory access), / . DMA, . ,
, . DMA ,
, , , (
0), . . DMA,
, .
. , , DMA. , , ..
, , DMA. ,
, . , ,
, . , DMA
, , .

, . DMA .
, , . DMA , DMA, , .
, , . DMA , (, SPARC), DMA
MMU . MMU , . , DMA . DMA ,
. , DMA, , , , , .
2 : () ( ). , . , , .
-, , .
, . , Win9x, NT
, 100 .
.
, , -
. . .
. 2 . .

. .

.

. 3 .
.

. ,
,
. 4. .
.

,

.
.
. , , , .
. , (). , . .
, , ,
. , ,
. . ,
, . . . Win . , , -. . Win 9x System.ini [vcache] MinFileCache ( ), MaxFileCache ( ), ChunkSize. Win NT 4, 2000, XP .
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Mamagment IOPageLockLimit
.
64. 4 (16 ) , 128
+ 64 4 . x86 512 , 512 .
, , , . . . ,
. ,
.

.
. , UNIX , .. .
. . , .
, .
, .. , . , , . , . . , , . ,
. , UNIX.
, .
. -, , .. : , , , , , , , . , ,
. , , , , . : , ,
. . :
- get , put
- read, write - , seek ,
- ioctl ( )
- open
- close , ,
- poll
- halt
. , . UNIX mem
, null , , zero , . .
UNIX 2 , , , ,
. u ,
, . , . , , , . bdevsw cdevsw
:
struct bdevsw {
struct cdevsw {
int (*d_open)();
int (*d_open)();
int (*d_mmap)();
int (*d_close)();
int (*d_close)();
int (*d_segmap)();
int (*d_strategy)();
int (*d_read)();
int (*d_xpoll)();
int (*d_size)();
int (*d_write)();
int (*d_xhalt)();
int (*d_xhalt)();
int (*d_ioctl)();
struct streamtab* d_str;

} cdevsw[];
} bdevsw[];
. . .
, . , dkopen, dkclose ..
. nodev(),
ENODEV. , , .
nulldev(), 0.
( )
. , .. . .
, , .
. . ,
.

.
, , . /dev . , , .
stdin, stdout, stderr . . , , , . , .
mknod(path,
mode, dev), , IFBLK IFCHR ,
.
Windows . . 2 : . Win
:
- (VDD). 16 MS DOS. API,
.
- . - ,
. , ,
USB .
:
- . ,
- PnP . , PnP. ..
, ,
- , PnP. . , . PnP.
, Windows Driver Model (WDM), , PnP, WMI. PnP . :
- . . ,
PnP .
- . .
PnP.
- . , .
. . .

, . . PnP . , PnP . , PnP .
,
. . . \Device , WinAPI.
.
HKLM\SYSTEM\CurrentControlSet\Services. PnP. Start :
- PnP, Start ,

- , Start 0 ( ). ,
- , , , Start 1 ( ).
- PnP, , Start 2 ().
- PnP, , Start 3 ( ), ,
.
. PnP Root,
. , PnP HAL. HardWare Abstraction Layer Hal.dll,
, Windows. , , , .. , -

. HAL , , , .
, PCI, . HAL
, Setup .
, , .
, PnP , . .
PnP .
:
- , .
PnP. ,
- PnP , Start. .
- PnP , .
.
- .
, ,
HKLM\SYSTEM\CurrentControlSet\Enum. , . \Device\HarddiskX\DRX, .
, , IoReadPartitionTable IoReadPartitionTableEx.
, , .
-. , , ,
. :
- FCFS (First Come First Served) , .
- SSF (Shortest Seek First) .
, . , . .
- Scan (). ,
. .
- Look. , , .
- NSS (Next Step Scan) . , , . ,
.
- C-Scan . , , , .. .
. .
100 . 63 . : 23, 67, 55, 14, 31, 7, 84, 10.
FCFS: 63 => 23 => 67 => 55 => 14 => 31 => 7 => 84 => 10;
40+44+12+41+17+24+77+74=329
SSF:
63 => 67 => 55 => 31 => 23 => 14 => 10 => 7 => 84;
4+12+24+8+9+4+3+77=141
Scan: 63 => 55 => 31 => 23 => 14 => 10 => 7 => 0 => 67 => 84;
8+24+8+9+4+3+7+67+17=147
Look: 63 => 55 => 31 => 23 => 14 => 10 => 7 => 67 => 84;
8+24+8+9+4+3+60+17=133
C-Scan: 63 => 55 => 31 => 23 => 14 => 10 => 7 => 0 => 99 => 84 => 67;
8+24+8+9+4+3+7+99+15+17=194


. . . .
. Windows. .
UNIX. GPT. LDM. . [1: 146-156; 2: 444-445,
776-778, 888-890; 7: 267-306, 659-674]
. . , , . UNIX ,
. . 0

MBR master boot record
.


. MBR 512
. MBR 01be
4 16 . :
1 (0 , 80h-)
1
- 2
- 1
1
- 2
2 4
2 4
( ) . 4 .
BIOS MBR-, , , , . ( )
. , .
. : ,
. , i, , . :
00h 17h Hidden NTFS, HPFS
82h LinuxSwap, Solaris
A5h Free BSD
01h FAT12
1bh Hidden FAT32
83h LinuxNative
A6h Open BSD
02h Xenix root
1ch Hidden FAT32 LBA
84h OS/2 C: Hidden
A9h Net BSD
03h Xenix /usr
1eh Hidden FAT16 LBA
85h Linux Extended
abh Apple booter
04h FAT16 (<32Mb)
35h OS/2 JFS
86h FAT16 Volume Set
bbh OS Selector
05h Extended
3ch Partition Magic
87h NTFS Volume Set
beh Solaris 8 boot
06h FAT16
42h LinuxSwp
8bh FAT32 Volume Set
C2h Hidden Linux Swap
07h NTFS, HPFS
43h LinuxNat
8ch FAT32 LBA Volume Set
C3h Hidden Linux Native
0ah OS/2 Boot Manager
4dh QNX 4.x first
8dh Free Fdisk FAT12
D1h Multiuser DOS FAT12
0bh FAT32
4eh QNX 4.x second
90h Free Fdisk FAT16 (<32Mb) D4h Multiuser DOS FAT16(<32Mb)
0ch FAT32 LBA
4fh QNX 4.x third, Oberon 91h Free Fdisk Extended
D5h Multiuser DOS Extended
0eh FAT16 LBA
52h CP/M
92h Free Fdisk FAT16
D6h Multiuser DOS FAT16
0fh Extended LBA
63h UNIX
97h Free Fdisk FAT32
D8h CP/M 86
11h Hidden FAT12
64h NetWare 2.x
98h Free Fdisk FAT32 LBA
ebh BeOS
14h Hidden FAT16 (<32Mb) 65h NetWare 3.x
9ah Free Fdisk FAT16 LBA
F2h DOS Secondary
16h Hidden FAT16
70h DiskSecure Multi-boot 9bh Free Fdisk Extended LBA
fdh Linux RAID
2 MBR 55aah, ..
0 1, . 2
.
(primary) (extended).
4.
. DOS,
(hidden).

,

.
, (LDT),

MBR.
. BIOS,
. .
BIOS.
, -, ZIP-, ..
-.
MBR. . ,
( ) . . , BIOS. BIOS,
, .
, .
BootMagic, PowerQuest. :
- ;
- , .. ;
- BIOS;
-
, BIOS;
- FAT16/32,
;
- ;
- MBR;
- ;
- .
, fdisk Microsoft.
PartitionMagic PowerQuest. :
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- .
MS-DOS Win 9x , . :\ ..
. 1, D 2 .. Win NT/2000/XP
, ntldr, .
. . Ntldr . boot.ini , , .
(- , , 2 3 , ). , . boot.ini:
[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operation systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS=Microsoft Windows XP Professional /fastdetect
C:\=Microsoft Windows
1 , , 2 . 3 . 1 (multi) , Int 13h. .. ,
, Int 13h. : multi(W)disk(X)rdisk(Y)partition(Z). W- , 0, X 0,
Y , (0-3 ATA , 1-15 SCSI), Z , 1. (SCSI) ,
/, Ntbootdd.sys. : scsi(W)disk(X)rdisk(Y)partition(Z). W
, , ( 0-15), Y logical unit number (LUN) , , 0, Z , 1. (signature)
, ,
ntbootdd.sys . GUID,
MBR . : signature(V)disk(X)rdisk(Y)partition(Z). V 32
, X- , Y 0, Z- .
, 7,8 , BIOS Int13h
, BIOS Int 13h.

Ntldr x86, .. ,
. . Ntldr (
, ), , ,
. boot.ini,
(MS DOS, Windows Me, Windows 9x), bootsect.dos,
bootsect.dos MBR, . XP/Server
2003/2000, ntdetect.com BIOS, hal.dll,
ntoskrnl.exe, bootvid.dll. ,
, , , , , ntoskrnl.exe.
, , smss.exe. , winlogon.exe. . , services.exe, , , . Winlogon , explorer.exe . , .
. Linux . , IDE master, hda.
hdb. Master hdc ..
MBR, . , 5.
-, .
boot . , , .
-. , ,
, main, . , .. , , .., , , , .
. 0 , , 1 (init) 2 . Init
, , etc/ttys, .
, getty,
bin/login, , .
EFI (Extensible Firmware Interface) Intel -, , , . . , EFI, Intel IA64. Windows EFI,

MBR.
EFI

GUID (GUID Partition Table - GPT). 64 , CRC , , , GUID. - MBR, , GPT.


2 , 2
. .
. MBR GPT .
Windows 2000 (LDM Logic Disk Manager).
, LDM , . ,
MBR GPT, ( , ),
LDM. MBR GPT , LDM . LDM-
1 . 4 :
(private header), , , , , Private Header. LDM GUID.
16 . 128 .
4 : partition, component, volume, disk.
, , , , .
, . GUID, ,
. GUID. -

( ),
, RAID .


. . . . .
. . . . . , , i-. . ,
. . . . . . . . .
:
-
- ,
-
, . . , .. . , . . , , , , . , , . ,
, .
. , . , .
.
, . . , 8- . ,
255 . (UNIX) ,
(MS-DOS) . Windows MS-DOS , NT
NTFS. , . MS-DOS 3 , UNIX . .
. ..
, .
. 1. . . . . .
, . 2.
, .
. 2. , . . ,
. ,
.
. , UNIX Windows
. , . , . UNIX . , , ,
, .. . ASCII . . , (UNIX), (MS-DOS).
ASCII , - .
, , , ,
.
. , , . : ( ), ,
( , ), , , , ,
, ASCII/, , ( ), , , , , , , ,
, .
. ,
, .
map unmap. ,

. , .
, seek write.
. , . . . -, :
- , .. , , . , .
, .. , , , . .
, .
. , . , ,
. D_RO. . , , .
, ,
. , , .
.
4
0

6
1
-1
2
8
3
1
4
7
5
6
3
7
2
8
-1

,
,
. FAT
file
allocation
table.

, . , , . i- ,
index node , . , i- , . , i-. , i-
, , ,
. , , . , .
, , .
UNIX, HPFS, NTFS . i-
.
, , . . . , . . : . : . . .
. . . .. . , .
, , ,
, . . . ...
.
. , . , i-. , ,
. . , i-, , . i-.
. 255 , . ,

. , . ,
, , . ,
, .. . . .
, , ,
. , .
. . - . 0 - N-1, N -. , - , ,
, , -. : , , .
. , .
. , . . , ,
.
, . ( i-)
. ,
(link). , . . , , . . , , , , ,
, , .
. ,
, , . , , .. .
. , , . , , .
. , . ,
. , 40 512 10 .
, ,
. .
N- . N-1 ,
.
. , ,
, . Mount, umount. , Windows
, , ,
. UNIX . usr, bin, home, dev .. mnt.
. .
, . , , . ,
i-, .
, . UNIX fsck, Windows scandisk. Fsck . ,
, . , .
. i-. 1. , . ,
, , . . - 0 , . .
- , . ,
. , , . , . . ,
, . . .
, , .
, i-. .

i- , , ,
, , . , i- , , ,
, .
. , .
, , . , i-,
.. . NTFS,
Ext3FS, ReiserFS . , , , ,
, . .
.
. , ,
. .
- . , , , , . , . ,
,
-. - . , .
(FIFO, , LRU).
, , i-, , , , , . , , LRU, . , , . , , ,
i-, , .
. UNIX sync, . ,
update, sync. MS-DOS ,
.
:
Create). Delete. Open . Close. .
Read. Write. Append. ..Seek. Get_attributes. Set_attributes. Rename.
Windows. CreateFile, CloseHandle. ReadFile, WriteFile. ReadFileGather WriteFileGather - . DeleteFile. CopyFile. CreateHardLink NT5 (2K,
WS2003, XP) ! !, UNIX. SetFilePointer. , , - , hEvent OVERLAPPED, ReadFile, WriteFile. GetFileSize. SetEndOfFile . FindFirstFile, FindNextFile, FindClose. GetFileTime.GetFileAttributes. GetTempFileName . LockFile (LockFileEx)
. UnlockFileEx.

( )

.
.

, - , - -

. Create. Delete. OpenDir. . CloseDir.ReadDir . Rename. Link. . , . Unlink. Windows: CreateDirectory, RemoveDirectory.SetCurrentDirectory, GetCurrentDirectory. SetVolumeMountPoint ,
. DeleteMountPoint.


FAT. FAT. . FAT16, FAT32. . HPFS.
HPFS, . NTFS. . NTFS. CD (ISO9660). . - . Joliet. UNIX System V s5fs. . . Berkeley FFS. Linux Ext2fs. proc. LFS
FAT MS-DOS, CP/M.
x86, . MS-DOS 1.0 FAT , CP/M. MS-DOS 2.0
, . FAT : . . : (boot record), , FAT, , 512 . FAT16 1 ,
FAT32 3 .

, FAT16 (32)
,

00h 3
jump 3eh, 2 , 3 NOP
03h 8
, .
0bh 2
, ,
0dh 1

0eh
2
( FAT32 32)
10h 1
FAT
11h 2
(FAT32 - 0)
13h 2
, 32 Mb, 0 (FAT32 - 0)
15h 1

16h 2
FAT, (FAT32 - 0)
18h 2

1ah
2

1ch
4
, .
20h 4
( FAT16 32 Mb)
FAT16
FAT32
24h 1
00- , 80h- 24h
4
FAT
25h 1

28h
2

26h 1
29H
2ah
2

27h 4

2ch
4
1
2bh 11

34h
2
.
36h 8

36h
12

3eh

1feh 2
( aa55h)
, . ,
. ,
( 512 ) .
. :
,
FAT12,
FAT16, Mb
FAT32, Tb
0,5
2
1
4
2
8
128
4
16
256
1
8
512
2
16
1024
2
32
2048
2
:
FAT16 (FAT32)
0-10
8+3
11
: , , , , ,
12
( NT, )
13

14-15
( )
16-17
( )
18-19
( )
20-21
( FAT)

22-23

24-25

26-27
FAT ( )
28-31

5 , 6 , 5 , 5 , 4 7 (-1980). , , .
0,
. ,
, . FAT32 . 8.3 ( ), 6 , ASCII, ~1. , ~2, .. , . 8.3 . , 8.3. 13 unicode, :
-
1

5 (10 )

,
1

,
1

, 1

6 , (12 )

0,

2 ,
(4 )

67
26-30
31-36
37-38
2
13-17
18-23
24-25
1
0-4
5-10
11-12
8.3
0fh,
. . , , +64. , + 260 800. . MS-DOS
, , .
. , .. MS-DOS
. Win98 255/256. Win98
FAT, , .
FAT , .
, FAT.
2 (4 FAT32) ,
,
, .
0 1 ,
, 2.
FAT ,
. FAT 0,
. fff0-fff6
, ffF7,
ffFF.
FAT12 4096 2 . MS-DOS 4
, FAT12 64. FAT16 16
, 64 . FAT16
128. . 2 FAT16 8. Win95 FAT12 FAT16
MS-DOS, 8.3. Win 95 OEM SR2
FAT32. 28 . 2,
() . FAT32 .
, , , 512 . 4.
FAT12 , Windows . () 16 FAT format DiskManagement Windows
FAT16, FAT12. FAT 2 16 .
Windows : Ntfs.sys (NTFS), fastfat.sys (FAT), cdfs.sys ( CD-ROM, ISO-9660 Joliet), udfs.sys (UDF OSTA Optical Storage Technology Association. OSTA UDF ,
DVD, ISO-13346 , ISO-9660), raw FSD, ntosKrnl.exe. , ,
. , ,
. ,
- . ,
, . . ,
. , . .

HPFS High Perfomance File System . OS/2.


IBM Microsoft
. , . , 4
, , , , .
. : ;
;
. . HPFS : (boot block 0-15, ,
, BIOS, ), (super block, 16, , , , , , ), (17 , , ,
, , ), 1, 1, 2, 2, 3, 3, 4,
4 .. ,
,
. 8 . 16.
. , 1 ,
, . , 15 , , , . , ,
. , 2 32 ,
( ). . , ,
4 . 8 .
, , 40
. . , HPFS . , 2 , .
, .
FAT N/2, - N , Int[log2N]
. , , , , ,
, , .
. , , . , . HotFix. , .
, .
. ,
, . , , , . , , HPFS. , .. ,
32 .
,
.
, , . OS/2 ,
: FIFO, , , , . . , . . , .
1 255. .
, HPFS .
NTFS :
- . . , .
- . NTFS . , , ,
, .

POSIX. (Portable Operating system for computing environments) .


1988 1990 . , AT&T UNIX System
V Berkeley Standart Distribution UNIX.
. , .
. 512 64 .
8.3 FAT.

( ) 16 (264). , ,
NT, , .
. .
. NTFS , 2
4 , 512 64. 2 . 12% MFT master file table. , MFT .
MFT MFT


16

MFT

MFT , . MFT
1 , - . MFT 1 4 . 16 , , MFT. 16 . MFT
. NTFS , $.
$MFT MFT
$MFTMirr 16
$LogFile
$Volume , ..
$AttrDef
$.
$Bitmap
$Boot
$Quota ( NTFS 5.0)
$Upcase
MFT , , , , .. MFT , , .
, MFT, . 64 . , MFT
, , MFT
. , . ..
MFT, , .. . , . Windows 2000 . , , . , . 1
16 . NTFS .
. Read Only, Hidden, Archive, System,
, ,
. - , , MFT,
, MFT.
. - Unicode. -. , POSIX
8.3.
.- , .
.
. - . ,
. ,
, , ( )
.
HPFS , HPFS
OS/2 OS/2 - Windows NT.

MFT , , , . ,
, . .
HPFS , .
, MFT, . Unicode, .. , 255 .
, . ,
, MFT, . .
NTFS , : , , , , , . :

NTFS


No access


list
Read, Execute

read
Read, Execute
Read, Execute
add
Write, Execute

Add & read
Read, write, Execute
Read, Execute
change
Read, write, Execute, delete
Read, write, Execute, delete
full control

-

NTFS
Read
, , , , ,

Write
, -
, , - , ,

, - , Execute
, - ,

De-

lete
-

Change
Permissions

Take
OwnerShip
NTFS . , . 16 . 1 , , .
MFT 2 , , 0 , . 0 , . NTFS - , , DES. NTFS
CD - ISO9660. 1988. ,
. , CD , . , ( ) 2352 . , ..
2048 .
. . 16 ,
. . , . (32 ),
(32 ), (128 ), (128 ).
, ,
. , ,
. , , . ,
. . . .

, . . 10 12 . Pentium ( ),
SPARC ( ). (1 ) ,
, . 8 (32- )
. , (8 ) . (7) , 1900. . , , . .
. 4 , .
2 16.
. , , , , . , , . 8 , . . ,
. , .
, . .
, 2 , . , . 8. 3
. 1 : 8.3, 8.0, . 2 . 31 . 3 .
, .
.
UNIX CD_ROM, . - .
. ,
. : PX POSIX,
, , .. PN , ,
/dev. SL , . NM
, . CL,PL . RE .
, .
. TF . , , . UNIX
CD_ROM, .
Microsoft. Joliet.
Windows, . : 64
, UNICODE (.. 64 128 ), , .
UNIX. UNIX . Sun Microsystems
vnode/vfs, . UNIX , .. , FIFO, ,
vnode/vfs , . , ,
, .
S5FS. System V File System. , UNIX .
. 512 , 2. ,
. . , . . i- 64 .
i-. i- . i- , ,
. i- . , , .
, i- , i-.,
, i-. , -
. , .
. . . , .
i-, . i- , . i- :

di_mode 2 , ..
di_nlinks 2

di_uid 2

di_gid 2

di_size 4

di_addr 39

di_gen 1
( )
di_atime 4

di_mtime 4

di_ctime 4

4
, ,
.. 9 ,
.. addr 13
: 3 .
10 .
, 11
, ,
, .. .
, 12
, ,
,
, , 13
. -
, ,
,
,
0.
.
16 . 2 i-, , 14 .
216=65535 i-. 14 ,
0. , , i-.
.
, , i- ,
, . .
FFS Fast File System Berkeley. ,
.
. 2 . ,
. , .. i- . , .
. .
4, 8 512 1 s5fs. . . ,
, 1,2,4 8 , 512 .
, . . , .
. , , i-. .
i-, , , , , 0,
255 . 512- , 1
. . FFS SVR4.
Linux Ext2fs. FFS. , ,
,
, , .
,
i-
, ..
, , i-
. i-. 1 . i-, 128 12
3 4 , 3. ,
, . 1 .

. ,
, , . , .
.
, Linux proc. /proc , PID
. , , , .. . , Linux, /proc. .
c . LFS. Log-structured File System ,
. . ,
, . . ,
, ,
. , UNIX : i- , , i- . LFS
. , . , , , , ,
. i-, , , . . 1 ,
100%. i-,
, , j j i-. . , , , .
, i- . i-, ,
i- . , ,
, .
, .
, , , .

2.

. . , , .
. . .
. . . SQL. 4GL. Java, HTML

1. .., .., .. . . ., , 2004.


2. .. : , , . . . ., , 2004.
3. .. . . ., , 2003.
4. .. . . ., , 2003.
5. .., .. . , -, 2005.
6. .. : , , , . . ,
, 2006.
.
- ..
. , Intel Pentium F8. , 0F A2.
2 E4 < >. 1 AX 40, BX
41. , , , -, , -, , ,
. . , . . , , . .
, Assembler, . , :
CLC
F8

CPUID IN AL, < > INC AX INC BX INC <>


MOV <>, <>
0F A2
E4 < >
40
41
...
, . - Assemblera, , . . Translate .
.
,
, ,
. 2
.
.
. ,
,
. C, C++, Pascal. Assembler . - , . .
, , , , . LEX, YACC. ,
, .
Visual Basic. , .
,
. .

. .
.
.
, .
. ()
() , , .

. ,
. , ,
. ,
. . . , . . , . , , , .

,

.

.

, , . ,
. , , . , ,
.. .
. . , , ..
- , . . . ,
, .
, : ,
, . ( ) , . (.. ) , . , . , . ,
, . , . . , , . . , , . . . .
, . ,
.
, , . .
, .
, . 4GL (Fourth Generation Languages)
RAD (Rapid Application Development).

.
.. . , ,
, .
:

. ,
.
HTML SQL.
SQL structured query language ,
. , ,
, , , ,
.., , .
SQL
. , Money
Salary 10, 100:
Delphi
SQL
While not (Money.Eof) do begin
If Money[Salary]>100 then begin
Money.Edit;
Money[Salary]:= Money[Salary]+10;
Money.Post;
End;
Money.Next;
End;

update money
set salary=salary+10
where salary>100

SQL , , , PL/SQL Oracle, ( ), -


, .
SQL , . 4GL , , . , . , , ,
. 4GL
.
, , .. MS Access,
, . ,
. , ,
. , .
. . .
, , ,
. Vusual C, .
,
.
Java, HTML.
Internet , Inet : ,
. - . HTML (HyperText
Markup Language ). HTML, , HTML . HTML
, , . , .
.
. , (, ), HTML . CGI common gateway interface ISAPI internet server
aplication programming interface -. CGI
Web-. ,
stdin. stdout. , . CGI ,
- -. UNIX PHP, Java, C, Forth .,

Windows VisualBasic, C/C++, Delphi .. CGI ISAPI , , . . ,


HTML CGI ISAPI . HTML
, . Perl (Practical Extraction and Report Language), PHP (personal home pages), ASP (active server pages). PHP ASP
HTML , ,
, , HTML,
.
Java HTML .
. Java , JVM, Java-. JVM -
. Java- , JVM-.
, . JVM . Java ,
.. . Java Script Java, HTML .
JVM . Java , .
VBScript Visual Basic.
Flash,
.
. , 4GL . , , , .
, . , , Asm Java. , , . .


. . , , , .
. . , . . . , , . , . . -. .
. . . .
.
( ), , .
, , .. () .
. A.
, . ()
.
, , .. , , . ,
, . =,
, .
||. = => ||=||. , ==. => ||=||+||.
, - . : ,: . : ()=().
,
. , =. () = =. . R . RR=. R=R-1=R-1. ,: ()R=RR. n - n , n, n0. () . 0=. : ||=0.
: ==. R=.
n0: n=.
.0=. A: (A), x, x A. ( ): ={a,b,c}, *={, a, b, c, aa, ab, ac, bb, ba, bc, cc, ca, cb, aaa, aab, aac,}.

A==

UA

, 0={}, A1=A. -

n =0

: A+= 1 2 =

UA

. A*= A+{}.

n =1

L : L(A)
: L(A)*. .
. .
. L(A) L(A): L(A) L(A), L(A): L(A). .. L() L(A). L(A) L(A) :
L(A)=L(A), L(A)L(A) L(A)L(A). L(A): L(A) L(A): L(A).
. L(A) L(A) : L(A)L(A), L(A){}=L(A){}.
. , . ,
( !!!): L{}={}L=L; L=L=. L :

L*= L0 L1 L2 =

UL

, L0={}. n1 Ln=LLn-1=Ln-1L.

n =0

L. L: L =L L =

UL

n =1

L+=LL*=L*L, L*=L+{}.
. .
:
;
( );
.
( ) . (, ) , . ,
, , .
, , . , , , , . , , .. , .
, . .

, , .. . , . ,
.. . , . . , . , . :

.
, . ,
. . ,
, , .
, , ,
.. .
.
L *. ,
. , =
* = .
, .
. , .
Z , Z, , L .. :
.
, .
. , , .
.. , .
, , .
() (, ). -> -
. 2 , , , .
, G, L(G). G G , : L(G) = L(G). ,
: L(G){}=L(G) {}.
G(T, N, P, S), T -
( G), N
( ), P () >, (NT)+, (NT)*, S () , SN, ,
G. : NT=. ..
. .
NT ( ) G. , , . ,
, . , . ,,,
a,b,c. ,,,
G (), =12 =12 ()P.
G (*), =0,1,,n=:
i+1i, i=0,1,,n-1, =. =0,1,,n n 0
G. n (=). ,
, +. * . ,
. , ,
.
L, G ,
: L(G)={ | S*, T*}
. G=<N,T,P,S>, N={S,D,C}, T={>,<,=,!}, P={CD=, CS, D!, D=, DS, S<, S>}, S={C}.
.. ()
, . . , .
-
. .
. () , , -

. | , .
::=, . , <>. :
<compare>::=<double>= | <single>
<double>::= ! | = | <single>
<single>::= < | >

. , () (),
(). , , .
. , :
. , . , , .
. , /1 :
1. []
2. , {}
3. ,
4. ( ,
),
5. , .
( ):

< double >=

<compare>::=
=
<double>::=2

< sin gle >


< sin gle >

<
>

<single>::=

<
[=]
>

<compare>::=
! =
=

. . Pascal. ,
. .
:
- . ,
- . ,

- . ,
- .
- . , .
.
. .
, .
. ()

,
.
,
.
.
.


.
.
, . . .
, . :
-
- ,
-
-
- .
. :
-
-
- .
, ,
.

, , .
,
, .. , , .

( ).
. . ,
, , .

. :
- .
- .
- .

. ,
, .
, , . .
.

.
.
,
.
.

, .
. ,
. .
.
, . . , .. .
. . . L(G) , , .,
L(G). ,
L(G) .


. - - .
. . . .
. . .
.
.
,
. 4 :
0. . :
G(T,N,P,S), V=NT : , V+, V*. . . , 0, , . .
1. - () . G(T,N,P,S), V=NT :
1212, 1, 2V*, N, V+. ,
, . 1, 2 , .
. G(T,N,P,S), V=NT
: , , V+, ||||. .
, . , , , . ,
.
2. - () . G(T,N,P,S), V=NT :
, N, V+. . .
1, 1=2=V*, .. .
. G(T,N,P,S), V=NT : , N, V*.
.
. .
3. () . : . G(T,N,P,S), V=NT : , , ,N, *. ..
, . G(T,N,P,S), V=NT
: , , ,N, *. . , , , , .
, .
: , , , ..
.
, : : G(T,N,P,S), V=NT : t, t, ,N, t, :
G(T,N,P,S), V=NT : t, t, ,N, t. ,
, . . S, S - . S .
, , , .
.
. . 0
, 3 .
.
, .
, ,
, . , L G1 (
1) G2 ( 2), 2.
0. . , 0. . , , . , .
( .. ).
1. - ().
. - .
2. - (). .
3. . .
(, ), () ..

.
.
0 , , ..
. ,

.
. .

() ( ). . .
.
. . ( ).
.

( ). . ,
. .
.
. G=<N,T,P,S>, N={S,D,C}, T={>,<,=,!}, P={CD=, CS, D!, D=, DS, S<, S>}, S={C}.
1 (): 1212, 1, 2V*, N, V+. . 1=2=V*, A={}N, ={D=}V+=(NT)+.
. . G 1.
. , , V+, ||||. . {}V+,{D=}V+, |D=|=2 > ||=1. .
2 (): , N, V+. . A={}N, ={D=}V+=(NT)+. .
3 (). , , ,N, *. , , ,N, *. .
A={}N, B={D}N, ={=}*. .
. a, a, ,N, a. . A={}N, B={D}N, a={=}. S. :
A={}N, B={S}N, a={}. .
1. L(G), G, .
2. L(G) , . L(G) ,
L(G)\ -. L(G) -, 0.
, :


. .
. . . . .
.
, . , . :
- ,
, ;
- ,
, ;
- ,
.
, . : , , : , , , .
,
.
- , . (< >,<>),
, , , , , .
, , - , (
) , , - .
.
. .
. :
long factorial (long x)
{if(x==1) return x;
return factorial(x-1)*x;}
:

( )
( )
01.
02.
03.
/
/
/
1
long
1
(
1
factorial
2
if
2
)
2
x
3
return
3
{

4
==
04.
5
;
/
6
1
1
7
*
8
}

( ):
(01,1)(03,1)(02,1)(01,1)(03,2)(02,2)
(02,3)(01,2)(02,1)(03,2)(02,4)(04,1)(02,2)(01,3)(03,2)(02,5)
(01,3)(03,1)(02,1)(03,2)(02,6)(04,1)(02,2)(02,7)(03,2)(02,5)(02,8)
,
.
, ,
. ,
, ,
, ..
, .
, , x+++y
: (++)+ +(++).
.
:
- (), ;

- (), .
.
- . , .
. , . , , . , , .
, .
.
: ,
. L
.
PA*, QA*. :
PQ PQ={pq | pP, qQ};
P* P*={p | pP};
:
1. - ;
2. {} ;
3. {a} aA;
4. P Q , PQ, PQ, P* - ;
5. .
.
.
. , , ,
. :
1. 0 , ;
2. - , {}
3. , {a} aA;
4. p q , P Q, p+q (p|q), pq, p* - , PQ, PQ, P* .
: , (), ().
, , =, . ,
. :
{01}
{0,1} {1}*
{0,1}*
{0}{1}*
{0,{1}*} {0,{1}{0}*}
{0,1}*{011} {{a}*{b},{c}{a}*}
*
*
*
*
*
*
01
0|1
1
(0|1)
01
0|1
(0|(1(0 )))=0|10
(0|1)*011
a*b|ca*
. 01
0,1
1,111 0,1,010 0,01,011 0,1,1111 0,1,10,10000
011010011
b,ab,aaab,c,ca,caaa
.
/
/

1
10
|=|
(*)*=*
2
11
0*=
|=
3
12
|(|)=(|)|
|0=
4
13
()=()
**=*
5
14
(|)=|
*=*
6
15
(|)=|
(*|*)*=(**)*=(|)*
7
16
==
()*=()*
8
17
0=0=0
(*)**=(|)*
*
*
*
9
18
=| = |
(*)*=(|)*|
. :
=|;
=|; ,A*, A.
. .., , ,
, . 1 *:
|=(*)|=(*)|=(*)|=(*|)=*=X, 2 X=*. =; =
=*, X= .
P


, , , , .
: , , , , ,
( ). .. L1 L2 ,
L1*, L1L2 L1L2 .
. * .
. ( ) L : L, ,,V*, >0 | =, ||p,
0<||p, = i, i0, L.

, - .
, , , . , L={0m1n | m,n0} , L={0n1n | n1} .
, :
- . L1(A) L2(A). .
- . L(A) *.
.
- . L(A). , , ..
, L(A).
( ) , ( ) .
.
G(T,N,P,S),
G(T,N,P,S). . :
1) AN, N=N{A}. .. G G.
2) aT, T=T{a}. .. G G.
3) piP: a1, a1, A,BN, a1T P=P{pi}. .. G .
4) piP: a1a2an, n>1, A,BN, akT, k=1,2,,n
N=N{A1,A2,,An-1}, P=P{AkAk-1ak, k=1,2,,n, An=A, A0=B}. n-1 n .
5) piP: a1a2an, n>1, AN, akT, k=1,2,,n
N=N{A1,A2,,An-1}, P=P{AkAk-1ak, k=1,2,,n, An=A, A0=}. n-1 n .
6) piP: B, , A,BN P=P{pi}. .. G .
7) piP: B, BC | BCa | Ba | B, A,B,CN, aT P=P{AC}|{ACa}|{Aa}|{A} . P=P\{B}. .. .
8) piP: , BA | BAa, A,B,N, AS, aT P=P{B}|{Ba} . P=P\{}. .. .
9) 7,8 , 7
10) S=S. .. .
B, 6-9 . ,
.
. , .
G({/,*,a,,},{S,C,K},P,{S}), - (chr(13)), - (chr(10)), a
, /,*,,. , .
P:
S C*/ | K
C /* | C/ | C* | Ca | C
K // | K/ | K* | Ka
1. N={S,C,K}
2. T={/,*,a,,}
3. P=P{ C C/ | C* | Ca, K K/ | K* | Ka }
4. a1a2an, N=N{A1,A2,,An-1}, P=P{AkAk-1ak, k=1,2,,n, An=A, A0=B}.
4.1. S C*/ : N=N{A1}, AkAk-1ak, An=A, A0=B : A1A0*, A2A1/ A1C*, SA1/ P=P{ A1C*, SA1/}.
4.2. S K : N=N{A2}, P=P{ A2K, SA2}.
4.3. C C : N=N{A3}, P=P{ A3C, CA3}.
5. a1a2an, N=N{A1,A2,,An-1}, P=P{AkAk-1ak, k=1,2,,n, An=A, A0=}.
5.1. C /* : N=N{A4}, AkAk-1ak, An=A, A0= : A1A0/, A2A1* A4/, CA4* P=P{ A4/, CA4*}.
5.2. K // : N=N{A5}, P=P{ A5/, KA5/}.
6-9. B,
10. S={S}
G=({/,*,a,,}, {S,C,K,A1,A2,A3,A4,A5}, P, S)
P:
S A1/ | A2
C C/ | C* | Ca | A3 | A4*
K K/ | K* | Ka | A5/
A1 C*
A2 K
A3 C
A4 /
A5 /

G=({/,*,a,,}, {S,C,K,A,B,D,E}, P, S)
P=
S A/ | B
C C/ | C* | Ca | D | E*
K K/ | K* | Ka | E/
A C*
B K
D C
E/

, .
: ; , , :
1. : N={X1, X2, Xn}, : Xi Xj, Xi , Xi, Xj N, T*.
.
2. :
X1 = 01 + X111 + X221 + + Xnn1
X2 = 02 + X112 + X222 + + Xnn2

Xn = 0n + Xn1n + X22n + + Xnnn


ji : ji = (1 | 2 | | m) | pP: Xi Xj1 | Xj2 | | Xjm , i>0, j0, X0 = .
, ji=. .
3. :
3.1. i=0;
3.2. i++; Xi Xi = Xiii + i , i =i0 + Xi+1ii+1 + + Xnin
3.3. Xi = iii* =(i0 + Xi+1ii+1 + + Xnin)ii* ,
Xi = ii*i. , i=n, Xn , .. ii i
Xm.
3.4. k | i<kn, Xk Xi iii*.
3.5. i<n, 3.2.
3.6. i-3.7. k | i<kn, Xi Xk .
3.8. i>1, 3.6.
3.9. X, , .
. .
G({[,],n,i,0},{R,L,K},P,{R}), n 1..9, 0 , x[0], i .
P:
R L]
L L0 | Ln | Kn
K i[ | R[
1. R=X1, L=X2, K=X3; P: X1 X2]; X2 X20 | X2n | X3n; X3 i[ | X1[ .
=
+ X1 + X2]
+ X3
2. X1 = X2]
=
+ X1 + X2(0+n)
+ X3n
X2 = X20 + X2n + X3n
= i[
+ X1[ + X2
+ X3
X3 = i[ + X1[
3.2. i=1. X1 = X2]; 11=; 1= X2];
3.3. X1 = X2].
3.4. 2 . X3 = i[ + X1[ = i[ + X2][
3.2. i=2. X2 = X20 + X2n + X3n = X2(0+n) + X3n; 22=0+n; 2= X3n;
3.3. X2 = 222* = X3n(0+n)*.
3.4. X3 = i[ + X2][ = i[ + X3n(0+n)* ][ .
3.2. i=3. X3 = i[ + X3n(0+n)* ][ = X3n(0+n)* ][ + i[ ; 33= n(0+n)* ][ ; 3= i[ .
3.3. X3 = 333* = i[ (n(0+n)* ][)*.
3.7. i=2. X2 = X3n(0+n)* = i[ (n(0+n)* ][)*n(0+n)*
3.7. i=1. X1 = X2] = i[ (n(0+n)* ][)*n(0+n)*]
3.9. 1. 1: =
i[(n(0|n)*][)*n(0|n)*].


. . . . . . . . . . LEX
.
: M (Q, V, , q0, F), Q , V ( ), - ,
VQ Q: (a,q)=R, aV, qQ, RQ; q0
, q0Q; F , FQ, F.
, : aV, qQ (a,q)=R, RQ.
q0. . , . ,
.
M (Q, V, , q0, F) V+, ,
fF. L(M), , . , . .
,
, (p,a)=q, aV, p,qQ (p,q), . ,
, ,
. : M({H,A,B,S},{a,b},,H,{S}). :
(H,b)=B, (B,a)=A, (A,b)={B,S}. ,
,
, ,
.
.
M (Q, V, , q0, F) , aV,
qQ: (q,a)={r}, rQ (q,a)=, ..

. .
.

. G(T,N,P,S), L(G). M(Q,V,,q0,F), L(M)=L(G). 2 . 1. G G. 2. M(Q,V,,q0,F) G(T,N,P,S). :


1) Q=N{H}. ,
H.
2) V=T. .
3) pi P: At, AN, tT (H,t)= (H,t){A}. H .
4) pi P: ABt, A,BN, tT (B,t)= (B,t){A}. B .
5) q0=H. .
6) F={S}. S.
.
G=({/,*,a,,}, {S,C,K,A,B,D,E}, P, S)
= { S A/ | B; C C/ | C* | Ca | D | E*; K K/ | K* | Ka | E/; A C*; B K; D C; E / }
1. Q={S,C,K,A,B,D,E,H}
2. V={/,*,a,,}
3. E / (H,/)= (H,/){E}.
4.1. S A/ (A,/)= (A,/){S}; S B (B, )= (B, ){S}
4.2. (C,/)= (C,/){C}; (C,*)= (C,*){C}; (C,a)= (C,a){C}; (D, )= (D, ){C}; (E,*)= (E*,){C}
4.3. (K,/)= (K,/){K}; (K,*)= (K,*){K}; (K,a)= (K,a){K}; (E,/)= (E,/){K}

4.4. (C,*)= (C,*){A}; (K,)= (K,){B}; (C,)= (C,){D}


5. q0=H
6. F={S}
S
C
K
A
B
D
E
H

C
K
S
K
E
/
C,A
K
C
*
C
K
a
D
B

S
C

, , .. (,*)={C,A}.
,
. .
.
. G(T,N,P,S), L(G). M(Q,V,,q0,F), L(M)=L(G). , , . :
1) Q=N{H}. ,
H.
2) V=T. .
3) pi P: At, AN, tT (A,t)= (A,t){H}. A H.
4) pi P: AtB, A,BN, tT (A,t)= (A,t){B}. A B.
5) q0=S. S.
6) F={H}. .
. M(Q,V,,q0,F), L(M). G(T,N,P,S), L(G)=L(M).
:
1) T=V. .
2) N=Q\{q0}. .
3) Ai = q0 | (Ai,t)={B1, B2,, Bn}, n>0, BkQ, k=1,2,..,n, tV P=P{Bkt}. .
4) Ai q0 , Ai Q| (Ai,t)={B1, B2,, Bn}, n>0, BkQ, k=1,2,..,n, tV P=P{BkAit}. .
5) F={F0} S={F0}. , .
6) F={F1, F2,, Fn}, n>1 N=N{S}, P=P{SF1 | F2 || Fn}. ,
S, .
. M(Q,V,,q0,F), L(M). G(T,N,P,S), L(G)=L(M). :
1) T=V. .
2) N=Q. .
3) Ai Q: (Ai,t)={B1, B2,, Bn}, n>0, BkQ, BkF, k=1,2,..,n, tV P=P{AitBk}. .
4) Ai Q: (Ai,t)={B1, B2,, Bn}, n>0, BkQ, BkF, k=1,2,..,n, tV P=P{Ait}. .
5) Ai Q: (Ai,t)={B1, B2,, Bn}, n>0, BkQ, BkF, k=1,2,..,n, tV, (Bk,t)={C1, C2,, Cm} CjQ, q=1,2,..,m, tV
P=P{AitBk}. , .
6) S={q0}
.
M({S,C,K,A,B,D,E,H},{/,*,a,,},,H,{S})
S
C
K
A
B
D
E
H

C
K
S
K
E
/
C,A
K
C
*
C
K
a
D
B

S
C

1. T={/,*,a,,}
2. N={S,C,K,A,B,D,E,H}
3.1. (C,/)={C} P=P{C/C}; (C,*)={C,A} P=P{C*C | *A};
P=P{CaC}; P=P{CD};
3.2. P=P{K/K | *K | aK | B};
3.3. P=P{D};
3.4. P=P{E/K | *C};
3.5. P=P{H/E}
4. (A,/)={S} P=P{A/}; (B,)={S} P=P{B}.
5. S , A/S; BS.
6. S={H}
P: {A/; B; C/C | *C | *A | aC | D; K/K | *K | aK | B; D; E/K | *C; H/E;}

. .
M(Q,V,,q0,F) M(Q,V,,q0,F):
1) V=V;
2) q0= q0;
3) Q={q0};
4) qiQ (qi, vj)= {(qk,vj)}=qij, qkqi, j=1,2,..,|V|; Q=Qqij; ;
5) qiQ, qkF, qkqi F=F{qi}; .
. .
1. V={/,*,a,,};
2. q0={H};
3-4.
H E K C B C,A D S C,S
H E K C B A D S G
C,S
C
G
C
/ E K K C
/ E K K C
C K C,A
C,A
C,A
C K A
A
A
*
*
K C
C
C
K C
C
C
a
a
B
D
D
D
B
D
D
D

S
C
S
C

5. F={{S},{CS}};
F={S,G};
.
.
:
. qQ M(Q,V,,q0,F)
, V+
q. :
1) Q={q0};
2) qiQ: (qi, vk)=qj, k=1,2,..,|V|; Q=Qqj ..
, ;
3) =(qi,vk), qiQ; ..
;
4)
F=FQ.
q, qQ n-, n0, , V*, ||n, . 0- F Q\F. , R(n), R(0)={F, Q\F}. :
1) n=0, R(n)
2) n=n+1. R(n): R(n)={ri(n): {qiQ: aV, (qi,a) rj(n-1)}}. .. ,,
n-1 .
3) R(n)R(n-1), 2.
, .
. ({A,B,C,D,E,F,G}, {0,1}, , A ,{D, E})
F G
A B C D E
C B D
F
0 B
E D G
F
1 C D E
1. Q={A};
2.1. Q=Q{B,C}
2.2. Q=Q{D,E}
2.3. Q=Q{B,C,D,E}
4. F={DE}{A,B,C,D,E}={D,E}
1.
2.
3.

R(0)={{A,B,C},{D,E}}
R(1)={0:{A},{BC},{D,E}; 1:{A},{BC},{D,E}};
R(2)={0:{A},{BC},{D,E}; 1:{A},{BC},{D,E}}.

, ,
. , , .
, . LEX. . - , (
) , .
.

-. -
- . -. . . . . . - (
, -, ).
, . :
-
-
- , .
. , . .
-. ) L -: L, ,1,,2,V*, >0 | =12, ||p, 0<|12|p, =
1i2i, i0, L.
, - . ,
L={0n1n| m,n1} , L={0n1n2n| n1} .
G(T,N,P,S) (), :
- V(TN{})
- , S
- , t(T{})
- AN, V1,V2,,Vn,
n>0, Vi(TN{}), G A V1,V2,,VnP
.
.. .
G({/,*,a,,},{S,C,K},P,{S}), P:{S C*/ | K; C /* | C/ | C* | Ca | C; K // | K/ | K* | Ka}
//a :
.
,
,
. ,
,

, ..
.
, :
G({(,a,)},{S},P,{S}), P:{S S+S | S*S | (S) | a | b}, a*b+a.
:
SS+SS*S+Sa*S+Sa*b+Sa*b+a

SS*Sa*Sa*S+Sa*b+Sa*b+a .
. .
. , . .. ,
, , .
:
SSS |
SSS |
SS | S |
SS | SS |
, . , , ..
.
, () (),
().

, : AN: A*A, V+.


: AN: A*, V+.
() AN: A* A, ,V+.
G(N,T,P,S) AN (), :
S*Ab, ,b,T*. .. .
A , AS : S*A, ,V*. ..
.
G(N,T,P,S) -, (-)
A, AN, S, S .
G(N,T,P,S) , A*A, AN. AB, A,BN.
.
. , , .

( ) - ,
. ,
, -, . -, , . : , , -, .
, .. .
G(N,T,P,S) G=(N,T,P,S) , P
: ABC | Aa, A,B,CN, aT; S, L(G) S . :
1. T=T, N=N, S=S;
2. piP: ABC, Aa, S, A,B,CN, aT P=P{ABC | Aa | S};
3. piP: ABa, A,BN, aT N=N{A}, P=P{ABA, Aa};
4. piP: AaB, A,BN, aT N=N{A}, P=P{AAB, Aa};
5. piP: AA1A2Ak, k>2 N=N{B1, B2,,Bk-2, A1, A2,Ak}, P=P{Bi-1AiBi}, i=1,2,,k-1, B0=A, Bk-1 =Ak,
AkN, Ak=Ak, Ak, P=P{Ak Ak} Ak
. G=({a,q,w},{X,D,E},{XDaqEw},X).
1. T={a,q,w}, N={X,D,E}, S=X; 5. K=5, N=N{B1, B2, B3, A1, A2, A3, A4, A5}={B1, B2, B3, D, A2, A3, E, A5};
P=P{B0A1B1, B1A2B2, B2A3B3, B3A4B4}={XA1B1, B1A2B2, B2A3B3, B3A4A5}=
{ XDB1, B1A2B2, B2A3B3, B3EA5}, P=P{ A2A2, A3A3, A5A5}={ A2a, A3q, A5w}
G=({a,q,w},{X,D,E, B1, B2, B3, A2, A3, A5},{ XDB1, B1A2B2, B2A3B3, B3EA5, A2a, A3q, A5w },X)
. : Ab, AN, bT, N*
S, L(G) S . :
1. G=G;
2. N={A1,A2,,An} , pP: AiAj, Ai,AjN, V* , i<j; k=|N|-1;
3. AkAj, Aj1|2||m AjN, dV* Ai1|2||m; Aj, d , d=1,2,m
Aj. k--; k!=0, .3
4. piP: Ab12m , AN, bT, iV AbY1Y2Ym , iT, N=N{Yi}, P=P{Yii}; iN, Yi=i ,
. G={{*,n},{S,A,B},{SB*A, Bn | A*B, An},S}
2. S1B2*A3, B2n | A3*B2, A3n; k=3-1=2;
3. B2n | A3*B2 B2n | n* B2; k=1
3. S1B2*A3 S1n* A3 | n* B2*A3; k=0;
4. A3n; B2n; B2n*B2B2nY1B2, N=N{Y1},P=P{Y1*}; S1n*A3S1nY1A3; S1n*B2*A3S1nY1B2Y1A3
G=({*,n},{S,A,B,Y},{ An; Bn | nYB; Y*; SnYA | nYBYA}, S)
.
Yi. , .
.
1. Y0=; i=1;
2. AN: (A)P, (Yi-1T)* Yi = Yi{A}; ..
, , ;
3. YiYi-1, i=i+1 2
4. N=Yi; T=T; S=S;
5. P=P{pi}, pi: A, A,(TYi)*; ,
. Yi.
, . , ,
.
1. Y0={S}; i=1;
2. AYi-1: (Ax)P, ,V* , xV Yi = Yi{x} Yi-1; .
, , ;
3. YiYi-1, i=i+1 2
4. N=NYi; T=T Yi; S=S;
5. P=P{pi}, pi: A, A,Yi; ,
. G({a,b,c},{A,B,C,D,E,F,G,S},P,S); P: { SaAB | E; AaA | bB; BACb | b; CA | bA | cC | aE; EcE | aE | Eb |
ED | FG; Da | c | Fb; FBC | EC | A; GGa | Gb;}
:
1. Y0=; i=1;
2-3.1. A, (Y0T)* = {a,b,c} Y1 = Y1{B,D}; Y1Y0; i=2;
2-3.2. A, (Y1T)* = {B,D,a,b,c} Y2 = Y2{A,B,D}; Y2Y1; i=3;
2-3.3. A, (Y2T)* = {A,B,D,a,b,c} Y3 = Y3{S,A,B,C,D}; Y3Y2; i=4;
2-3.4. A, (Y3T)* = {S,A,B,C,D,a,b,c} Y4 = Y4{S,A,B,C,D,F}; Y3Y2; i=5;
2-3.5. A, (Y4T)* = {S,A,B,C,D,F,a,b,c} Y5 = Y5{S,A,B,C,D,F}; Y4=Y5;
4. N=Y5={S,A,B,C,D,F}; T=T={a,b,c}; S=S={S};
5. P={ SaAB; AaA | bB; BACb | b; CA | bA | cC; Da | c | Fb; FBC | A;}
:
1. Y0={S}; i=1;

2-3.1. AY0={S}: Ax, ,V*, xV Y1 = Y1{a,A,B}{S}={a,A,B,S}; Y1Y0; i=2;


2-3.2. AY1={a,A,B,S}: Ax, ,V*, xV Y2 = Y2{a,A,B,b,C}{a,A,B,S}={a,b,A,B,C,S}; Y2Y1; i=3;
2-3.3. AY2={a,b,A,B,C,S}: Ax, ,V*, xV Y3 = Y3{a,A,B,b,C,c}{a,b,A,B,C,S}={a,b,c,A,B,C,S}; Y3Y2; i=4;
2-3.4. AY3={a,b,c,A,B,C,S}: Ax, ,V*, xV Y4 = Y4{a,A,B,b,C,c}{a,b,c,A,B,C,S}={a,b,c,A,B,C,S}; Y4=Y3;
4. N=NYi={A,B,C,S}; T=T Yi= {a,b,c}; S=S={S}
5. pi: A, A,Yi; P={ SaAB; AaA | bB; BACb | b; CA | bA | cC; }
-. Yi.
, -. , .
1. Y0 ={A: (A)}; i=1;
2. A: (A)P, Yi-1* Yi = Yi-1{A}; . , , ;
3. YiYi-1, i=i+1 2
4. N=N; T=T; S=S; P=P\{A};
5. piP: AX11X22Xnn, XjYi P=P{AW11W22Wnn: Wk={{Xk , XkYi}{Xk, XkYi}}\
{A, AA;}}. .. , Yi
, , .
6. SYi N=N{S}, P=P{S | S}, S={S}; . L(G), ,
. G({a,b,c},{A,B,C,S},P,S); P:{SAaB | aB | cC; AAB | a | b | B; BBa | ; CAB | c;}
1. Y0 ={B}; i=1;
2-3.1. (AB), BY0* Y1 = Y0{A}={A,B}; Y1Y0; i=2;
2-3.2. (CAB; AAB; AB), A,BY1* Y2 = Y1{A,B,C}={A,B,C}; Y2Y1; i=3;
2-3.2. ( CAB; AAB; AB), A,BY2* Y3 = Y2{A,B,C}={A,B,C}; Y3=Y2;
4. N=N={A,B,C,S}; T=T={a,b,c}; P={SAaB | aB | cC; AAB | a | b | B; BBa; CAB | c;}
5.1. SAaB, A,BY3; P=P{SAaB | Aa | aB | a};
5.2. SaB; BY3; P=P{SaB | a};
5.3. S cC; CY3; P=P{ScC | c};
5.4. AAB; A,BY3; P=P{AAB | A | B}\{AA};
5.5. AB; BY3; P=P{AB};
5.6. BBa; BY3; P=P{ BBa | a};
5.7. CAB; A,BY3; P=P{ CAB | A | B};
P={ SAaB | aB | cC | Aa | a | c; AAB | a | b | B; BBa | a; CAB | c | A | B;}
6. SY3
. X Yx,
.
1. XN:
2. Yx0={X}; i=1;
3. pkP: AB, AYxi-1 Yxi= Yxi-1{B}; .. , , ;
4. Yxi Yxi-1, i=i+1, 3;
5. Yx=Yxi\{X};
6. N=N; T=T; P=P\{AB}; S=S;
7. piP: A P=P{B}, AYB, BA; -.
. G=({+,-,/,*,a,b},{S,T,E},P,S); P={SS+T | S-T | T; TT*E | T/E | E; E(S) | a | b};
1.1. Ys:
2.1. Ys0={S}; i=1;
3-4.1.1. ST, SYs0 Ys1= Ys0{T}={S,T}; Ys1Ys0; i=2;
3-4.1.2. ST, TE, S,TYs1 Ys2= Ys1{T,E}={S,T,E}; Ys2Ys1; i=3;
3-4.1.3. ST, TE, S,TYs2 Ys3= Ys2{T,E}={S,T,E}; Ys3=Ys2;
5.1. Ys= Ys3\{S}={T,E};
1.2. YT:
2.2. YT0={T}; i=1;
3-4.2.1. TE, TYT0 YT1= YT0{E}={T,E}; YT1YT0; i=2;
3-4.2.2. TE, TYT1 YT2= YT1{E}={T,E}; YT2=YT1;
5.2. YT= YT2\{T}={E};
1.3. YE:
2.2. YE0={E}; i=1;
3-4.2.1. YE1= YE0
5.2. YE= YE1\{E}=;
6. N=N={S,T,E}; T=T={+,-,/,*,a,b}; P={SS+T | S-T; TT*E | T/E; E(S) | a | b}; S=S={S};
7.1. SS+T | S-T; SYS, SYT SYE;
7.2. TT*E | T/E; TYS; P=P{ ST*E | T/E};
7.3. E(S) | a | b; EYS, EYT; P=P{ S(S) | a | b; T(S) | a | b };
P={ SS+T | S-T | T*E | T/E | (S) | a | b; TT*E | T/E | (S) | a | b ; E(S) | a | b }

. - , ,
- . ,
. . .
1. AiN, i=1,2 |N|: ..
2. pkP: AiB, BV, V*, Ai B P=Ppk; N=NAi; .. Ai ,
;
3. pkP: AiAi, V* : Ai=Ai1 | Ai2 || Aim | 1 | 2 | p, j, 1jp, j=Ak, ki P=P{Ai1 | 2 ||
p | 1Ai | 2Ai || pAi; Ai1 | 2 || m | 1Ai | 2Ai || mAi;}; N=N{Ai, Ai}; .. Ai Ai
4. i=|N|, , .9;
5. i=i+1; j=1;
6. pkP: AiAj, V* P=P{Ai1 | 2 || q: {Aj1 | 2 || q}P}\pk; .. ;
7. j=i-1, .2;
8. j=j+1; .6
9. S=S;

G({a,b,c,d,z},{S,A,B,C},P,S); P:{ SAa; ABb; BCc | d; CAz | a;}


1. i=1; Ai=S;
2-3.1. SAa P=P{SAa}; N=N{S};
4.1. i4
5.1. i=2; Ai=A; j=1; Aj=S;
6.1.1. P AS
7.1.1. j=i-1, .2
2-3.2. ABb P=P{ABb}; N=N{A};
4.2. i4
5.2. i=3; Ai=B; j=1; Aj=S;
6.2.1. P BS
7.2.1. ji-1
8.2.1. j=2; Aj=A .6.
6.2.2. P BA
7.2.2. j=i-1; .2

P={ SAa }

P={ SAa; ABb }

2-3.3. BCc | d P=P{ BCc | d }; N=N{B};


P={ SAa; ABb; BCc | d }
4.3. i4
5.3. i=4; Ai=C; j=1; Aj=S;
6.3.1. P CS
7.3.1. ji-1
8.3.1. j=2; Aj=A .6.
6.3.2. {CAz}P, {ABb}P P=P{CBbz}\{CAz}
P={ SAa; ABb; BCc | d; CBbz | a}
7.3.2. ji-1
8.3.2. j=3; Aj=B .6.
6.3.3. {Bbz}P, {BCc | d} P P=P{ C{Cc | d}bz = Ccbz | dbz}\{ Bbz }
P={ SAa; ABb; BCc | d; C Ccbz | dbz | a }
7.3.3. j=i-1; .2
2-3.4. C Ccbz | dbz | a P=P{ Cdbz | a | dbzD | aD; Dcbz | cbzD }; N=N{C,D};
4.4. i=4; .9
P={ SAa; ABb; BCc | d; Cdbz | a | dbzD | aD; Dcbz | cbzD }
9. S=S;
N={S,A,B,C,D}


. -. . . . - . . -. -.
. . . S-
-, G(N,T,P,S), A,
AN, V*. () . - : R(Q,A,Z,, q0, z0, F), Q , A , Z
, AZ, - , Qx(A{})xZ P(QxZ*), q0Q , z0 Z , FQ .
- , ,
. , . : , , (q,,).
(q,a, z)(q,,), (q,)(q,a,z), q,qQ, aA{}, A*, zZ{}, ,Z*.
, , , .
. , , . () -. ,
(=z).
(q0, , z0), A*, (q,,) qF, Z*.
() , ,
, . , , . R1 R2
, L(R1)=L(R2). ,
, ( (q,,)).
, . , , .
Qx(A{})xZ*. . - , .
-, .
,
. :
1. (q,a,z) 1 : (q,a,z)={(q,)}, Z*, (q,,z)=;
2. (q,a,z)=, (q,,z) 1 (q,,z)={(q,)}, Z*;
3. (q,a,z)=, (q,,z)=;
, -. , , .
- -. , , -. , -, . ,
-.
- 2 . . ( ). ,
. ( ).
2 : ,
-. .
() , .
.
.
. .
, .
, , , . ,
, . , () .
:
1. . , . , . ..
.
2. , :

1 | 2 || n. ? . :
, , ; 2-3 , ;
, -
, ; .
3. . , . , .
, , ( ).
. -,
. , . , , . ,
, , , ,
, , , , . , , . , . , ,
- .
-. -, , .. . , . ( ). . : G=(T,N,P,S). M=(Q,A,Z,, q0, z0, F), , L(M)=L(G).
, . . . - . .
1. Q={q}; q0=q; F=; Z=TN, A=T, z0=S.
2. piP: X, XN, V* (q,,X)=(q,,X)(q,).
. , , ..
3. aT (q,a,a)=(q,). ,
.
. G=({+,(,),i},{E,F},P,E). P={EF+E | F; F(E) | i};
1. Q={q}; q0=q; A={+,(,),i}; Z={+,(,),i,E,F}; z0=E; F=;
2. 1. (q,,E)=(q,F+E); 2. (q,,E)=(q,F); 3. (q,,F)=(q,(E)); 4. (q,,F)=(q,i);
3. 5. (q,+,+)=(q, ); 6. (q,(,()=(q, ); 7. (q,),))=(q, ); 8. (q,i,i)=(q, );
(i), , :
(q,(i),E)?1 (q,(i),F+)?3 (q,(i),(E)+)6 (q,i),E)+)?1 (q,i),F+)+)?3 (q,i),()+)+)?(q,i),F+)+)?4 (q,i),i+)+) 8 (q,),+)+)?(q,i),F+)+)??2
(q,i),E)+) (q,i),F)+) ?3 (q,i),(E))+) ?8 (q,),)+) 7 (q,,+) ?(q,i),F)+) ?4 (q,i),i)+)
?(q,i),F)+)
(q,i),E)+) ?(q,(i),F+)?4 (q,(i),i+) ?(q,(i),F+)??2
(q,(i),E) (q,(i),F) ?3 (q,(i),(E)) 6 (q,i),E)) ?1 (q,i),F+)) ?3 (q,i),()+)) ?8 (q,),+))?(q,i),F+)) ?4 (q,i),i+))
?(q,i),F+))
?3 (q,i),()))
?(q,i),E)) ?2 (q,i),F))
?4
8 (q,),)) 7 (q,,)
(q,i),F))
(q,i),i))
, .. . , ? , .
(q,(i),E)?2 (q,(i),F) ?3 (q,(i),(E)) 6 (q,i),E)) ?2 (q,i),F)) ?4 (q,i),i)) 8 (q,),)) 7 (q,,)
. .
, .
. . ,
, . , , . .
. , . - -. , , -

, , . .
-.
-, . , ( #), . . , . :
- G=(T,N,P,S). M=(Q,A,Z,, q0, z0, F), , L(M)=L(G).
1. Q={q, r}; q0=q; F={r}; Z=TN{#},A=T,z0=#.
2. piP: X, XN, V* (q,,)=(q,,)(q,X).
,
3. aT (q,a,)=(q,a). ,
- .
4. (q,,#S)=(r,). .
. G=({+,(,),i},{E,F},P,E). P={EF+E | F; F(E) | i};
1. Q={q,r}; q0=q; A={+,(,),i}; Z={+,(,),i,E,F,#}; z0=#; F=r;
2. 1. (q,,F+E)=(q,E); 2. (q,,F)=(q,E); 3. (q,,(E))=(q,F); 4. (q,,i)=(q,F);
3. 5. (q,+,)=(q,+); 6. (q,(,)=(q,(); 7. (q,),)=(q,)); 8. (q,i,)=(q,i);
4. 9. (q,,#E)=(r,).
(i), :
(q,(i),#) 6 (q,i),#)) 8 (q,),#(i)4 (q,),#(F) 2 (q,),#(E)7 (q,,#(E)) 3 (q,,#F) 2 (q,,#E) 9 (r,). , .. . .
. -. , . . . : -
G=(T,N,P,S) . M=(Q,A,Z,, q0, z0, F), , L(M)=L(G).
1. Q={q}; q0=q; F=; Z=N,A=T,z0=S.
2. piP: Xb, bT, XN, N* (q,b,X)= (q,b,X)(q,).
.
. G=({+,(,),i},{E,F,G},P,E). P={E(EFGE | iGE | (EF | i ; F); G+};
1. Q={q}; q0=q; F=; A={+,(,),i}; Z={E,F,G}; z0=E;
2. 1. (q,(,E)=(q,EFGE); 2. (q,i,E)=(q,GE); 3. (q,(,E)=(q,EF); 4. (q,i,E)=(q,); 5. (q,),F)=(q,); 6. (q,+,G)=(q,);
: (q,(,E)={(q,EFGE), (q,EF)}; (q,i,E)={(q,GE), (q,)}; (q,),F)= (q,); (q,+,G)= (q,);
(i), :
(q,(i),E) ?1 (q,i),EFGE) ?2 (q,),GEFGE) ?(q,i),EFGE)?4 (q,),FGE)
5 (q,,GE) ??(q,i),EFGE)
(q,(i),E) ?3 (q,i),EF)
?2 (q,),GEF) ?(q,i),EF) ?4 (q,),F) 5 (q,,). , .. .
. ,
. .
, ,
. .
S-. - G(N,T,P,S) S-, :
1. piP: Aa, AN, aT, V*; .. ,
2. piP: A a11 | a22 | | ann , AN, aiT, iV*, aiaj, i,j=1, 2,..., n; ij; .. ,
, .
S- , , . . G , i ( ).
, ,
. , . , ,
,
. .
S- , . .. - ,
, , . ,
, , - S- ,
, . -, , ,
, . S- , ,
.
S- ( ):

1.
2.

A=T{#}; Z=N{t: tT, AtP}{#}; Q={q}; q0=q; F=; z0={S#}. S- , # - .


piP: Xa, aT, XN, V* (q,a,X)=(q,).
;
3. t: tT, AtP (q,t,t)=(q,); .
:
1. t ;
2. , , , ( 3);
3. , t , , ( 2)
4. (q, #, #), .. ,
5. .
. G({a, b, d, p, q, x, y},{S, X, Y}, P, S), P: {SpX | qY; XaXb | x; YaYd | y};
1. A={a, b, d, p, q, x, y, #}; Z={S, X, Y, b, d, #}; Q={q}; q0=q; F=; z0={S#}.
2. SpX (q,p,S)=(q,X);
1
SqY (q,q,S)=(q,Y);
2
XaXb (q,a,X)=(q,Xb); 3
Xx (q,x,X)=(q,);
4
YaYd (q,a,Y)=(q,Yd); 5
Yy (q,y,Y)=(q,);
6
3. b: (q,b,b)=(q,);
d: (q,d,d)=(q,);
paaxbb, :
(q,paaxbb#,S#)1 (q,aaxbb#,X#)3 (q,axbb#,Xb#)3 (q,xbb#,Xbb#)4 (q,bb#,bb#)7 (q,b#,b#)7 (q,#,#)
, .
(1-6) .

LL(k)
. LL(k) . LL(k) . , - -. LL(1) . LL(1)
. -. . LL(1) .
, , .. .
: {L | R}{L | R}(k). ,
L , R , - (L)
(R) , k . k, .
.
LL(k)-. , . LL(k) . - G LL(k)-, V* k , , , , , k .
LL(k)-. -
, y.
x ,
-. , .
,
.
k ,
. LL(k) :
- LL(k)- k>0 ;
- , , LL(k) k.
, , , LL(1) .
:
- , - LL(k)- k;
- - LL(k) k
LL(k)- k>1 , k . ,
k , LL(k). , .
LL(1) . S- . LL(1)
S : LL(1) , , -. LL(1)- AN , .
LL(1)-. DS(k,,) , N,
V* DS(k,,) = S(k,)F(k,). S(k,) k, S(k,)={ | T*, ||=k, V+, *, V*}.
, , k . F(k,) - k, F(k,)={ | T*, ||=k, S*, S- , N,
,V*, *}. , , k . F(k,) , * (..
).
LL(1) : DS(,) , N, V* DS(,) = S()F(). S() - S()={b | bT, V+, *b,
V*}. F() - F()={b | bT, S*b, S- , N, ,V*, *}.
- LL(1) , ,
, . AN: A1 | 2 | |n P, DS(,i) DS(,j)=, ij, i,j=1,2,..,n.
- LL(1)- LL(1) , .. , . , ,
, - LL(1) :
- : |
- *A
- , -.
#. L(G) #, S,
S#.

-. S()={b | bT, V+, *b, V*}. ,


=d, dT, V*, .. , S()={d}. , =A, AN, V*, .. , S()=S(A). S(A):
1. G(N,T,P,S) G(N; T, P, S), -.
2. AN: S0(A)={X | AXP, XV, V*}, i=0.
3. AN: Si+1(A)= Si(A)Si(B), BSi(A)N.
4. AN: Si+1(A)Si(A) i=i+1; 3
5. AN: S(A)= Si(A)\N. .
-. F(A) - F(A)={b | bT,
S*Ab, S- , AN, ,V*, *}.
1. AN: F0(A)={X | BAXP, BN XV, ,V*}, i=0. ,
A.
2. F0(S)=F0(S){#}. .
3. AN: Fi(A)=Fi(A)S(B), BFi(A)N.
4. AN: Fi(A)=Fi(A) Fi(B), BFi(A)N, B
5. AN: Fi+1(A)=Fi(A) Fi(B), BN, BA, V*
6. AN: Fi+1(A)Fi(A) i=i+1; 3
7. AN: F(A)= Fi(A)\N. .
. G({+,-,/,*,a,b,(,)},{S,R,T,F,E},P,S), P: {STR; R | +TR | -TR; TEF; F | *EF | /EF; E (S) | a | b}
, LL(1) . .
1. -. G({+,-,/,*,a,b},{S,R,T,F,E},P,S), P: {ST | TR; R+T | -T | +TR | -TR; TE | EF; F*E | /E | *EF | /EF;
E (S) | a | b}
S0(R)={+,-};
S0(T)={E};
S0(F)={*,/};
S0(E)={(,a,b};i=0;
2. S0(S)={T};
3. S1(S)= S0(S) S0(T)={T,E};
S1(R)={+,-};
S1(T)= S0(T) S0(E)={E,(,a,b}; S1(F)={*,/};
S1(E)={(,a,b};
4. i=1; 3
3. S2(S)= S1(S) S1(T) S1(E)={T,E,(,a,b}; S2(R)={+,-}; S2(T)= S1(T) S1(E)={E,(,a,b}; S2(F)={*,/};
S2(E)={(,a,b};
4. i=2; 3
S3(T)= S2(T) S2(E)={E,(,a,b}; S3(F)={*,/};
S3(E)={(,a,b};
3. S3(S)= S2(S) S2(T) S2(E)={T,E,(,a,b}; S3(R)={+,-};
4. i=2
5. S(S)={(,a,b};
S(R)={+,-};
S(T)={(,a,b};
S(F)={*,/};
S(E)={(,a,b};
STR; S(TR)=S(T)={(,a,b}
R ; S()=
R+TR; S(+TR)={+}
R-TR; S(-TR)={-}
TEF; S(EF)=S(E)={(,a,b}
F; S()=
F*EF; S(*EF)={*}
F/EF; S(/EF)={/}
E(S); S((S))={(}
Ea; S(a)={a}
Eb; S(b)={b}
1. F0(S)={)}; F0(R)=; F0(T)={R}; F0(F)=; F0(E)={F}; i=0;
2. F0(S)={),#};
3

Fi(A)=Fi(A)S(B), BFi(A)N
F0(S)={),#};
F0(R)=;
F0(T)= F0(T)S(R)={R,+,-};
F0(F)=;
F0(E)=F0(E)S(F)={F,*,/};
6. i=1; 3.

Fi(A)=Fi(A) Fi(B), BFi(A)N,B


F0(S)={),#};
F0(R)=;
F0(T)= F0(T)F0 (R)={R,+,-};
F0(F)=;
F0(E)=F0(E)F0(F)={F,*,/};

F1(S)={),#};
F1(R)={),#};
F1(T)= F1(T)S(R)={R,+,-};
F1(F)= F1(F)S(R)={R,+,-};
F1(E)=F1(E)S(F)={F,*,/};
6. i=2; 3.

F1(S)={),#};
F1(R)={),#};
F1(T)= F1(T)F1(R)={R,+,-,),#};
F1(F)= F1(F)F1(R)={R,+,-,),#};
F1(E)=F1(E)F1(F)={R,+,-,F,*,/};

F2(S)={),#};
F2(R)=F1(R)F1(S) {:STR}={),#};
F2(T)={R,+,-,),#};
F2(F)=F1(F)F1(T) {:TEF}={R,+,-,),#};
F2(E)={R,+,-,F,*,/};

Fi+1(A)=Fi(A) Fi(B), BN, BA, V*


F1(S)={),#};
F1(R)=F0(R)F0(S) {:STR}={),#};
F1(T)={R,+,-};
F1(F)=F0(F)F0(T) {:TEF}={R,+,-};
F1(E)={F,*,/};

F2(S)={),#};
F2(R)={),#};
F2(T)=F2(T)S(R)={R,+,-,),#};
F2(F)=F2(F)S(R)={R,+,-,),#};
F2(E)=F2(E)S(R)S(F)={R,+,-,F,*,/};
6. i=3; 3.

F2(S)={),#};
F2(R)={),#};
F2(T)= F2(T)F2(R)={R,+,-,),#};
F2(F)= F2(F)F2(R)={R,+,-,),#};
F2(E)=F2(E)F2(F)F2(R)={R,+,-,F,*,/,),#};

F3(S)={),#};
F3(R)=F2(R)F2(S) {:STR}={),#};
F3(T)={R,+,-,),#};
F3(F)=F2(F)F2(T) {:TEF}={R,+,-,),#};
F3(E)={R,+,-,F,*,/,),#};

F3(S)={),#};
F3(R)={),#};
F3(T)=F3(T)S(R)={R,+,-,),#};
F3(F)=F3(F)S(R)={R,+,-,),#};
F3(E)=F3(E)S(R)S(F)={R,+,-,F,*,/,),#};
6. AN: Fi+1(A)=Fi(A)

F3(S)={),#};
F3(R)={),#};
F3(T)= F3(T)F3(R)={R,+,-,),#};
F3(F)= F3(F)F3(R)={R,+,-,),#};
F3(E)=F3(E)F3(F)F3(R)={R,+,-,F,*,/,),#};

F4(S)={),#};
F4(R)=F3(R)F3(S) {:STR}={),#};
F4(T)={R,+,-,),#};
F4(F)=F3(F)F3(T) {:TEF}={R,+,-,),#};
F4(E)={R,+,-,F,*,/,),#};

7. F(S)={),#}; F(R)={),#}; F(T)={+,-,),#}; F(F)={+,-,),#}; F(E)={+,-,*,/,),#}


A: DS(A,) = S()F(A). S()={a | aT, V+, *a, V F(A)={a | aT, S*Aa, S- , AN, ,V*, *}.
STR; DS(S,TR)=S(TR)={(,a,b,}
R ; DS(R,)=S()F(R)={),#}
TEF; DS(T,EF)=S(EF)={(,a,b}
F; DS(F, )=S()F(F)={+,-,),#}
E(S); DS(E,(S))=S((S))={(}

R+TR;DS(R,+TR)=S(+TR)={+}

R-TR; DS(R,-TR)=S(-TR)={-}

F*EF; DS(F,*EF)=S(*EF)={*}
Ea; DS(E,a)=S(a)={a}

F/EF; DS(F,/EF)=S(/EF)={/}
Eb; DS(E,b)=S(b)={b}

DS(R,) DS(R,+TR)=; DS(R,) DS(R,-TR)=; DS(R,-TR) DS(R,+TR)=;


DS(F,) DS(F,*EF)=; DS(F,) DS(F,/EF)=; DS(F,*EF) DS(F,/EF)=;
DS(E,(S)) DS(E,a)=; DS(E,(S)) DS(E,b)=; DS(E,a) DS(E,b)=;
. LL(1) .
LL(1) . R(Q,A,Z,, q0, z0, F) .
( LL(1) )
4. Q={q}; A=T{#}; Z=N{t | tT, BtP, BN, V*}{#}; q0=q; z0={S#}. F=; S- , # -
.
5. pP: Xa, aT, XN, V* (q, a, X)=(q,);. ;
6. pP: XA, X,AN, V* DS(X,A) (q, a, X)=(q, A); ;
7. pP: X, XN DS(X,) (q,a,X)=(q,); ;
8. t: tT, AtP, AN, V* (q,t,t)=(q,); . .
, , , . (q,#,#), , ,
, .
. . a+a* a+a*b.
G({+,-,/,*,a,b,(,)},{S,R,T,F,E},P,S),
P: {STR; R | +TR | -TR; TEF; F | *EF | /EF; E (S) | a | b}
1. A={+,-,/,*,a,b,(,),#}; Z={S,R,T,F,E,),#}; Q={q}; q0=q; z0={S#}
2.1. R +TR (q,+,R)=(q,TR); 1
2.2. R -TR (q,-,R)=(q,TR);
2
2.3. F *EF (q,*,F)=(q,EF);
3
2.4. F /EF (q,/,F)=(q,EF);
4
2.5. E (S) (q,(,E)=(q,S));
5
2.6. E a (q,a,E)=(q,);
6
2.7. E b (q,b,E)=(q, );
7
3.1. STR DS(S,TR)={(,a,b} (q,(,S)=(q,TR)
(8); (q,a,S)=(q,TR)
(9);
(q,b,S)=(q,TR) (10);
3.2. TEF DS(T,EF)={(,a,b} (q,(,T)=(q,EF)
(11); (q,a,T)=(q,EF)
(12);
(q,b,T)=(q,EF) (13);
4.1. R DS(R,)={),#} (q,),R)=(q, ) (14); (q,#,R)=(q, ) (15);
4.2. F DS(F,)={+,-,),#} (q,+,F)=(q, ) (16); (q,-,F)=(q, ) (17);(q,),F)=(q, ) (18); (q,#,F)=(q, ) (19);
5. (q,),))=(q, );
(q,a+a*#,S#)9(q,a+a*#,TR#)12(q,a+a*#,EFR#)6(q,+a*#,FR#)16(q,+a*#,R#)1(q,a*#,TR#)12(q,a*#,EFR#)6(q,*#,FR#)
3
(q,#,EFR#) ,
(q,a+a*b#,S#)9(q,a+a*b#,TR#)12(q,a+a*b#,EFR#)6(q,+a*b#,FR#)16(q,+a*b#,R#)1(q,a*b#,TR#)12(q,a*b#,EFR#)
6(q,*b#,FR#)3(q,b#,EFR#)7(q,#,FR#)19(q,#,R#)15(q,#,#) , . .

LR(k)
LR(k) . . -. LR(0) LR(1) . . LR(0) . LR(0)
. LR(1) . LR(1) . SLR(1) LALR(1) . SLR(1) . -. YACC
LR(k)-. k
. LR(k) . , - :
- ( )
-
- , 1, 2,, n
- G LR(k)-, k0 - k .
- .
G(N,T,P,S) -, : S * A * , AN, ,V*, ,T*. , . .. .
: G({S,L,I},{i, , ,r},{SrL; LL,I | I; Ii},S). ri,i :
S 1 rL 2 rL,I 4 rL,i 3 rI,i 4 ri,i.
: ri,i rI,i rL,i rL,I rL S, ()
: r[i],i r[I],i rL,[i] r[L,I] [rL] S
,
, .
LR(k)-. -
, y.
x ,
, z,
-. ,
.
k .
z ,
. z.
LR(k) :
- LR(k)- k0 ;
- , , LR(k)- k.
:
- , C- LR(k)- k;
- - LR(k) k
-. G , G(N,T,P,S) :
- G=G, S : pP: AS, A,SN, ,V*;
- G={N{S},T,P{SS},S}, S : pP: AS, A,SN, ,V*.
, ()
. .. ,
.
LR(k) .
- LR(1) , . LR(0) LR(1)
, k>1 LR(k) . LR(1)
-. - , LR(1)
. LR- , LL-.
-, LL-, LR-, . . , LL(k) LR(k) , . k
.
LR(0) .
. , ..
( ) . - , , . .. . LR(0)

. , ,
. LR(0) , LR(1) ,
.
-,
-, .
. . S
- G(T, N, P, S), S1 | 2 | | n P, i V*,
R={S1 , S2 , , Sn }. :
1. rR : AB, A,BN, ,V* , pP : B, V* R=R{B}, ..
2. rR : Ax, AN, ,V* , xV R={Ax }, RxR .. , x ,
x.
.
. ,
. : R0, R1, R2, , Rn. R0
. :
G=({a,b},{S}, {SaSS | b},S). .
, :
G=({a,b},{S,S}, {SS, SaSS | b},S).
0. R0={ SS}.
1. S, R0= R0{ SaSS , Sb}
2. R0 s R1 = { SS}
2. R0 a R2 = { SaSS }.
1. S, R2= R2{ SaSS , Sb}
2. R0 b R3 = { Sb }.
2. R2 s R4 = { SaSS }
1. S, R4= R4{ SaSS , Sb}
2. R2 a R5 = { SaSS }.
1. S, R5= R5{ SaSS , Sb}
2. R2 b R6 = { Sb }.
2. R4 s R7 = { SaSS }
2. R4 a R8 = { SaSS }.
1. S, R8= R8{ SaSS , Sb}
2. R4 b R9 = { Sb }.
6 : 0,1,2,3,4,7. :

R0={ SS, SaSS , Sb}


R2={ SaSS, SaSS , Sb}
R4={ SaSS, SaSS , Sb}
R5={ SaSS, SaSS , Sb}=R2
R6=R3
R8={ SaSS, SaSS , Sb}=R2
R9=R3

. LR(0) .
: , (
). ij , , i, j. 2 . 4 :
- () (s). . .
. s.
s.
- (n, A, k). k: A. n , n = ||. . (k) . , .

- E. . .
- . , .
U = {uij } .
1. Ri i.
2. Ri :
- r Ri : A, V* , AN, k A uij = (||, A, k), jS
- r Ri : Ax, ,V* , xV, AN, Rix Rj uix = (j)
3. u0S =
4. .
, .
, .. , LR(0) . 0, , .
#, 0. . :

0
1
2
3
4
7

E
E
E
E
E

abababb:

abababb#
0
bababb#
2
ababb#
3
ababb#
2
ababb#
4
babb#
2
abb#
3
abb#
2
abb#
4
bb#
2
b#
3
b#
2
b#
4
#
3
#
4
#
7
#
4
#
7
#
4
#
7
#
0
#
1
#
0

S
(1)
(1, S, 1)
(4)
(1, S, 3)
(7)
(3, S, 2)

a
b
a
S
a
b
a
S
a
b
b
S
b
#
S
#
S
#
S
#
S
#
S

a
(2)
(1, S, 1)
(2)
(1, S, 3)
(2)
(3, S, 2)

#
#a
#ab
#a
#aS
#aSa
#aSab
#aSa
#aSaS
#aSaSa
#aSaSab
#aSaSa
#aSaSaS
#aSaSaSb
#aSaSaS
#aSaSaSS
#aSaS
#aSaSS
#aS
#aSS
#
#S
#

b
(3)
(1, S, 1)
(3)
(1, S, 3)
(3)
(3, S, 2)

0
02
023
02
024
0242
02423
0242
02424
024242
0242423
024242
0242424
02424243
0242424
02424247
02424
024247
024
0247
0
01
0

(1, S, 1)

(1, S, 3)

(3, S, 2)

3
3
3
3
33
33
33
33
333
333
333
3333
3333
33332
33332
333322
333322
3333222
3333222
33332221

. G({+, (, ), i},{S, E, F},{SE; EF+E; EF; F(E); Fi}, S)


0. R0={ SE}.
1. E, R0= R0{ EF+E , EF} R0={ SE, EF+E, EF }
R0={ SE, EF+E, EF, F(E) , Fi}
1. F, R0= R0{ F(E) , Fi}
2. R0 E R1 = { SE}
2. R0 F R2 = { EF+E, EF }
2. R0 ( R3 = { F(E)}
1. E, R3= R3{ EF+E , EF} R3={ F(E), EF+E , EF }
R3={ F(E), EF+E , EF, F(E) , Fi }
1. F, R3= R3{ F(E) , Fi}
2. R0 i R4 = { Fi}
2. R2 + R5 = { EF+E }
1. E, R5= R5{ EF+E , EF} R5={ EF+E, EF+E , EF }
1. F, R5= R5{ F(E) , Fi}
R5={ EF+E, EF+E , EF, F(E) , Fi }
2. R3 E R6 = { F(E) }
2. R3 F R = { EF+E, EF } , R2
2. R3 ( R = { F(E)}

1. E, R= R{ EF+E , EF}
R={ F(E), EF+E , EF }
1. F, R= R{ F(E) , Fi}
R={ F(E), EF+E , EF, F(E) , Fi }
R3
2. R3 i R = { Fi } , R4
2. R5 E R7 = { EF+E }
2. R5 F R = { EF+E, EF } , R2
2. R5 ( R = { F(E)}
1. E, R= R{ EF+E , EF}
R={ F(E), EF+E , EF }
1. F, R= R{ F(E) , Fi}
R={ F(E), EF+E , EF, F(E) , Fi }
R3
2. R5 i R = { Fi } , R4
2. R6 ) R8 = { F(E)}
8 . :

0
1
2

E
(1)
(1,S,1)
(1,,3)

F
(2)
(1,S,1)
(1,,3)

3
4
5
6
7
8

(6)
(1,F,5)
(7)

(3,,2)
(3,F,4)

(2)
(1,F,5)
(2)

(3,,2)
(3,F,4)

(1,S,1)
(1,,3)
(5)

(1,F,5)

(3,,2)
(3,F,4)

(
(3)
(1,S,1)
(1,,3)

(1,S,1)
(1,,3)

i
(4)
(1,S,1)
(1,,3)

(1,S,1)
(1,,3)

(3)
(1,F,5)
(3)

(3,,2)
(3,F,4)

(1,F,5)

(8)
(3,,2)
(3,F,4)

(4)
(1,F,5)
(4)

(3,,2)
(3,F,4)

(1,F,5)

(3,,2)
(3,F,4)

(2,+) -. LR(0). LR(1) .


LR(1) . S - G(T, N, P,
S), S1 | 2 | | n P, i V*, R={S1 /#, S2 /#, , Sn
/#}. , .
:
1. rR : ABb /a, A,BN, a,bT, ,V* , pP : B, V* R=R{B /b}, ..

2. rR : AB /a, A,BN, aT, V* , pP : B, V* R=R{B /a}
3. rR : ABC /a, A,B,CN, aT, ,V* , pP : B, V* , cS(C) R=R{B /c}, S(C)
4. rR : Ax /a, AN, ,V* , aT, xV R={Ax /a}, RxR
: G({+, (, ), i},{S, E, F},{SE; EF+E; EF; F(E); Fi}, S)
0. R0={ SE /#}
R0={ SE /#, EF+E /# , EF /#}
1. E, R0= R0{ EF+E /# , EF /#}
1. F, R0= R0{ F(E) /+ , Fi /+, F(E) /# , Fi /# }

R0={ SE /#, EF+E /# , EF /#, F(E) /+ , Fi /+, F(E) /# , Fi /# }


2. R0 E R1 = { SE /#}
2. R0 F R2 = { EF+E /#, EF /# }
2. R0 ( R3 = { F(E) /+ , F(E) /# }
1. .. E, R3= R3{ EF+E /) , EF /)}
R3={ F(E) /+ , F(E) /#, EF+E /) , EF /) }
1. F, R3= R3{ F(E) /+ , Fi /+, F(E) /) , Fi /) }
R3={ F(E) /+ , F(E) /#, EF+E /) , EF /), F(E) /+ , Fi /+, F(E) /) , Fi /) }
, 15 . :

LR(1) . LR(1) , LR(0). U = {uij } .


1. Ri i.
2. Ri :
- r Ri : A /a, V* , AN, aT, k A uia = (||, A, k)
- r Ri : Ax /a, ,V* , xV, AN, aT, Rix Rj uix = (j)
2. u0S =
3. .
, LR(1) .
0, ,
. #, 0.
. :

0
1
2
3
4
5
6
7
8
9
10
11

E
(1)

(7)

(6)

(13)

F
(2)

(8)

(2)

(8)

(5)

(1,F,5)

(12)

(1,F,5)
(3,F,4)

(
(3)

(9)

(3)

(9)

(11)
(1,,3)

(1,F,5)

i
(4)

(10)

(4)

(10)

(1,S,1)
(1,,3)

(1,F,5)

(3,,2)

(3,F,4)

12
13
14
15

(15)

(8)

(3,F,4)

(9)

(14)
(3,F,4)
(3,,2)

(10)

, , ,
, LR(0) . , (i)+i:

(i)+i#
i)+i#
)+i#
)+i#
)+i#
)+i#
)+i#
+i#
+i#
+i#
i#
#
#
#
#
#
#
#
#

0
3
10
3
8
3
7
11
0
2
5
4
5
2
5
6
0
1
0


(
i
)
F
)
E
)
+
F
+
i
#
F
#
E
#
E
#
S


#
#(
#(i
#(
#(F
#(
#(E
#(E)
#
#F
#F+
#F+i
#F+
#F+F
#F+
#F+E
#
#E
#


0
03
0 3 10
03
038
03
037
0 3 7 11
0
02
025
0254
025
0252
025
0256
0
01
0

5
5
53
53
53
534
534
534
534
5345
5345
53453
53453
534532
534532
5345321

LR(0) - LR(1)
, . SLR(1) ( simple - )
LALR(1) ( look ahead ) . (2,+) {(1,,3),
(5)} LR(0) , , #, ..
. , , SLR(1) . LALR(1) .
SLR(1) , LR(0) , :
U = {uij } .
1. Ri i.
2. Ri :
- r Ri : A, V* , AN, k A uij = (||, A, k), j F(A), F(A) - ( , LR(0), )
- r Ri : Ax, ,V* , xV, AN, Rix Rj uix = (j)
3. u0S =
4. .
, SLR(1) .
0, ,
. #, 0.
. :
. .
: F(S)={#}; F(E)={),#}; F(F)={+,),#}.
:

S
E
F
+
(
)
i
#
0

(1)
(2)

(3)

(4)

(1,S,1)
2

(5)

(1,,3)

(1,,3)
3

(6)
(2)

(3)

(4)

(1,F,5)

(1,F,5)

(1,F,5)
5

(7)
(2)

(3)

(4)

(8)

(3,,2)

(3,,2)
8

(3,F,4)

(3,F,4)

(3,F,4)

(i)+i#
0
(
#
0
i)+i#
3
i
#(
03
)+i#
4
)
#(i
034
)+i#
3
F
#(
03
5
)+i#
2
)
#(F
032
5
)+i#
3
E
#(
03
53
)+i#
6
)
#(E
036
53
+i#
8
+
#(E)
0368
53
+i#
0
F
#
0
534
+i#
2
+
#F
02
534
i#
5
i
#F+
025
534
#
4
#
#F+i
0254
534
#
5
F
#F+
025
5345
#
2
#
#F+F
0252
5345
#
5
E
#F+
025
53453
#
7
#
#F+E
0257
53453
#
0
E
#
0
534532
#
1
#
#E
01
534532
#
0
S
#
0
5345321
, LR(1) .
-:
,
, . ,

. ,

.
SLR(1) LR(1) ,
. , SLR(1) ,
LR(1), , SLR(1) .
SLR(1) LALR(1) ,
. -
LALR(1) . , ,
LALR(1) LR(1) , ,
LR(1) LALR(1) .
, ,
,
, .
, YACC (Yet
Another Compiler Compiler). , -, . YACC LALR(1) .


. . . . . . . . . .

. , . - . , .
, . , , , .
- , :
1.
:
Bi =. Bj (Bi ,Bj V) pP : ABiBj , AN, ,V*
Bi <. Bj (Bi ,Bj V) pP : ABiD , D* Bj, A,DN, ,,V*
Bi .> Bj (Bi ,Bj V) pP : ACBj , C* Bi, pP : ACD , C* Bi, D* Bj, A,C,DN, ,,,V*
2. piP : Aii , i j , i,j=0,1,,|P|, i j. .. . ,
, .
B

. , . , - .
,
:
Bi <. Bi+1 , Bi+1 , .. Bi
Bi .> Bi+1 , Bi , .. Bi
Bi =. Bi+1 , Bi , Bi+1
. .
a , b . , ,
<. =. . .> , ,
, =. . . i (i,j), j. :
L(A) = {X | A* X}, AN, XV, V* -
R(A) = {X | A* X}, AN, XV, V* -
:
1. AN : R0 (A) = {X | A X}, XV, V* ;
L0 (A) = {X | A X}, XV, V* ; i=1;
2. AN : Ri (A) = Ri-1 (A) Ri-1 (B), B (Ri-1 (A)N); Li (A) = Li-1 (A) Li-1 (B), B (Li-1 (A)N);
3. Ri (A) Ri-1 (A) Li (A) Li-1 (A) i=i+1; .2.
. B={bij}
( ). (#).
:
1. pP : Aij , AN, i,j V, ,V* bij = =.
2. pP : AiD , jL(D), A,DN, i,j V, ,V* bij = <.
3. pP : ACj , iR(C), A,CN, i,j V, ,V* bij = .>
4. pP : ACD , iR(C), jL(D), A,C,DN, i,j V, ,V* bij = .>
5. jL(S) : S-, AN, j V, b#j = <.
6. iR(S) : S-, AN, i V, bi# = .>
B

: G({t, i, ,, ;},{S,N},{StN Ni,N Ni;},S)


R0(N)={N, ;}; L0(S)={t};
R0(S)={N};
R1(S)= R0(S) R0(N)={N, ;};
R1(N)={N, ;}; L1(S)={t};
R2(N)={N, ;}; L2(S)={t};
R2(S)= R1(S) R1(N)={N, ;};
:
StN 1) b(t,N)= =.
2) L(N)={i}, b(t,i) = <.
Ni,N 1) b(i, ,)= =. b(,, N)= =. 2) L(N)={i}, b(,, i) = <.
Ni; 1) b(i, ;)= =.
5) L(S)={t}, b(#,t)= <.
6) R(S)={N, ;}, b(N, #)= .> b(;, #)= .>
:
S
N
t
i
,
;
#
S

L0(N)={i};
L1(N)={i};
L2(N)={i};

>.
N
=.
<.
t
=.
=.
i
=.
<.
,
>.
;
<.
#
: = , , :
1. : ; .
2. ; ;
3. :
3.1. =. : , ;
3.2. <. : , ;;
3.3. .> : , ;
:
3.4. =. : ;
3.5. <. : , , , ;
4. , , .
:

ti,i;#
#
t
<.
0
i,i;#
#t
i
<.
0
,i;#
#ti
,
=.
0
i;#
#ti,
i
<.
0
;#
#ti,i
;
=.
0
#
#ti,i;
#
.>
0
#
#ti,i
;
=.
;
1
#
#ti,
i
<.
i;
1
#
#ti,N
#
.>
0
3
#
#ti,
N
=.
N
1
3
#
#ti
,
=.
,N
1
3
#
#t
i
<.
i,N
1
3
#
#tN
#
.>
0
32
#
#t
N
=.
N
1
32
#
#
t
<.
tN
1
32
#
#S
#
0
321
- ,
.
. -, :
1. :
ai =. aj (ai , aj T) pP : Aaiaj , AaiBaj A,BN, ,V*
ai <. aj (ai , aj T) pP : AaiD , D* aj, D* Baj, A,D,BN, ,,V*
ai .> aj (ai , aj T) pP : ACaj , C* ai, C* aiB, A,C,BN, ,,V*
2. piP : Aii , i j , i,j=0,1,,|P|, i j.
3. .
. ,
. ,
.
, . . :
Lt(A) = {t | A* t A* Bt }, A,BN, tT, V* -
Rt(A) = {t | A* t A* tB }, A,BN, tT, V* -
:
1. L(A) R(A) .

2. AN : Rt0 (A) = {t | A t A tX }, tT, XN, V* ;


Lt0 (A) = {t | A t A Xt }, tT, XN,
*
V ; i=1; L , R
.
3. AN : Rti (A) = Rti-1 (A) Rti-1 (B), B (R(A)N); Lti (A) = Lti-1 (A) Lti-1 (B), B (L(A)N);
4. Rti (A) Rti-1 (A) Lti (A) Lti-1 (A) i=i+1; .3.
. B={bij}
( ). (#).
:
1. pP : Aij AiBj, A,BN, i,j T, ,V* bij = =.
2. pP : AiD , jLt(D), A,DN, i,j T, ,V* bij = <.
3. pP : ACj , iRt(C), A,CN, i,j T, ,V* bij = .>
5. jLt(S) : S-, AN, j T, b#j = <.
6. iRt(S) : S-, AN, i T, bi# = .>
: G({t, i, ,, ;},{S,N},{StN Ni,N Ni;},S)
1. R(S)= {N, ;}; R(N)={N, ;};
L(S)={t};
L(N)={i};
Lt0(N)={i}; i=1
2. Rt0 (S)={t}; Rt0(N)={, , ;}; Lt0(S)={t};
t
t
t
Lt1(S)= Lt0 (S) ={t};
3.1. R 1 (S)= R 0 (S) R 0(N)= {t, , , ;};
t
t
R 1(N)= R 0 (N)={, , ;};
Lt1(N)= Lt0 (N)={i}; i=2
t
t
t
3.2. R 2 (S)= R 1 (S) R 1(N)= {t, , , ;};
Lt2(S)= Lt1 (S) ={t};
t
t
R 2(N)= R 2 (N)={, , ;};
Lt2(N)= Lt1 (N)={i};
:
Ni,N 1) b(i, ,)= =. 2) Lt(N)={i}, b(,, i) = <.
StN 1) Lt (N)={i}, b(t,i)= <.
t
Ni; 1) b(i, ;)= =.
5) L (S)={t}, b(#,t)= <. 6) Rt(S)={t, , , ;}, b(t, #)= .> b(, , #)= .> b(;, #)= .>
:
t
i
,
;
#
<.
>.
t
=.
=.
i
<.
>.
,
>.
;
<.
#
, , . . .
, ,
. , ,
. .
:

ti,i;#
#
t
<.
0
i,i;#
#t
i
<.
0
,i;#
#ti
,
=.
0
i;#
#ti,
i
<.
0
;#
#ti,i
;
=.
0
#
#ti,i;
#
.>
0
#
#ti,i
;
=.
;
1
#
#ti,
i
<.
i;
1
#
#ti,N
#
.>
0
3
#
#ti
,
=.
,N
1
3
#
#t
i
<.
i,N
1
3
#
#tN
#
.>
0
32
#
#
t
<.
tN
1
32
#
#S
#
0
321
, . , , ,
.
. , , . , , . . ,
, .
SS, .
. . , , .
.

.
. . . .
. , , . . . . .

-. -, ,
. 2 : - .
. . , , .
: . :
-
- ,

- , .

, :
- , ,
- ( )
-
-
- ..

.
. , , . , . :
-
-
-
-
-
- ..
, , , .
. . , ,
. :
- (, ),
-
- () ()
- .
, .
. , .
.
, - . ,
, , . .
. , . : (a-b)*(c+e). 1) a b 2) + c e 3) * (1) (2). . 4 : , . : 1) a b r1 2) + c e r2 3) * r1 r2. ()
. , , ,
. .
. ,
. . Addr, . : , ,
. (a+b[1+1,j])*c+1.3. :

& . , ,
. : a b i 1 + j 3 & + c * 1.3 +. , ( ), , . , . false ?, ->.
if A then B else C :
2 : , , ,
. . :
A m1 ? B m2 -> C. : A m1 ? B m2 -> m1: C m2:
, ,
, . , ,
( ).
, , . , . . . , . . .
. ,
. . . . .
. , . . .
, , , , , ,
.
, .
,
, ,
.
, , .
, , , .

.
, () , . , .
, . , ,
.. ,
, , 2,4,8,16 . ,
, .
, .
: , , . ,
.
, . , . , , ,
. .
. . ,
, . ,
. . , , Pascal . , . , , .
, , ,
. , .

. :
-
-
- , :
- -
- - , ( ) , .
- , , , , ..
,
. , . . ,
, , , . RTTI Run Time Type Information.
.
. 1. , . , , -
. 2. . , , a+b :
mov ax, a
add ax, b
mov res, ax
, . , , . , .
() .
.
, , .
.
.


. . - . -. . . . . - . -. . -.

,
, ( ).
, . , . - .
, .
, .
. , . ,
, . ,
( .. )
, ().
. - : N C(N). , - . -. - , , LR LL . - :
-
-
- , , .
:
-
- ()
- ()
- ( )
- .
, , , .
, , . . ,
. .
, , , , . , , . , , .
:
1. , , .
2. , , .
3. , , , .1
4. , , ,
, .3
5. , ,
, ,
, ,
.1.
6. ,
, , .3, .
. G ({+, - , / ,*, (, ), a ,b}, {S, R, T, F, E}, P, S), :
S TR | T
R +T | -T | +TR | -TR
T EF | E
F *E | /E | *EF | /EF
E (S) | a | b
(a+a)*b ,
:
,
.

: <> (<1> <2> <>). , , . . , ,


. . , , .
. ,
, .
, . . ,
. . .
- . ,
R p. ,
,
. :
S S+T
R(p)=+
shift(p)
S S-T
R(p)=-
shift(p)
ST
T T*E
R(p)=*
shift(p)
T T/E
R(p)=/
shift(p)
TE
E (S)
Ea
R(p)=a
shift(p)
Eb
R(p)=b
shift(p)
. ,
. , : , ,
, . , , NodeGen, , .
4 XXX :
1. (op1 - , op2 - ). : mov ax, op1; XXX ax, op2
2. (node), op1. : NodeGen(node); mov dx,ax; mov ax, op1;
XXX ax, dx
3. (node), op1. : NodeGen(node); XXX ax, op2
4. (node1 - , node 2 - ). : NodeGen(node1); push(ax); NodeGen(node2); mov dx, ax; pop ax; XXX ax, dx.
XXX , , *, /, + , - (mul, div, add, sub).
(=) . .
1. (op1 , op2- ). : mov ax, op2; mov op1, ax;
2. op1, (node). : NodeGen(node); mov
op1, ax.
z=(a+a)*b :
:
NodeGen (node2)
NodeGen(node3)
mov ax, a
mov z, ax
mov dx, ax
add ax, a
mov ax, b
mov dx, ax
mul ax, dx
mov ax, b
mov z, ax
mul ax, dx
mov z, ax
. -, mul ax, op2.
86 , : mul
op2. .. . ,
, , . , .
- D=(T, N, , R, S), (), N
, - , R A,, V*, (N)*; S - . - , A,
. - , N** (A ,) R. , - D=(T, N, , R, S), (D)={(,y) | (S,S)* (,y), T*,
y*}. G=(T,N,P,S), P={A | (A ,) R }, -.
G=(,N,P,S), P={A | (A ,) R }, -. -
M=(Q, A, Z, , , q0, z0, F), Q ,A
, Z , - , -
(Q(A{}Z) (QZ**), .. :(Q(A{}Z)M(QZ**), q0
, q0Q, z0 , z0Z, F

, FQ. (q,,,y)(QA*Z**). y - , : (q0, , z0, )* (q, , , y), qF, Z*. () , (M)={(,y) | (q0, , z0, )* (q, , , y), qF, Z*}.
D - LL(k), - . D - LR(k), -.
- , .
(-). -
. - . :
G(N={S,T,E},T={+,-,*,/,(,),a,b},={+,-,*,/,a,b},P,S)
S S+T+ | S-T- | T
T T*E* | T/E / | E
E (S) | a a | b b
- . . , . , . : (a a + a a +)* b b * .
(a + a )* b aa+b*,
. - - , ,
. -
.
- ,
. , .
.
-.
, .. .
- () - .
.
, .
. :
Sp Sa+Tb+ | Sa-Tb- | Tq : p=a+b; p=a-b; p=q;
Tp Ta*Eb* | Ta/Eb / | Eq p=a*b, p=a/b; p=q
Ep (Sq) | aq a | bq b p=q; p=q; p=q;
(a4 + a5)*b7, .
:
,
(-). -
, :
1. , ,
( .. )
2.
3. :
3.1. ,
3.2.
4. :
4.1.
4.2.

5. , , .
:
1. - ,
2. ,
3.
4. , , : ,
, , ,
5. .5. , .
-, , .


. . . .
. . - . .

,
. .
. . ,
, . ,
, , . .
. , , , . ( ) 10-30%.
:
- ,
- .
. ,
. .
. ,
.
: , , , ,
.
. , .
, . : , , , , .
,
i, j, j>i,
i j , i .
, , .
, . i ,
j, j<i , , i
j.
,
.. , , .
,
, . : 2***3 (2*3)**. , ,
(+)+(+) .
+(+(+)) .

. , *+* = *(+).
, , . , .
, OR True, AND false.
. A OR F(B) , F(B) . () , , ..,
. , . ,
0. , . .
. ,
.
. : (inline ). , . ,
. inline , .
. , , . :
; ; . ,

, . , . ,
. : for(S=10, i=1; i<=N; i++) A[i]=i*S;
for(S=10, i=1; i<=N; i++, S+=10) A[i]=S;
. : for(i=1;i<=N;i++) for(j=1;j<=M;j++) A[i][j]=0; :
for(X=M*N, i=1; i<=X; i++) A[i]=0; ,
.
- . . , ., ,
, , . ,
. , ,
, . ? . ,
, . ,
, .
, , . , , , . . : ? . .
. .
.
. . , .. . .
, . . . .
, ,
. ,
, :
-
-
-
-
- ,
-
- .
60-. : ,
. , . ,
. , ..
. . . . .
.
. .
:
- ,
- . ,
- . ,
, . .


. . . .
. . . . . .
. .

. . .
, , . , , . , .
, . .
. .
, . :
push0 macro
mulx2 macro k, x

mulx2 7, 15 :
xor ax, ax
mov ax, x
mov ax, 15
push ax
mul x
mul 15
endm
mul k
mul 7
endm
. local.
. ,
.

mulx2
15
3
2
0
k
7

x
15

mov ax, @2
mul @2
mul @1
. ,
, .
macro, .
local, . , .
, . , . , . , . .
, ,
, .
. :
-
-
-
- ()

- .
, .
. ,
, , . .
. . . , 6 : , , ; ,
; , , , ; ; ; , ; , .
x86 , . . . . : -,
(), -, . ,
. : w (0 , 1
), s (0 , 1- ), d . -
. 3 : mod ( 6,7), reg ( 5-3), r/m ( 0-2). mod r/m
. , mod=11, r/m , mod=00, r/m=110. reg ,
. , d=1, 0.
. , w=0, w=1.
32 , (4 ) 2 , - 66h.
.
. . - . , .
. , .
.
(). , . .
. ,
.
. , , , . ,
, , . :
80
96 , ,
98 (, , 96),

8 ( )
0 , 98
9 96, 98 ,
9 . , ,
8 ( ), 4 ( ), ( ).
90 , ,
8 , .
(32,16,64). . . . :
COM MS-DOS
MZ MS-DOS
NE windows 3.1
PE Windows 9x/NT
COFF UNIX

. , , . , .

, . .
. . . , ,
.