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

. .

. . , . .

2009

. ., . .
( ) .:
( 05899
24.09.2001), 2009 93 .


, .
,
.
(-2 -5), .
,
.
.. .

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

-
. . .

ISBN



. . . , 2009
.., .., 2009
4


1. ...............................................................................................6
1.1. ..............................................6
1.2. ......................................................................10
1.3. ........................................................................12
1.4. -...................................................................14
1.5. ..........................................17
1.6. -.......................................................................21
2. -2.................................................................................................29
2.1. - ...............................................29
2.2. ...........................................................31
2.3. ..................................36
2.4. ..............................................................................38
2.5. ...........................................................43
2.6. .........................................................45
3. -5.................................................................................................49
3.1. ...........................................................................49
3.2. ............................................................................51
3.3. ............................................................................55
3.4. ..............................................................................57
3.5. ........................................................................61
4. ....................................................63
4.1. ............................................................63
4.2. .......................................................................68
4.3. .................................................73
5. ......................................................................................81
5.1. ...........................................................81
5.2. ...............................................82
5.3. .............................84
5.4. .................................85
5.5. ...........................................................86
5.6. -......................................................88
5.7. - ............................................90
5.8. ....................................................91
6. .....................................................................................................93
1. -2......................................................94
2. -5......................................................96

( )
60-
,
(, .) [1,2].
,

[3-6]
.
,
,

.
,
( ,
.).

1.

,
-2 -5.

.
-2.
1.1.

, ..
[7],
.
()
(), ,
- A B
A B, A B .
- A B
(A B),
6

, (A B),
.
. C
-
:
C C1 C2 Cn .
:
I. A B A B,
. A B
A B , A
Cj.
II. Cj :

A B
Cj+1 . Cj ,
.
,
, .
- ,
.

,
.
(..
),

.
, ,
(
).
.
:
{a, b},
{0, 1, 2, 3}.
1. , :
a
b

* ,
. , *
7

, :
( ),
.
2. , , :
a a$
b b$
$a $
$b $
$
*


: * , $
( )
.
3. , ,

, :
0 00
1 01
2 10
3 11

,

.

(), :
,

.
.
, (
), :

,

. ,
, :
- = -.

,
.
,
.

,
, ,
. -
, -
, .

, .
-,
, .
, 5 . ,
*, .

*
f1
s1 e2 = e2
* ,
f2
s1 e2 = s1
* ,
* ,
f3
'0' e2 = '00' <f3 e2>
'1' e2 = '01' <f3 e2>
'2' e2 = '10' <f3 e2>
'3' e2 = '11' <f3 e2>
=
f1, f2 f3 , s1
e2 ,
. (-)
(-).
,
<.
, f3 .
(
) .

1.2.

,
,
-. -, -
, ,
.
,
,
.
( ), < >, =,
() ', S s, T t, E e.
, -,
(), .
, ,
ASCII. ,
-
(), ,
: 'B', '+', 'e', ')'. , )
')',
'' .. ' ' ,
, .

,
, : 'x+y', 'define', ' ' (
). ,
-,
-
: 'x' '+' 'y', 'd' 'e' 'f' 'i' 'n' 'e', ' ' ' '.
(.. )
, - ,
:
( );
< >;
' '.


, .
, -
10

,
, :
('for' ('i=1')) sa ('g' <f5 e1> (e2))
'for', 'i=1', 'g' -, sa, 1,
e2 , f5 , <f5 e1>
.
:
_
s, t
, :
s ( S) ;
t ( T)
- ;
e ( E)
- ( ).
,
.
, , , e1
e2 .
-
-,
.
,
-,

. ,
.
- ( )
,
- ( -):
::= |
::= _ | _ |
_
_ ::= | -
_ ::= ()
_ ::= <_ >
::=
11

,
.
, . ,
''('B'('C')'D') : '' ('B'('C')'D'),
(
- 'B', 'E', 'D' ('C')).
,
,
:
,
, : 'type'('int3 = 1..3');
- ,
, : e1 '+' e2 (sa e3);
, :
'a-b' <pr '+c+g'>(<fun 'dg'>);
,
( -
).
, -
.
.
1.3.

,
-
. ,

,
.
- ,
:
<_ >
-

- =
.
(-)
12

(- )
: - ,
. ,

.
, ,
,
- .
,
.
, .

( +),
, + ,
.
* ChangeFirstPlus
* ( ) ,
* , 'A+B' 'A-B',
* 'XY+Z85' 'XY-Z85'
ChangeFirstPlus
e1 '+' e2 = e1 '-' e2
e1 = e1
- ,
,
.
-
-. ,
, .
ChangeFirstPlus ,
e1

.

,
. ,
,
.

, , :
s1 e2 s1 e3 = s1 s1 e2 e3

13

(..
)
.
s1 e1 = e1

s1 e2 = e1.
-:
* ChangeAllPlus
* , ,
* 'A+B+C' 'A-B-C'
ChangeAllPlus e1 '+' e2 = <ChangeAllPlus e1 '-' e2>
e1 = e1

ChangeFirstPlus,

ChangeAllPlus :
, ,
. ,
+,
.

.
1.4.

-. - (
) , -.
- :
,
,
, -.
-
, ,
,
, : <ChangeAllPlus 'A+B+C'>.
- ,
-,
. ,
, , ,
.
,
.
14

(
), .
-, :
I.


.
,
.
: <f t>, f , Et
( ).
II.
f.
, f,
, ,
El = Er, El
t
<f t>.
--------------------------------------------------------------------------------------------,
- El Et,
- El
( ), El
,
c Et.
-------------------------------------------------------------------------------------------- El c Et,
f .


.
III.
f.
I
<f t> Er. Er
Er
,
.

III - I
,
.
-
. , I
( ).
15

- , ,
, .
- ,
I II
. .
, ,
.
, -
, , ,
-.
-.
-
ChangeFirstPlus,
<ChangeFirstPlus 'XY+Z85'>.
- , ,
ChangeFirstPlus,
'XY+Z85' e1 '+' e2
e1 'XY', e2 'Z85'.
- 'XY-Z85',
, ,
.

ChangeFirstPlus :
Num1
Num2

= '731'
= '+1230'

,
.
-
<ChangeFirstPlus <Num1> <Num2>>
-
<Num1>, '731',
, ,
Num1.
:
<ChangeFirstPlus '731' <Num2>>
<Num2>,

16

<ChangeFirstPlus '731+1230'>
,

ChangeFirstPlus e1 '731', e2 '1230'.


'731-1230',
. -
'731-1230' .
1.5.

-
, . ,
-,
.
- 'for ' e1 '=' e2 'to' e3 'do' e4
'for i=1 to 12 do n:=n+1'
: e1 'i', e2 '1 ' ( 2
, ), e3 ' 12 '( 3
: , 1, 2, ), e4 ' n:=n+1'.
- s1 e2 ')' e3
'A*(B+C)-D'

:
s1 'A',
e2 '*(B+C', e3 '-D' ( -
, ).
- e1 '+' t2 e3
'X-5*Y+8/Z' :
e1 'X-5*Y', t2 '8', e3 '/Z'.

. -

.
:
1. -
-, , 'g' 'g'.
2. ,
. , e-
, ;
t- ; s-
-.

17

3. -

. , ,
- s1 e2 s1 'abca'
(s1 'a', e2 'bc'), 'abcd'.
4.
( )
. ,
.
- ,

-
, -
. -
.
-
,
. -,
, s- t-
, ,
,
. -,
s- . t-
( ),
( ).
:
,
, .. .
,
-
'A'(e1 t2)s3

'A'(('2'))'7'
(. . 1):
1.
- 'A' - 'A';
2.

;
3.


-;
4.
t2 -
('2');
18

e1 ;
s3 - '7'.

5.
6.

'A'

'A'

t2

'2'

''

s3

'7'

1.
.
- s1(e2 ',' e3)
'c'('ga,d'),
s1 'c', e2 'ga', e3 'd'. sx ty
sx 'c', ty ('ga,d').
')' '(' -
s-, .
- .
(e1(s2'('))
('a)'('b('))
e1 'a)' s2 'b'.
,
-

e-


. , e1'+'e2
'a+b+c' : e1 'a',
e2 'b+c' e1 'a+b', e2 'c'.
, -
,
.
19

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

, . -
.
, 1 2
'a+b+c'
:
e1 ,
e2 'a+b+c';

:
e1 'a+b+c', e2 .
ChangeAllPlus,
1.3, .
-
<ChangeAllPlus 'A+B+C'>. -

ChangeAllPlus, 'A+B+C'
e1 '+' e2 e1 'A', e2 'B+C' (
).
<ChangeAllPlus '-B+C'>
,
, '-B+C'
-
ChangeAllPlus,
e1 '-B', e2 'C'.
:
<ChangeAllPlus '--C'>

20

- ( )
'--C',

1 '--C' ( +).
-,
,
'A--'
<ChangeAllPlus 'A+B+C'>
1.6.

,
,

,
.
:
,
, ..
.

.

. -
.

,
-.
-
.
1: ChangeAllPlus,
1.3:
ChangeAllPlus e1 '+' e2 = <ChangeAllPlus e1 '-' e2>
e1 = e1

+ -. ,
, (
+), 1
, + .

2

21

+, . ,
:
* ChangeAllPlus
* ,
* : 'A+B+C' 'A-B-C'
ChangeAllPlus e1 '+' e2 = e1 '-' <ChangeAllPlus e2>
e1 = e1

, .. -

.
,
<ChangeAllPlus 'AX+BY+CZ'>
-
ChangeAllPlus,
'AX+BY+CZ' e1 '+' e2 e1 'AX',
e2 'BY+CZ'.
-
'X-'<ChangeAllPlus 'BY+CZ'>
,
, 'BY+CZ'
-
ChangeAllPlus,
e1 'BY', e2 'CZ'.
:
'X-BY-'<ChangeAllPlus 'CZ'>
- ( )
'CZ',
1 'CZ'
( +).
'AX-Y-Z',

<ChangeAllPlus 'AX+BY+CZ'>.
2: Palindrom, ,
.
, , ,
, , , ,
.

22

4 , ,
( )
'yes' 'no'.
* Palindrom, ,
*
Palindrom
s1 e2 s1 = <Palindrom e2>
s1 = 'yes'
= 'yes'
e1 = 'no'
:
s1,
2 .
Palindrom.
.
(
), (
, -
).
(
, , ).
Palindrom
,
.
, Palindrom (
'no') ,
.
,
:
,
.
-
<Palindrom ''>.
-
Palindrom, : s1 '', e2 ''.
<Palindrom ''>.
,
: s1 '', e2 '',
: <Palindrom ''>.
23

,
, : s1 ''.

<Palindrom ''> 'yes'.
-,
.
'yes'
<Palindrom ''>.
3: DelRepSymb,
, ..
. ,
.
* DelRepSymb
* ,
* .
* , 'abaacebf' 'abcef'
DelRepSymb e1 sA e2 sA e3 = e1 <DelRepSymb sA e2 e3>
e1 = e1
,
, , .
.

.
, 1,
, 1
,
( ), , 1
. ,
, sA

.
2 3,
sA, .
,
, .

<DelRepSymb 'abaacebf'>.
DelRepSymb,
e1 sA e2 sA e3
24

'abaacebf' : e1 ,
sA 'a', e2 'b', e3 'acebf'.

<DelRepSymb 'abacebf'>.
,
: e1 , sA 'a', e2 'b',
e3 'cebf'.
: <DelRepSymb 'abcebf'>.
,
: e1 'a',
sA 'b',
e2 'ce',
e3 'f', : 'a'<DelRepSymb 'bcef'>.

,
. ,
DelRepSymb, 'abcef'
.
.

:
* DelRepSymb2
* ,
*
* , 'abaacebf' 'acebf'
DelRepSymb2 e1 sA e2 sA e3 = e1<DelRepSymb2 e2 sA e3>
e1 = e1

,
,
<DelRepSymb2 'abaacebf'>
'acebf'.
4: ,
, ..
: , 'abcde'
'edcba'.
* RevString
* ()
RevString
s1 e2 = <RevString e2> s1
=
25

,
s1 2, s1
, 2.
( ) .
,
.

<RevString 'abc'>.
( : s1 'a', e2 'bc')
: <RevString 'bc'>''.
(s1 'b', e2 'c')
(s1 'c', e2 ),

<RevString 'c'>'b'

<RevString >'cb'. -
,
,
'cb', .
RevString ,
-. ,
, .
5: , . ,

'a'('b'('cd'))('ef')

('fe')
(('dc')'b')'a'.
* RevExp
*
RevExp s1 e2 = <RevExp e2> s1
(e1) e2 = <RevExp e2> (<RevExp e1>)
=
RevExp ,
s1
, 2
RevExp. 2 :
,
.
RevExp .

26

-
<RevExp 'a'('b'('cd'))('ef')> (
-).
1. :
<RevExp 'a'('b'('cd'))('ef')>
RevExp.
: s1 'a', 2 ('b'('cd'))('ef').
,
<RevExp ('b'('cd'))('ef')> 'a'.
2.
<RevExp ('b'('cd'))('ef')>
(..

),

:
1 'b'('cd'), 2 ('ef').

:
<RevExp ('ef')> (<RevExp 'b'('cd')>) 'a'
3. <RevExp ('ef')>
, :
1 'ef',
2 .

<RevExp > (<RevExp 'ef'>),


:
<RevExp > (<RevExp 'ef'>)(<RevExp 'b'('cd')>) 'a'
4. <RevExp >
RevExp,
. -
:
(<RevExp 'ef'>)(<RevExp 'b'('cd')>) 'a'
5. <RevExp 'ef'>

s1 'e', 2 'f'. <RevExp 'f'>'e',
:
(<RevExp 'f'>'e')(<RevExp 'b'('cd')>) 'a'
6. <RevExp 'f'>
, : s1 'f',
2 . <RevExp >'f',

27

:
(<RevExp >'fe')(<RevExp 'b'('cd')>) 'a'
7. : <RevExp >
,
. -
('fe')(<RevExp 'b'('cd')>) 'a'
8. : <RevExp 'b'('cd')>
RevExp, :
s1 'b' 2 ('cd'). <RevExp ('cd')>'b',
('fe')(<RevExp ('cd')> 'b') 'a'
9. : <RevExp ('cd')>

e1 'cd',
2 .

<RevExp>(<RevExp 'cd'>), :
('fe')( <RevExp>(<RevExp 'cd'>)'b') 'a'
10. <RevExp >
: ,
-: ('fe')((<RevExp 'cd'>)'b') 'a'
11. : <RevExp 'cd'>
, :
s1 'c', 2 'd'. <RevExp 'd'> 'c',
:
('fe')
((<RevExp 'd'>'c')'b') 'a'
12. : <RevExp 'd'>
s1 'd',
2 . <RevExp >'d',
: ('fe')((<RevExp> 'dc')'b') 'a'
13. : <RevExp >
,
- : ('fe')(('dc')'b')'a'
14.
, - 'a'('b'('cd'))
('ef').

28

2. -2
,
-6 .
-2 ,
,
-2 (
),
. -2,
( , ), [8].
2.1.

-2 :
< >
( )
/ ' : = +
S W V E s w v e R L

-2.
- ('z', '+', '7' ..)
.
, ,
. ,
s-.

/, : /alpha/, /178/, /abcd/.
/.
-
-.
-

24
0 16777215 (2 -1),
/. : /0/, /1/, /512/, /23/. -
- , -2
,
. , ,
- . ,
-38 :
29

'-'/38/. , -2
-.
(, 224),
,
224. , /1//0/ 224, ..
16777216, /3//21//35/
3(224)2+21(224)1+35(224)0=844425282453539.
-

,
..
, -, .
- ,
255 , .
, -, 255
, . -: /Lh/,
/L24/, /---/.
- -
, -. -

,
.
-:
(/const/ '=3.14, one=1')(/type/ 'i, n: integer').
-2 - ,
/ , <func 'get+2+3'>
</func/ 'get+2+3'>.

: </func/ sx>
<func sx>, <funcsx> (
funcsx).
,
.
-2.
,
(s S, w W, v V, e E). -
. , -
/ab/, /Ab/, /aB/, /AB/, -
- /AB/.
-,
. ,
: -
30

(, - '' '' ),
: SX Sx
, SX sX .
,
, -.
, .
.
'' - (
, ' ' ,
). , A'C 'A''C',
'A'B '''A''B', A'B'
'A''B'''.
,
, , '' ''''.

, , 'XY' '+Z3' XY+Z3,
'XY''+Z3' XY'+Z3.
-
. , A'B
: 'A' '' 'B',
'A''' 'B', 'A' '''B' 'A''B'
-
,
, .
2.2.

-2 :
_ []

. .
: s S, w W, e E, v V (
). ,
S-: S1, S2 sA; W-: W1 W; V-: v9
VZ; E-: E1, e5 EA.
.
, .

31

:
S-, , - -;
W-,
;
E-,
( ).
V-,
;
, S-
: 'G', '+', /172/, /alpha-beta/.
'172', '-'/172/,
('a+b'),
,
. W- ,
, 'G', '+', /172/, /alpha/, ('a+b'),
'172', '-'/172/, ''('a+b'),
, .
V- E-,
,
,
E-. ,
W-.
-2
,
,
.
,
, :
::= (_) |
.
,
.
, : '', /21/, /beta/,
, ,
. -:

32

_ ::= - | - | - |
_ |
_ ::= S | F | N | O | L | D | W | B
:
S ;
F -;
N -;
O - ( );
L ( );
D ;
W ;
B , .. (R), R
.
,

:
__ ::= |
_ __
, L'5'
5, LD .

- , . ,
'+-*/' ,
D'ABCDEFabcdef'
A, B, C, D, E, F, a, b, c, d, e, f, ..
.

:
_ ::= __ |
__
(__) _
Cn+ (Cn-) Cn-1+(Cn-1-) C1+(C1-) C0 , n 0 ,
Ci+ Ci- ,
. n=0,
C0, .
n 1, Mn
:
33

Mn = Cn+ (Mn-1 \ Cn- )


\ , Mn-1
, Cn-1+(Cn-1-) C1+(C1-) C0 .
, C0 n 1
, C0 W ( ).

:
'ABC' - 'A', 'B', 'C';
('ABC') -, -
'A', 'B', 'C';
('A')L , 'A';
('XY')L('0')D - , 'X' 'Y',
, '0'.
, ,
,
. S- W-
,
V- E- ,
,
.
,
:
S(('89')D)1 ;
S(D'abcdefABCDEF')2 ,
, 9, ,
;
S((/0/)N)3 , ;
W(B)4
;
V(('89')D)5 ;
V(D'abcdefABCDEF')6 ;
V('+-')x '+' '-';
E('+-')x , ,
'+' '-';
E(('+-'))X ,
'+' '-', ,
, ('+')('-'), '+'('-');
34

E(B)x , ,
, : ('A+D-S')(/56/'+'/45/)()('A'('BC')'DE').
S(L)x E(LD)y
, ..
, .
,
( )
, ,
: S( (/0/) N )3 S((/0/)N)3.

,
:
::= :_:

-
_ S _
()
.

. ,
:
ArOper S '+-*/'
LogOper S 'V&'
, -
S:ArOper:x S(:ArOper: :LogOper:)y.
Sx , Sy
.
,
, :_:

(:_:),

S:ArOper:x S(:ArOper:)y
.
.
, -,
-.
:
,
.
35

Binary,
Octal Decimal , :
Binary S '01'
Octal S :Binary: '234567'
Decimal S :Octal: '89'
2.3.

.

(-) ,
, .
.
-
, .
,


, .
, (
). , -
S(('A'))X S(('B'))X = SX
S(('AB'))X SX = SX
S(('AB'))X SX = S('CD')X
-
S- W-
. -
V- E-
.
.
V- E
( -),
, ..
,
.. V- E -
.

36

, - e1';'e2
'a:=2; b:=a; c:=a+b' e1
'a:=2', e2
' b:=a; c:=a+b'. e1
'a:=2; b:=a', e2 ' c:=a+b'.

- -
R. R
. R
, , R ,
:
R e1';'e2 = e1(e2)
R L,
:
L e1';'e2 = e1(e2)

'a:=2; b:=a; c:=a+b',
'a:=2; b:=a'(' c:=a+b').

'a:=2'(' b:=a; c:=a+b').
- ,
- ,
L .
,
.
Implic,
, ( )
->.

, ,
'p->q->r->z' '((p->q)->r)->z' .
* Implic
* ,
Implic R e1 '->' s2 = '('<Implic e1>')->' s2
e1 = e1


.

37

2.4.

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


. -2 -
( ,
224), - '+' '-'.
- /0/,
.
- ,
,
-,
: (_)_, (N1)N2.

.

.
1)
<Add (N1)N2>
, N1 N2. ,
<Add ('+'/3/)'-'/5/> '-'/2/
<Add (/34/)/90/> /124/
2)
<Sub (N1)N2> N1 N2. ,
<Sub (/12/)/5/> /8/
<Sub ('-'/2/)'-'/8/> /6/
3)
<Mul (N1)N2>
N1 N2. ,
<Mul (/3/)'-'/5/> '-'/15/
38

4)

5)

6)

7)

8)

<Div (N1)N2>
N1 N2. ,
<Div (/12/)/5/> /2/
<Dr (N1)N2>

(), N1
: N1=N2*+. ,
<Dr ('-'/14/)/5/> '-'/2/('-'/4/)
<P1 N> - N
;
0 16777214 (=224-2). :
<P1 /0/> /1/
<P1 /675/> /676/
<M1 N> - N
;
1 16777215 (=224-1). ,
<M1 /350/> /349/
<Nrel (N1)N2>
(N1)N2, '<', '=' '>',
, N1 ,
N2. :
<Nrel ('+'/3/)'-'/5/> '>'('+'/3/)'-'/5/
<Nrel ('-'/8/)'-'/5/> '<'('-'/8/)'-'/5/
<Nrel ('+'/3/)/3/> '='('+'/3/)/3/


:
<Add (/12//34/)/7//90/> /19//124/
<Add ('-'/16777210/)'-'/8/> '-'/1//2/
<Sub (/1//2/)/8/> /16777210/
<Mul ('-'/12345/)'-'/12345/> /9//1404081/
<Div ('-'/9//1404081/)/12345/ '-'/12345/
<Dr (/1//4/)/25/> /671088/(/20/)
<Nrel (/16777215/)/1//2/> '<'(/16777215/)/1//2/
<Nrel ('-'/16777215/)'-'/1//2/>
'>'('-'/16777215/)'-'/1//2/

39

10)

11)

12)

13)

14)

15)

-
9) Numb ,
,
( -2147483647
2147483647=231-1). ,
<Numb '-27'> '-'/27/
<Numb '+15'> /15/
<Numb '2147483647'> /127//16777215/
Symb , ..
-
( , Numb).
,
<Symb '-'/348/> '-348'
<Symb /127//16777215/> '2147483647'
Cvb Numb .
,
<Cvb '12345678901234567890'>
/43860//11111659//2034386/
<Cvb '-27'> '-'/27/
Cvd Symb .
,
<Cvd '-'/43860//11111659//2034386/>
'-12345678901234567890'
<Cvd /348/> '348'
Ftochar , -. ,
<Ftochar /REF/> 'REF'
Chartof -
- ,
. ,
<Chartof 'Lr25'> /LR25/
<Ftochar <Chartof 'AsDf'>> 'ASDF'
Chartof -
.
Functab , . , -
-, -
40

Chartof. -
<Functab -> .

16) Lengw -,
,
-, ,
<Lengw 'AS'('ADF')'DF'> /5/.
, .. <Lengw> /0/.
17) First -,
-,

, .
.

, ,
- '*'. ,
<First /3/'a'('b')'cd'('e')> ('a'('b')'c')'d'('e')
<First /5/'a'('bcd')'e'> '*a'('bcd')'e'
18) Last ,
, ,
- '*'. ,
<Last /3/'a'('b')'cd'('e')> 'a'('b')('cd'('e'))
<Last /5/'a'('bcd')'e'> 'a'('bcd')'e*'

19) Card
Enter.
<Card>,
.
20) Print, Printm, Prout Proutm
,


- ,
. Print Prout
Printm Proutm
: ,
-, Print Prout
41

:
- , - . ,

<Printm /VARX/':='/25/';'/Y/':=-'/9/>
:
/VARX/':='/25/';'/Y/':=-'/9/

<Print /VARX/':='/25/';'/Y/':=-'/9/>
:
'VARX':='25';'Y':=-'9'

21) Openget Openput ,
,
( Openget) (
Openput).
. :
<Openget 'EXAMPLES\data.txt'>
22) Clsget Clsput ,
.
<Clsget> <Clsput>
.
23) Libget ,
,

, .
24) Libput
-,
- '(' ')'.
,
.
Libput .
,

.
Apply
,

.
42

: <Apply _ >,
_ -.
,
<_ >,
. ,
Apply,
.
, :
'N' , 'R'
, 'S'
.
2.5.

.

.
,
.
-2 -, ,
, .

,
-, .
:
(1'='1)(2'='2)...(N'='N)
1, 2, ..., N 1, 2, ..., N
. ,
1, 2, ..., N
- '='.
, 1, 2, ..., N
- 1, 2, ... ,
N. .

Br (Burry ), Dg (Dig Out ), Cp (Copy ),
Rp (Replace ) Dgall (Dig Out All ).
, Cp,
.

43

Br <Br '='>,

,

('='), .. Br,
.
Dg <Dg >.

('=') ,
. ,
.
,
.
Cp , Dg,
, , , ..
('=') .

Rp

<Rp '='_>,
,

('=')

('='_).
, Rp , r, ..
('='_).
Dgall
-, .. <Dgall>

, .. ,
.
.
,
. ,
(, : <Br 'X=A'>,
<Br 'X=B'>), , (
('X=B')), .
Dg Cp ''
('X=B'), ''.
Rp:
,
.
44

2.6.

-2 -
.ref.
,
72 (
).
- , 72 , ,
73-, .
- ,
.
+, ,
,
.
-
.
*, .
- . ,
, .
- , . ,
.
,
.
, .
,
( ), .
-
.
, (
). -2
-, . ,
-
,
, .

45

,
(
).
,
. ,
Psi Alpha:
Psi
Alpha

EMPTY, :
EMPTY _
_
.
_ ::= |
, _
EMPTY
.
Psi Alpha:
EMPTY

Alpha,Psi


EXTRN, :
EXTRN _
_ ::= _ |
_, _
_ ::= _ |
_(_)
EXTRN
.
-2.
,
. , Mul Sub
,
:
EXTRN (Mul),(Sub)
Mul Sub

.
46

- START
END. :
START
-
END
, START
, .
START END
.
- Go,
ENTRY:
ENTRY

Go

ENTRY .
Go , :
Go

= _

-
, ,
.
- -
<Go>,
- <Go>
_, .
-,
,
.
Factorial START
*
*
EXTRN (Mul),M1,Prout,Card
ENTRY Go
* Go
Go = <prout ' : '> +
<fact <card>>
*
EXTRN numb,cvd

47

*
fact v(D)1 = <prout <cvd <fact1 (/1/)<numb v1>>>>
E1 = <prout ' '>
*
fact1 (v1)/1/ = v1
(v1)v2 = <fact1 (< (v1)v2>)<M1 v2>>
END
-, , ,
prog.ref,
Refal2 refgo prog.ref.
- ,
-2
k . ( < k, > ),
-.
.

48

3. -5
-5 , -2,
,
-2.
,
,
. -5
-2.
3.1.

-2
-5 :
W- V-. , -5
: s-, t e-
, (..
) .

, ,
.

, ..
.
-

where-, .
- ,
-,
.
with-,
-
-, , .
,
.

49

-5 .
:
.
;
s, t ;
; -,
;
{ } : , ;
: ,
where-
-,
, with-;
, & where- with .
, -5 :
' ( ) < > = s t e = . ; : { } , &
,
-2 : - . -5 ,
,
, , True, X, Begin,
3, 853.
-, :
X23 '+' 678 '*'(Z45 '-' Fsr '/' 936)
-5 15
- ,
,
. -5
,
, .
() s, t, e.
::= _ | _ |
_. | _._
_ ::= s | t | e
: e.True, tA, t.28, s.First, e.last, s2.
, ,
, (). ,
50

,
: e.X eX
.
,
. ,
.
, t1 t2 t3,
t1t2t3, t ,
.
t.1t.2t.3 .
-5
-2. -
. , ,
, .
,
.
_ ::= _ { } |
$ENTRY _ { }
::= | ; | ;
, Palindrom (. 1.6)
-5 :
* Palindrom ,
*
Palindrom { s.1 e.2 s.1 = <Palindrom e.2> ;
s.1 = 'yes' ;
= 'yes' ;
e.1 = 'no' ;
}
, $ENTRY
, -
(. 3.5).
3.2.

, where-,
-5 , (
&, ).

51

.
, ,
.
, ,
. -5
:
_ =
_ ::=
, _ |
::= :
::=
- : -,
:,
.
, .

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

. -
, ,
- ,
. ,
,
,
.

,
.

52

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

i,
i .
,
. , , ..
, .
i i
, - i-1:i-1
,
- Pi-1 ( i=1

).
, - .
i-1 i-1, -
i i,
. ,
i:i , ,
, i, .

, '+' '-'
(
) ,
, , ,
, . ,

'X*Y/8*'('Z/3-56')'+9*A-23*B'
('X*Y/8*'('Z/3-56'))'+'('9*A-23*B')
* Search-plus-minus
* ,
* + -

53

Search-plus-minus {
e.1 s.2 e.3 , '+-' : e.X s.2 e.Y =
(e.1) s.2 (e.3);
e.X = e.X }

e.1 s.2 e.3, s.2,
'+'
'-' e.X s.2 e.Y
- '+-'.
, .

, ,
s.2
.

s.2 '+' '-' (
e.X, e.Y
). ,
s.2 '+' '-',
, .1 .3
.
(
s.2 , )
,
.1 , ,
s.2 ( )
.
, ,

s.2, .1
, s.2 '+' '-'
.
'+'
'-',
( s.2)
, .

54

3.3.

-5 :
_ , _
_ ::= : { }

- :

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

,
.
, , . ,
,
- ( ).

- ,

( ).
,
,
55

.
,

.

Tran, ,
, ,
*. , Tran
, 'No'. ,

Tran

'X-2+Y*P/3=9*A=5*Z-8' ('A=5').
Tran Fract ,
, , F
.
*
Fract { s.1 '=' s.2 = T;
e.X = F }
* Tran
* , ,
* 'No'
Tran { e.1 '*' e.2 , <Fract e.1>: { T = (e.1)
F = <Tran e.2> };
e.X = 'No' }
,
, .

, .
OrdABC ,
. ,
'',
'' '', '' '', ''
''. F.
*
*
*
*
*
*

OrdABC ,

'',
'',
''.
F.
56

OrdABC {
e.X 'A'

e.X

e.1 , e.1 :
{ e.Y 'B' e.2 , e.2 :
{ e.Z 'C' e.3 =
e.Z = F } ;
e.Y = F } ;
F }

T ;


:
SimpleOrdABC {
e.X '' e.Y 'B' e.Z 'C' e.D = T ;
e.X = F
}
, ..
-,
.
OrdABC :
'' , ''. ''
, '', ,
, .
''. ( F) .
3.4.

-5,
,
-2.
, , -2.
-5 [9, 10].

1)
2)
3)



, ,
. , -2,
(N1)N2.
:
Add ( +) .
Sub ( -)
.
Mul ( *)
.
57

4)
5)
6)

7)

Div ( /)
.
Mod
.
Divmod ( Dr -2)
() ,
: N1=N2*+.
Compare ( Nrel -2)
: '-', -
N1 N2, '+',
, '0', .

:
- , :
8)
Numb
(), .
9)
Symb , ..
() .
10)
Explode .
11)
Implode , ,
, 0 ,

.
:
<Implode 'sd12'> Asd12
<Implode 'sd12y/89'> Asd12y '/89'
<Implode '12(as)kl'> 0 '12(as)kl'

:
12)
First
.
,
( ), .
:
<First 4 '+'('B-C')'*D'> ('+'('B-C')'*')'D'
<First 7 '+'('B-C')'*D'> ('+'('B-C')'*D')
13)
Last

58

. :
<Last 3 '+'('B-C')'*D'> ('+')('B-C')'*D'
<Last 7 '+'('B-C')'*D'> ()'+'('B-C')'*D'

14)
15)

:
Lower .
Upper .
, ..

:
16)
Lenw ( Lengw -2),
, .
,
<Lenw '+'('B-C')'*D'> 5 '+'('B-C')'*D'
:
17)

Type -
-, .
:
'Ll' -;
'D0' -;
'Wi' ;
'N0' ;
'0' ;
'Pl' ;
'*0' .
:
<Type '5bn9'(36)> 'D05bn9'(36)
<Type (Num)'5bn9'(36)> '0'(Num)'5bn9'(36)
<Type '/5bn9'(36)> 'Pl/5bn9'(36)
<Type> '*0'

,
18)
Card ,
;
0.

59

19)

20)

21)
22)
23)

24)
25)
26)
27)
28)

Print Prout ,

.
Open .
: <Open Mode Descr File-name>,
Mode 'r' 'R' ( ), 'w' 'W'
( );
Descr ( 1-19, 0
);
File-name , .
Get , ,
.
Put ,
.
PutOut Put, .
, ,
-2,
.

Br .
Dg .
Cp .
Rp , .
Dgall .


29)
Time ,
, , , .
30)

Mu

:
<Mu Fname Expr> <Mu (String) Expr>.
Fname ( ),
, <Implode String> (
) Expr.
<Fname Expr>
<<Implode String> Expr>. Mu
(.. ,
), .

60

3.5.

-5 ,

$ENTRY.
, ,
external-.
-:
::= _ | _ |
_ ; | external- ; |
external- ;
external- ::= $EXTERNAL __ |
$EXTERN __ |
$EXTRN __
__ ::= _ |
_ , __
, $ENTRY, $EXTERNAL
() .
,
;,
. ,

- . external ;.
-5
( -2) . ,
*. - ,
/* */,
, .
-2, -
Go;
$ENTRY.
-2, external .
,
:
prog.ref, fact.ref.
61

*
$EXTRN Fact ;
$ENTRY Go {
= <Prout ' : '>
<Check <Card>>
} ;
* , * , .
* ,
* ' '.
Check { s.1 e.2 ,
<Subset s.1 e.2 ('1234567890')> : True
= <Prout <Fact <Numb s.1 e.2>>> ;
e.1 = <Prout ' '>
} ;
* ,
* .
Subset { (e.1) = True ;
s.1 e.2 (e.3 s.1 e.4) =
<Subset e.2 (e.3 s.1 e.4)> ;
e.1 = False
}
*
$ENTRY Fact { e.1 = <Fact1 (1) e.1> };
Fact1 { (e.1) 1 = e.1 ;
(e.1) e.2 = <Fact1 (<* (e.1) e.2>)<- (e.2) 1>>
}

, :
refc prog
refc fact

: prog.rsl
fact.rsl, :
refgo prog+fact

62

4.

.
-2
-5 ,
-2.
4.1.

,
( ).

1.
Erase,
, ..
.
''. ,
Erase
'Hewritesaswellasshe'
'Hewritesaswellasshe'
:

, , .
* Erase ,
* 1
Erase
e1 '' e2 = <Erase e1 '' e2>
e1 = e1
:
( ) ( ,
).
.
.
, ,
1,
. 1 ,
-

63

. ,
1 :
* Erase ,
* 2
Erase
e1 '' e2 = e1 <Erase '' e2>
e1 = e1

Erase
, .

-
'Hewritesaswellasshe':

1
2
3
4
5
6

-
<Erase 'Hewritesaswellasshe'>
'Hewrites'<Erase 'aswellasshe'>
'Hewrites'<Erase 'aswellasshe'>
'Hewritesas'<Erase 'wellasshe'>
'Hewritesas'<Erase 'wellasshe'>

'Hewritesaswellasshe'

2.
Correct,
, #.
#,
. ,

'Children### is playe#ing'

'Child is playing'.
,
:
* Correct
* #,
Correct e1 sA '#' e2 = <Correct e1 e2>
e1 = e1

64

'#'
,
. .

(
) , #.

1 , ..
.

.
.
,
, .. 1.

Correct,
Cor
:
* Correct
* #,
Correct e1 = <Cor ( ) e1>
Cor (e1 sX) '#' e2 = <Cor (e1) e2>
(e1) e2 sX '#' e3 = <Cor (e1 e2) e3>
(e1) e2 = e1 e2
Cor
(.. ) #
#,
.
Cor ,
#,

, .
,
. ,
.
,

,
Cor,
.
65

-

'Children### is playe#ing'.

1
2
3
4
5
6
7

-
<Correct 'Children### is playe#ing'>
<Cor ()'Children### is playe#ing'>
<Cor ('Childre')'## is playe#ing'>
<Cor ('Childr')'# is playe#ing'>
<Cor ('Child')' is playe#ing'>
<Cor ('Child is play')'ing'>

'Child is playing'

3.
Count,
'A'. ,
<Count 'CATS AND DOGS ARE NOT FRIENDS'> 3.


: 'A',
'A' 1
(
).
'A', 0.
* Count
*
Count
e1 'A' e2 = <Add (/1/)<Count
e1 = /0/

e2>>


-
Add , Count
'A'. 'A' , Count
/0/,

.
,

'CATS AND DOGS ARE NOT FRIENDS' :

66

1
2
3
4
5
6
7
8

<Count 'CATS AND DOGS ARE NOT FRIENDS'>


<Add (/1/)<Count 'TS AND DOGS ARE NOT FRIENDS'>>
<Add (/1/)<Add (/1/)
<Count 'ND DOGS ARE NOT FRIENDS'>>>
<Add(/1/)<Add(/1/)<Add(/1/)
<Count 'RE NOT FRIENDS'>>>>
<Add (/1/)<Add (/1/)<Add (/1/) /0/>>>
<Add (/1/)<Add (/1/) /1/>>
<Add (/1/) /2/>
/3/

,
( )
'A' .
, -
(
),
. ,
-
.
?

,
,
.
. ,

.

CountR: ,

'A'.
.

,
CountB CountR,
:
* CountB:
*
CountB e1 = <CountR (/0/)e1>
*
CountR (s1)e2 'A' e3 = <CountR (<Add (/1/)s1>)e3>
67

(s1)e2 = s1
,
-

'CATS AND DOG ARE NOT FRIENDS' -:

1
2
3

-
<CountB 'CATS AND DOGS ARE NOT FRIENDS'>
<CountR (/0/)'CATS AND DOGS ARE NOT FRIENDS'>
<CountR (<Add (/1/)/0/>)
'TS AND DOGS ARE NOT FRIENDS'>
<CountR (/1/)'TS AND DOGS ARE NOT FRIENDS'>
<CountR (<Add (/1/)/1/>)
'ND DOGS ARE NOT FRIENDS'>
<CountR (/2/)'ND DOGS ARE NOT FRIENDS'>
<CountR (<Add (/1/)/2/>)'RE NOT FRIENDS'>
<CountR (/3/)'RE NOT FRIENDS'>
/3/

4
5
6
7
8
9

,
'A'
.
,
.
4.2.

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

4.
, ,
'(' ')'
, , '5/((A+B)^2-(A-B)^3)+8*A'

68

'5/'(('A+B')'^2-'('A-B')'^3')'+8*A'.
, .


. ,

, ,
, . ,

( ) ,

.
:
,
, ,
. ,
Error , ,
.
-2
:
RBrac , LBrac
.
* -2:
* RBrac
RBrac e1 ')' e2 = <RBrac <LBrac e1> e2>
e1 '(' e2 = <Prout ' '><Error>
e1 = e1
* LBrac
*
LBrac
R e1 '(' e2 = e1(e2)
e1 = <Prout ' '><Error>
, LBrac
, ,
, ( )
.
RBrac ,
,
.
1,
, LBrac,
69

.
LBrac RBrac
,
,
.
, RBrac
, ,
, LBrac
, .
-5 RBrac
. , -5
, LBrac
. ,
'(' ,
, 2
'('.
Check.
-5:
* -5:
* RBrac
RBrac { e.1 ')' e.2 = <RBrac <LBrac e.1> e.2> ;
e.1 '(' e.2=<Prout ' '><Error>;
e.1 = e.1
}
* LBrac
*
LBrac { e.1 '(' e.2 , <Check e.2> : True = e.1(e.2) ;
e.1 = <Prout ' '><Error> }
* , *
Check { e. '(' e. = False ;
e. = True }
-
-2
'5/((A+B)^2-(A-B)^3)+8*A':

1
2
3
4

-
<RBrac '5/((A+B)^2-(A-B)^3)+8*A'>
<RBrac<LBrac '5/((A+B'> '^2-(A-B)^3)+8*A'>
<RBrac '5/('('A+B')'^2-(A-B)^3)+8*A'>
<RBrac<LBrac '5/('('A+B')'^2-(A-B'> '^3)+8*A'>
70

5
6
7
8

<RBrac '5/('('A+B')'^2-'('A-B')'^3)+8*A'>
<RBrac<LBrac '5/('('A+B')'^2-'('A-B')'^3'> '+8*A'>
<RBrac '5/'(('A+B')'^2-'('A-B')'^3')'+8*A'>
'5/'(('A+B')'^2-'('A-B')'^3')'+8*A'

5.
: ,
.
,
,
. , '5/
([A+B]^2-{A-B}^3)+8*A'
'5/'(('[A+B]')'^2-'('{A-B}')'^3')'+8*A'.
, ,
:
,
.
,
, , (
) (
). ,
.
:
, .
* -2: ,
*
* RBrac
*
RBrac e1 s(')]}')A e2 = <RBrac <LBrac e1 sA> e2>
e1 s('([{')B e2 = +
<Prout ' '><Error>
e1 = e1
* LBrac
*
LBrac
R e1 s('([{') e2 = e1 <EqBr s e2>
e1 = <Prout ' '><Error>
* EqBr ,
* ,
*
EqBr '(' e1 ')' = (e1)
'[' e1 ']' = ('[' e1 ']')
'{' e1 '}' = ('{' e1 '}')
71

e1

<Prout

' '><Error>


'5/([A+B]^2-{A-B}^3)+8*A':

1
2
3
4
5
6
7
8
9
10
11

-
<RBrac '5/([A+B]^2-{A-B}^3)+8*A'>
<RBrac<LBrac '5/([A+B]'> '^2-{A-B}^3)+8*A'>
<RBrac'5/('<EqBr '[A+B]'> '^2-{A-B}^3)+8*A'>
<RBrac '5/('('[A+B]')'^2-{A-B}^3)+8*A'>
<RBrac<LBrac '5/('('[A+B]')'^2-{A-B}'> '^3)+8*A'>
<RBrac'5/('('[A+B]')'^2-'<EqBr '{A-B}'>'^3)+8*A'>
<RBrac'5/('('[A+B]')'^2-'('{A-B}')'^3)+8*A'>
<RBrac<LBrac '5/('('[A+B]')'^2-'('{A-B}')'^3)'>
'+8*A'>
<RBrac '5/'<EqBr '('('[A+B]')'^2-'('{A-B}')'^3)'>
'+8*A'>
<RBrac '5/'(('[A+B]')'^2-'('{A-B}')'^3')'+8*A'>
'5/'(('[A+B]')'^2-'('{A-B}')'^3')'+8*A'

-2,
, :
s(')]}')A
s('([{')B .
-5 ,

CheckInM ,
.
CheckInM (),
True,
, False .
* -5: ,
*
* RBrac
*
RBrac { e.1 s.A e.2 , ')]}' : e.3 s.A e.4 =
<RBrac<LBrac e.1 s.A> e.2> ;
e.1 s.B e.2 , '([{' : e.3 s.B e.4 =
<Prout ' '><Error> ;
e.1 = e.1
}
72

* LBrac ()
*
LBrac { e.1 s.B e2 , '([{' : e.3 s.B e.4 ,
<CheckInM ('([{')e.2> : True
= e.1<EqBr s. e.2>;
e.1 = <Prout ' '><Error> }
* EqBr ,
* ,
*
EqBr { '(' e.1 ')' = (e.1) ;
'[' e.1 ']' = ('[' e.1 ']') ;
'{' e.1 '}' = ('{' e.1 '}') ;
e.1 = <Prout ' '><Error> }
* CheckInM: True,
*
* , False
CheckInM { (e.1 s.X e.2) e.3 s.X e.4 = False ;
e.1 = True }
4.3.


,
, ..
.

6.
-,
, .

-:
::= ( ',' ) |
::= |
''
'', '0' '1'.

73

, , 2
'A'(''('5,')',0'), ,
3.
,
-, -
:
I.
(
) -.
Tree,
Node.
II.
-
,
-.

Tree.
III.

-
.
.
- .
s-, .. , ..
.
s- w- ( -5 t-),

, .
( ),
( ',' ).
- -5 v- -2 (
).
74

-2:
* Tree ()
Tree s (v1 ',' v2) = <Node s> +
(<Tree v1> ',' <Tree v2>)
s = <Node s>
*
Node 'A' = 'B'
'0' = '1'
s1 = s1

Tree ,
Node,
. Tree
2
. ,

.
,
( ), ,
:
1 = <Prout ' : '1> +
<Error>
-
,
'A'(''('5,')',0'):

1
2
3
4
5
6
7
8
9

<Tree 'A'(''('5,')',0')>
<Node 'A'>(<Tree ''('5,')>','<Tree '0'>)
'B'(<Tree ''('5,')>','<Tree '0'>)
'B'(<Node ''>(<Tree '5'>','<Tree ''>)','<Tree '0'>)
'B'(''(<Tree '5'>','<Tree ''>)','<Tree '0'>)
'B'(''(<Node '5'>','<Tree ''>)','<Tree '0'>)
'B'(''('5,'<Tree ''>)','<Tree '0'>)
'B'(''('5,'<Node ''>)','<Tree '0'>)
'B'(''('5,')','<Tree '0'>)

75

10
11

'B'(''('5,')','<Node '0'>)
'B'(''('5,')',1')

, 11 -
.

7.

( ,
).
(
- -2
-5), , ,
, . ,
5*(2-3)+8/(2*4-7)-11*6
5 2 3 - * 8 2 4 * 7 - / + 11 6 * -.
,
.
-:
::= -add-sub |
::= -mul-div |
::= | ()
-add-sub ::= '+' | '-'
-mul-div ::= '*' | '/'

.

.
, , 7+12-23+5
: ((7+12)-23)+5,
,
.
,

. -
,
,
.


76

,
,
.
-,
6, - ,

PolizExp, PolizSum PolizMult.
.
-
- ,
. -
,
,

. , -add-sub
-mul-div (
).

-
. -add-sub -mul-div
( ) s-, -2
'+-' '*/'.
w- -2 t-
-5, ,
(.. ).
v- -2
( ) - -5.
PolizExp
,
. PolizSum


, ,
(
).
PolizMult ,
,
.
, -2
:
* -2:
77

PolizExp R v1 s('+-')2 v3 = <PolizExp v1> +


<PolizSum v3>s2
v1 = <PolizSum v1>
*
PolizSum v1 s('*/')2 w3 = <PolizSum v1> +
<PolizMult w3>s2
w1 = <PolizMult w1>
*
PolizMult s(N)1 = s1
(v1) = <PolizExp v1>
, -
PolizExp,

,
. - PolizSum
PolizMult , ,
,
. , PolizSum
,
,
.
-
/5/'*'(/2/'-'/3/)'+'/8/'/'/6/'-'/11/,
-2:

1
2
3
4
5
6
7
8

-
<PolizExp /5/'*'(/2/'-'/3/)'+'/8/'/'/6/'-'/11/>
<PolizExp /5/'*'(/2/'-'/3/)'+'/8/'/'/6/>
<PolizSum
/11/> '-'
<PolizExp /5/'*'(/2/'-'/3/)><PolizSum /8/'/'/6/>'+'
<PolizSum /11/> '-'
<PolizSum /5/'*'(/2/'-'/3/)><PolizSum /8/'/'/6/>'+'
<PolizSum /11/> '-'
<PolizSum /5/><PolizMult (/2/'-'/3/)>'*'<PolizSum /
8/'/'/6/>'+' <PolizSum /11/> '-'
<PolizMult /5/><PolizMult (/2/'-'/3/)>'*'<PolizSum /
8/'/'/6/>'+' <PolizSum /11/> '-'
/5/<PolizMult (/2/'-'/3/)>'*'<PolizSum /8/'/'/6/>'+'
<PolizSum /11/> '-'
/5/<PolizExp /2/'-'/3/>'*'<PolizSum /8/'/'/6/>'+'
78

9
10
11
12
13
14
15
16
17
18
19
20

<PolizSum /11/> '-'


/5/<PolizExp /2/><PolizSum /3/>'-*'<PolizSum /
8/'/'/6/>'+' <PolizSum /11/> '-'
/5/<PolizSum /2/><PolizSum /3/>'-*'<PolizSum /
8/'/'/6/>'+' <PolizSum /11/> '-'
/5/<PolizMult /2/><PolizSum /3/>'-*'<PolizSum /
8/'/'/6/>'+' <PolizSum /11/> '-'
/5/ /2/<PolizSum /3/>'-*'<PolizSum /8/'/'/6/>'+'
<PolizSum /11/> '-'
/5/ /2/<PolizMult /3/>'-*'<PolizSum /8/'/'/6/>'+'
<PolizSum /11/> '-'
/5/ /2/ /3/ '-*'<PolizSum /8/'/'/6/>'+' <PolizSum /
11/> '-'
/5/ /2/ /3/ '-*'<PolizSum /8/><PolizMult /6/>'/+'
<PolizSum /11/> '-'
/5/ /2/ /3/ '-*'<PolizMult /8/><PolizMult /6/>'/+'
<PolizSum /11/> '-'
/5/ /2/ /3/ '-*' /8/<PolizMult /6/>'/+' <PolizSum /
11/> '-'
/5/ /2/ /3/ '-*' /8/ /6/ '/+' <PolizSum /11/> '-'
/5/ /2/ /3/ '-*' /8/ /6/ '/+' <PolizMult /11/> '-'
/5/ /2/ /3/ '-*' /8/ /6/ '/+' /11/ '-'


-5 , 5,

CheckInM:
* -5:
PolizExp { e.1 s.2 e.3 , '+-' : e.A s.2 e.B ,
<CheckInM ('+-')e.3> : True =
<PolizExp e.1><PolizSum e.3> s.2 ;
e.1 = <PolizTerm e.1>
}
*
PolizSum { e.1 s.2 t.3 , '*/' : e.A s.2 e.B =
<PolizSum e.1><PolizMult t.3> s.2 ;
t.1 = <PolizMult t.1>
}
*
PolizMult
{ s.1 , <Type s.1> : 'N' e.2 = s.1 ;
(e.1) = <PolizExp e.1> }
* ,
*
CheckInM { (e.1 s.X e.2) e.3 s.X e.4 = False ;
e.1 = True }
79

, - -5
(
5) , -2,
.

80

5.

:
, .
5.1.

-,

,
.
.
D: ,
D ,
, :
Dy:sin(x+2*y)*y^-4+(8*a-b)*sqrt(sin(y-2)+cos(y+9))

-:
::= | _
_ ::= + |
::= | _
_ ::= * | /
::= __ | | ^
| _() | () |
()^
::=
::= __
::= | + |
_ ::= sin | cos | ln | exp | sqrt |
arcsin | arccos
- :

;

81

(
,
, , ,
);
.

.
:

, ,
.

5.2.

n m , n m 1,
(m=2, n=2):
3*x+2*x-16/(1+7)*y=11
x+2*y=7
,
(
, , , ).
-,
.
:
1) :

a*x+b*y+c*z+...+d=0
a, b, c, d .
2)

:
x=-(b*y+c*z+...+d)/a = -b/a*y-c/a*z-...-d/a.
3)

82



, ,
, .
1-3 ,
,
.
( ) ,
(,
6-4=0). -



(0=0), ,
.

,
.
.
_=,
,

,
, :
x=3
y=2

, (,
x+y+2=0), ,
. -
(
)
. ,
:
x+2*y-z=2
2*x-y+3*z=-6
- :
x=-z-2
y=z+2
z

83

5.3.

() .
TRUE FALSE,
: (), (),
(), () ( ),
.
. ,
a1 (b1 a2 c) (c b2).


.

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

(.. ).
, x y x y.

() . xk
f(x1, , xn), n1, kn,
a1, , ak-1, ak+1, , an
f(a1,,ak-1,0,ak+1,,an) f(a1,,ak-1,1,ak+1,,an)
, x ,
( x x ) y z.
:

(
);


;


;

84


.

-.
-
:
;
;
;
.
5.4.

,
TRUE FALSE,
: (), (), (),
(), .
. ,
a (b c d) .


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

. , p q
p q r, q r .
,
,
,

. , q p
p q r.

85

-, ,

( ) . :
;

;
,
, (
) ;
,


;
,
,
,
. ,
x y p q r
: x , y q.

-
-.
5.5.

-, ,
, .
:
x=2,y=3,z=x+=2*y-3*x?++y>4?(8-4)*x:25:x--&&y/3?x<<3:5
, ,
:
++ ;
+ ;
*, / %;
<< >>;
!, &&, ||;
!=, ==, >, <, >=, <=;
?:;
86

=, +=, -=, *=, /=, %=, >>=, <<= ;


(,).


[11] . 1 (
).
:
::= _ |
, _
_ ::= _ |
_ _
_ ::= = | += | -= | *= | /= |
%= | <<= | >>=
_ ::= __ |
__ ? : _
__ ::= __ |
__ || __
...
::= _ |
_ _
_ ::= * | / | %
_ ::= _ |
_ _
_ ::= ! | ++ | -- | + | _ ::= _ |
_1
_1::= |
_1 _
_ ::= ++ | -_ ::= | __ |
()
,
-, .

87

1.
( )
++ -! ++ -- + * / %
+ <<
>>
< <= > >=
==
!=
&&
||
? :
= += -= *= /= %= <<= >>=
,

5.6.

,
.
-.
0, 1
.
::= program ; _ _
::=
_ ::= _ _
_ ::= | const =; {=;}
_ ::= var {; };
::= {, } :
::= integer | boolean
::= {}
::= | + |
._ ::= {}
._::= true | false
_ ::= begin {; } end.
::= _ | _ |
_ | ___ |
___ | __for |
_ | _
88

_ ::= :=
::= _ |
_ _ _
_ ::= > | < | <> | <= | >= | =
_ ::= |
_ _
_ ::= + | - | or
::= |
_
::= | () | ._ | ._ |
not
_ ::= * | div | mod | and
_ ::= writeln(_)
_ ::= {,}
::=
_ ::= begin {; } end
___ ::=
repeat {; } until
___ ::= while do
__for ::=
for := to do
_ ::=
case of {; } endcase
::= _ :
_ ::= | _
_ ::=
if then else

[12].
, :
- ;


;
() ,
-.
89


,
( ).
:

begin end,
case endcase;
;


;
.

,
, , .
for,
- .
,
.
5.7.

-, ,
[12]
, [11].
, ,
.
- :
- ;

;
-
;

90

-,

(, i+=1 ++i);

()
.

- ,
.

5.8.



.

, , ,
:
( )
- ;
( ,
)
-;
(sin, cos .
) (begin, end, case, integer .
-)
- (/sin/, /cos/,
/begin/ ..);
, ,
- (,
: ++ /pp/, *= - /mulassign/);
+ ,
+ .

,
. :

;
91



? :
-, ,
/question/ /two-spot/,
?:
;
-

-
,
-
/begin/ /end/, /then/ /else/, /case/ /endcase/,
/repeat/ /until/ ( ).
,

,

(, , , ..
).

.

92

6.
1.

.. ().
: , 4, 1968.

2.

.., .. -. // 2-
. .
, 1970.

3.

.. .
(. ) .
"", vol. 5, N 33. . :
1974.

4.

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


.., .., .., ..
(.
). (
""), , vol. 5, N 40. : 1977.

5.

.., .. .
. : , 71,
1987.

6.

..
// 3- ., . 3.
: / . ..,
.., : , 1990, . 4755.

7.

.. .. . .: , 1996.

8.

.. -2. : ,
71, 1987.

9.

Turchin V. REFAL-5, Programming Guide and Reference Manual New


England Publishing Co., Holyoke, 1989.

10. ..

-5.
. http://www.refal.net/rf5_frm.htm

11. ., . . :

, 1992.
12. ., . .

. : , 1982.

93

1. -2
- ::= _ START
-__
END
_ ::=
-__ ::= _ |
_
-__
_ ::= | _ |
_
::= ENTRY- |

ENTRY- ::= ENTRY Go

EXTRN-

EMPTY-

EXTRN- ::= EXTRN __


__ ::= _ |
_, __
_ ::= |
(_)
EMPTY- ::= EMPTY _
_ ::= |
, _
_ ::= _ S _
_ ::=
_ ::= __ |
__
(__) _
__ ::= |
_ __
_ ::= - | - | - |
_ |
::= :_:
- ::= ''
- ::= /_/
_ ::= |
_
94

- ::= //
_ ::= S | F | N | O | L | D | B | W
_ ::= _ -_- |
Go = ___
_ ::=
___ ::= _
-_- ::= |
- -_-
- ::=
_ - =
_ ::= | L | R
- ::= | 1 -
1 ::= - | - | - |
| (-)
::= |
::= - | - | - |
| () | <_ >
_ ::= | 2 _
2 ::= - | - | - |
(_) | <_ _>
::= |
::= s | S | w | W | e | E | v | V
::= |
::= | (_)
::=

95

2. -5
::= _ |
_ |
_ ; |
external- ; |
external- ;
_ ::= _ { } |
$ENTRY _ { }
external- ::= $EXTERNAL __ |
$EXTERN __ |
$EXTRN __
__ ::= _ |
_ , __
_ ::=
::= | ; | ;
::= _ = |
_ , _
_ ::=
, _ |
::= :
::=
::= | _
_ ::= - | | |
| ()
_ ::= : { }
::= |
::= - | | |
| () | <_ >
::= _ | _ |
_. | _.
_ ::= s | t | e
- ::= ''
::= _

96