. , , ,

,,,

L — ,

L

 

 

WHILE( ) [, , ...])>];

 

WHILE -

-

- ,

- ,

:

WHILE(A>44

A>44

clrscr() - ,

 

 

 

 

 

 

 

 

 

 

G[Z] L

 

 

, G[Z], Vt, Vn, Z, P, :

Vt -

Vn -

Z -

P -

G[<>]:

1. <> à while( ) [<>];

2. à T| < T| > T| <= T | >= T | != T

3. à O | T*O | T**O | T+O | T-O | T/O

4. à () | | <>

5. à {|}

6. <> à {}

7. <> à ([{,}])

8. à | <> | Ω

 

 

 

 

 

 

G[Z]

G[<>]:

1. <> à while( ) [<>];

2. à T| < T| > T| <= T | >= T | != T

3. à O | T*O | T**O | T+O | T-O | T/O

4. à () | | <>

5. à {|}

6. <> à {}

7. <> à ([{,}])

8. à | <> | Ω

 

:

<> à Z

à A

à B

à C

< > à D

à E

<> à F

à G

:

WHILE à a

( à b

) à c

; à d

֠ à f

à g

, à h

G[Z]:

1. Z à abAc[D]d

2. Aà B|A B|A <= B |A >= B |A != B

3. B à C | B*C | B**C | B+C | B-C | B/C

4. C à bAc | E | F

5. E à g{g|f}

6. F à f{f}

7. D à Eb[G{hG}]c

8. G à E | F | Ω

: G[Z] - - .

 

- , . , , .

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

, .

, , .

:

While (A > ) cls();

1. Z à abAc[D]d

2. Aà B|A B|A <= B |A >= B |A != B

3. B à C | B*C | B**C | B+C | B-C | B/C

4. C à bAc | E | F

5. E à g{g|f}

6. F à f{f}

7. D à Eb[G{hG}]c

8. G à E | F | Ω

Z


a b A c D

B A E

C B g{g} b G c

E C Ω

g E

g

While ( A > ) cls ( ) ;

 

while .

_____________________________________________________________________

- While(a>)cls();

While - (

AB

TERM

O

IDENT, - a

AB

TERM

O

IDENT, - )

, - )

FUNC, - c

IDENT, - c

While(a>)cls();

: ()

_____________________________________________________________________

- while(1<(3*(43+5*(3-4-(4<454)))) ;

While - (

AB

TERM

O

IDENT, - 1

, - 1

AB

TERM

O

AB

TERM

O

IDENT, - 3

, - 3

TERM

O

AB

TERM

O

IDENT, - 4

, - 4

TERM

O

IDENT, - 5

, - 5

TERM

O

AB

TERM

O

IDENT, - 3

, - 3

TERM

O

IDENT, - 4

, - 4

TERM

O

AB

TERM

O

IDENT, - 4

, - 4

AB

TERM

O

IDENT, - 4

, - 4

FUNC, - ;

IDENT, - ;

while(1<(3*(43+5*(3-4-(4<454)))) ;

)

:

_____________________________________________________________________

- 435 4 whilei>>3t*(ewqw++()*we) rscr(456,345,rtgrt,345444rtr,,,)

While - i

AB

TERM

O

IDENT, - i

AB

TERM

O

IDENT, - 3

, - 3

TERM

O

AB

TERM

O

IDENT, - e

TERM

O

IDENT, - +

, - +

TERM

O

TERM

O

IDENT, - w

FUNC, - r

IDENT, - r

PAR, - 4

IDENT, - 4

, - 4

PAR, - 3

IDENT, - 3

, - 3

PAR, - r

IDENT, - r

PAR, - 3

IDENT, - 3

, - 3

PAR, - ,

IDENT, - ,

, - ,

435 4 whilei>>3t*(ewqw++()*we) rscr(456,345,rtgrt,345444rtr,,,)

(

)

: ()

;

() -

435, 4,

_____________________________________________________________________

- whiLE(43-(sss<233)fewfew) sd(we)

While - (

AB

TERM

O

IDENT, - 4

, - 4

TERM

O

AB

TERM

O

IDENT, - s

AB

TERM

O

IDENT, - 2

, - 2

AB

TERM

O

IDENT, - f

FUNC, -

IDENT, - s

PAR, - w

IDENT, - w

whiLE(43-(sss<233)fewfew) sd(we)

;

/ * ** + -

_____________________________________________________________________

- while(i>344>(5445<<2323*343243+2343*(w))>23*232) clrscr(,)

While - (

AB

TERM

O

IDENT, - i

AB

TERM

O

IDENT, - 3

, - 3

AB

TERM

O

AB

TERM

O

IDENT, - 5

, - 5

AB

TERM

O

IDENT, - 2

, - 2

TERM

O

IDENT, - 3

, - 3

TERM

O

IDENT, - 2

, - 2

TERM

O

AB

TERM

O

IDENT, - w

AB

TERM

O

IDENT, - 2

, - 2

TERM

O

IDENT, - 2

, - 2

FUNC, -

IDENT, - c

PAR, - ,

IDENT, - ,

, - ,

while(i>344>(5445<<2323*343243+2343*(w))>23*232) clrscr(,)

;

_____________________________________________________________________

- while(u>r+erhgeerg(e>=rwe+++r+788erwe++)) scr(eee,qee<)

While - (

AB

TERM

O

IDENT, - u

AB

TERM

O

IDENT, - r

TERM

O

IDENT, - e

AB

TERM

O

AB

TERM

O

IDENT, - e

AB

TERM

O

IDENT, - r

TERM

O

IDENT, - r

TERM

O

IDENT, - 7

, - 7

FUNC, -

IDENT, - s

PAR, - e

IDENT, - e

PAR, - q

IDENT, - q

PAR, - <

IDENT, - <

, - <

while(u>r+erhgeerg(e>=rwe+++r+788erwe++)) scr(eee,qee<)

;

/ * ** + -

_____________________________________________________________________

- while(i>77777u777) clrscr(,...,)

While - (

AB

TERM

O

IDENT, - i

AB

TERM

O

IDENT, - 7

, - 7

FUNC, -

IDENT, - c

PAR, - ,

IDENT, - ,

, - ,

while(i>77777u777) clrscr(,...,)

;

_____________________________________________________________________ - while(4545>>445--- ;

While - (

AB

TERM

O

IDENT, - 4

, - 4

AB

TERM

O

IDENT, - 4

, - 4

TERM

O

IDENT, -

, -

FUNC, - ;

IDENT, - ;

while(4545>>445--- ;

)

:

_____________________________________________________________________

- while(i>=0);

While - (

AB

TERM

O

IDENT, - i

AB

TERM

O

IDENT, - 0

, - 0

FUNC, - ;

IDENT, - ;

while(i>=0);

:

_____________________________________________________________________

- while(i>=0) 544();

While - (

AB

TERM

O

IDENT, - i

AB

TERM

O

IDENT, - 0

, - 0

FUNC, -

IDENT, - 5

while(i>=0) 544();

;

:

_____________________________________________________________________

- whilei>=0) clrscr();13

While - i

AB

TERM

O

IDENT, - i

AB

TERM

O

IDENT, - 0

, - 0

FUNC, -

IDENT, - c

whilei>=0) clrscr();13

(

: ()

_____________________________________________________________________

- whilertt<=243+++344-23!=345 wwqwq;

While - r

AB

TERM

O

IDENT, - r

AB

TERM

O

IDENT, - 2

, - 2

TERM

O

IDENT, - 3

, - 3

TERM

O

IDENT, - 2

, - 2

AB

TERM

O

IDENT, - =

, - =

AB

TERM

O

IDENT, - 3

, - 3

FUNC, - w

IDENT, - w

whilertt<=243+++344-23!=345 wwqwq;

(

)

_____________________________________________________________________

- while(dd>>3432*23432)

While - (

AB

TERM

O

IDENT, - d

AB

TERM

O

IDENT, - 3

, - 3

TERM

O

IDENT, - 2

, - 2

FUNC, -

IDENT, -

while(dd>>3432*23432)

;

:

H # 10

While

- 513.cpp

- test.513

- error.513

pࠠ : Ӡ

pࠠ : -513

򠠠 :

p : , 򠠠

p p p,

򠠠 ࠠ p pࠠ

ࠠ : 30 1997.

//----------------------------------------------------------------------------

// .

//----------------------------------------------------------------------------

#include

#include

#include

#include

#include

#include

#define UP 72 //

#define DOWN 80 //

#define ALTX 45 //

#define F1 59

#define F2 60

#define F3 61

#define ESC 27

#define FL_NAME "test.513"

#define FL_TEST "error.513"

void open_fl(void); // p

void work_space(void); // p p

void print_page(void); // p

void help_line(void); // p

void help(int);

int scan(); //

int my_while(); // pp

int AB(); //

int TERM(); //

int O(); //

int IDENT(); //

int ZBZ(); //

int FUNC(); //

int PAR(); //

char TEXT[22][80];

int position; //

int cur_y=3; // pp p

int x,y; //

int f=0; // f=1

char screen[4096]; // p p

char screen1[4096]; // p p

char *mistake[]={" !!!", //0

"pp while ", //1

" (", //2

" )", //3

": ()", //4

" ; ", //5

": ", //6

" / * ** + - ", //7

"", //8

" ", //9

" () - ", //10

" ", //11

" ", //12

" ", //13

" ", //14

""}; //15

FILE *fl_t;

int mistake_number[15]; // (0 1)

// 1- , 0

//mistake_number[i], i mistake

char strange[100]; //

//

int s=0; // strange

void main()

{

open_fl();

help_line();

print_page();

work_space();

}

//----------------------------------------------------------------------------

//

//----------------------------------------------------------------------------

void open_fl(void)

{

FILE *fl;

int i;

window(1,1,80,25);

textbackground(BLACK);

textcolor(WHITE);

clrscr();

_setcursortype(_NOCURSOR);

if((fl_t= fopen(FL_TEST,"w"))== NULL) exit(1);

if ((fl = fopen(FL_NAME,"r"))==NULL)

{

window(18,10,60,16);

textbackground(GREEN);

textcolor(BLACK);

clrscr();

gotoxy(5,2);cprintf(" test.513");

gotoxy(5,3);cprintf(" ");

gotoxy(5,4);cprintf(" ");

gotoxy(3,6);cprintf(" ");

getch();

exit(0);

}

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

{

window(40-i,12-i/5,40+i,12+i/5);

textbackground(GREEN);

textcolor(BLACK);

clrscr();

delay(7);

}

textcolor(WHITE);

gotoxy(12,2);cprintf(" ");

gotoxy(12,3);cprintf(" ");

gotoxy(12,4);cprintf(" ");

gotoxy(12,5);cprintf(" test.513 ");

gotoxy(7,8);cprintf(" ");

getch();

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

{

if (fgets(TEXT[i],78,fl)==NULL) break; //

}

TEXT[i][0]=NULL;

position=0; // p

fclose(fl);

}

//----------------------------------------------------------------------------

//

//----------------------------------------------------------------------------

void work_space(void)

{

char c;

while(1)

{

gotoxy(1,cur_y);

c=getch();

switch(c)

{

case UP:

if(cur_y!=3)

{

cur_y--;

print_page();

}

else

{

if(position!=0)

{

position--;

print_page();

cur_y=3;

}

}

break;

case DOWN:

if(cur_y!=7)

{

cur_y++;

if(TEXT[cur_y+position-3][0]==NULL) cur_y--;

print_page();

}

else

{

cur_y=7;

if(TEXT[cur_y+position-2][0]!=NULL)

{

position++;

print_page();

}

}

break;

case F1:

help(1);

break;

case F2:

help(2);

break;

case F3:

help(3);

break;

case ALTX:

window(1,1,80,25);

textbackground(BLACK);

textcolor(WHITE);

fclose(fl_t);

clrscr();

exit(1);

case ESC:

window(1,1,80,25);

textbackground(BLACK);

textcolor(WHITE);

clrscr();

fclose(fl_t);

exit(1);

}

}

}

//----------------------------------------------------------------------------

// , ,

// ()

//----------------------------------------------------------------------------

void print_page()

{

int i,xx=10;

puttext(1,1,80,25,screen);

for(i=0;i<=15;i++) //

mistake_number[i] = 0;

strange[0]=NULL;

s=0;

x=cur_y+position-3;

y=0;

f=0;

fprintf(fl_t,"______________________________________________________________________________n");

fprintf(fl_t," - %sn",TEXT[x]);

scan(); //

fprintf(fl_t,"n %sn",TEXT[x]);

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

if(mistake_number[i] == 1)

{

gotoxy(4,xx++);

printf("%s ",mistake[i]);

fprintf(fl_t," %sn",mistake[i]);

if(i==10 && mistake_number[i] == 1)

{

printf(" %s",strange);

fprintf(fl_t," %sn",strange);

}

}

if(xx == 10) // , ..

{ // (xx)

gotoxy(4,xx++);

printf("%s ",mistake[0]);

}

textbackground(BLACK);

textcolor(WHITE);

if(TEXT[0][0]!=NULL)

{

for (i=1;i<6;i++)

{

if(TEXT[i-1+position][0]==NULL) break;

gotoxy(1,i+2);

puts(TEXT[i-1+position]);

}

}

gotoxy(1,cur_y);

textbackground(RED);

clreol();

puts(TEXT[cur_y+position-3]);

}

//----------------------------------------------------------------------------

//

//----------------------------------------------------------------------------

void help_line(void)

{

window(1,1,80,25);

textbackground(BLACK);

clrscr();

textbackground(GREEN);

textcolor(BLACK);

gotoxy(1,1);

clreol();

printf(" Borland C++ p pp WHILE");

gotoxy(1,25);

textbackground(LIGHTCYAN);

clreol();

cprintf(" F1 - F2 - F3 - ࠠ ALT+X-");

gotoxy(1,2);

textbackground(LIGHTCYAN);

clreol();

printf("------------------------------- C -------------------------------");

gotoxy(1,8);

textbackground(LIGHTCYAN);

clreol();

printf("------------------------------ ----------------------------");

gotoxy(1,9);

gettext(1,1,80,25,screen);

gettext(1,9,80,24,screen1);

}

//----------------------------------------------------------------------------

// , n

//----------------------------------------------------------------------------

void help(int n)

{

char string[4096];

gettext(1,8,80,22,string);

window(1,8,80,22);

textbackground(CYAN);

textcolor(BLACK);

clrscr();

gotoxy(1,1);

if(n ==1)

{

cprintf("n H HH H Hnrr");

cprintf(" p p H Hnrr");

cprintf(" pnnrrr");

cprintf(" :rn");

cprintf(" F1 - HELP.rn");

cprintf(" F2 - p .rn");

cprintf(" F3 - .rn");

cprintf(" Esc - .rn");

cprintf(" Alt-X - .rnnn");

cprintf(" (c) 1997 ");

}

if(n == 2)

{

cprintf("n nnrr");

cprintf(" 1. <> -> WHILE ()[];nrr");

cprintf(" 2. -> T| >T | <=T | >=T | !=Tnrrr");

cprintf(" 3. T -> O | T+O | T-O | T*O | T/O | T**Onrrr");

cprintf(" 4. O ->() | | <>nrrr");

cprintf(" 5. -> {|}rrrrn");

cprintf(" 6. <> -> {}rn");

cprintf(" 7. -> ([{,}])rn");

cprintf(" 8. -> | <> rn");

}

if(n == 3)

{

cprintf("n nnnrr");

cprintf(" WHILE(AB) [FUNCTION([PAR,PAR,...])];rnn");

cprintf(" AB - rn");

cprintf(" FUNCTION - rn");

cprintf(" PAR - , rn");

cprintf(" rnn");

cprintf(" rnnn");

}

getch();

puttext(1,8,80,22,string);

window(1,1,80,25);

}

//----------------------------------------------------------------------------

// While

//----------------------------------------------------------------------------

int scan()

{

int k,j,w; //

mistake_number[1]=1;

for(j=0;;j++)

{

if(TEXT[x][j] == NULL) break;

if(TEXT[x][j] == 'W')

{

y=j; // W w

if(my_while() == 1) break; //

} //my_while

if(TEXT[x][j] == 'w')

{

y=j;

if(my_while() == 1) break;

}

if(TEXT[x][j] != ' ')

{

strange[s++]=TEXT[x][j];

mistake_number[10]=1;

}

if(TEXT[x][j] == ' ')

{

strange[s++]=',';

strange[s++]=' ';

}

}

strange[s]=NULL;

return(1);

}

//----------------------------------------------------------------------------

// While

//----------------------------------------------------------------------------

int my_while()

{

char str[10];

int k,j,w; //

for(w=0;w<5;w++)

{

if(TEXT[x][y] == NULL) break;

str[w]=toupper(TEXT[x][y++]); //Toupper -

} //

str[w]=NULL;

if(strcmp(str,"WHILE") == 0) // While

{ //

fprintf(fl_t," While - %cn",TEXT[x][y]);

if(TEXT[x][y] != '(') mistake_number[2]=1;

else y++;

AB();

if(TEXT[x][y] != ')') mistake_number[3]=1;

y++;

mistake_number[1]=0;

FUNC();

return(1);

}

else return(0);

}

//----------------------------------------------------------------------------

//

//----------------------------------------------------------------------------

int AB()

{

char signal[4]=">

int z;

fprintf(fl_t," ABn");

TERM();

if(TEXT[x][y] == '<')

{

y++;

if(TEXT[x][y] == '=') y++;

for(z=0;z<4;z++)

if(TEXT[x][y] == signal[z]) //

{ //

mistake_number[14]=1; //

y++; //

z=0;

}

AB();

return(1);

}

if(TEXT[x][y] == '>')

{

y++;

if(TEXT[x][y] == '=') y++;

for(z=0;z<4;z++)

if(TEXT[x][y] == signal[z])

{

mistake_number[14]=1;

y++;

z=0;

}

AB();

return(1);

}

if(TEXT[x][y] == '=')

{

y++;

if(TEXT[x][y] == '=')

{

y++;

}

for(z=0;z<4;z++)

if(TEXT[x][y] == signal[z])

{

mistake_number[14]=1;

y++;

z=0;

}

AB();

return(1);

}

if(TEXT[x][y] == '!')

{

y++;

for(z=0;z<3;z++)

if(TEXT[x][y] == signal[z])

{

mistake_number[14]=1;

y++;

z=0;

}

if(TEXT[x][y+1] == '=')

{

y++;

}

AB();

return(1);

}

if(TEXT[x][y] == NULL) return(1);

return(1);

}

//----------------------------------------------------------------------------

//

//----------------------------------------------------------------------------

int TERM()

{

fprintf(fl_t," TERMn");

O();

if(TEXT[x][y] == '/')

{

y++;

TERM();

}

else if(TEXT[x][y] == '*')

{

y++;

if(TEXT[x][y] == '*') y++;

TERM();

}

else if(TEXT[x][y] =='+')

{

y++;

if(TEXT[x][y] == '+' && TEXT[x][y+1] == ')' )

{ //

y++; // y++

return(0); // y+++e

}

if(TEXT[x][y] == '+'&& TEXT[x][y+1] == '+') y+=2;

TERM();

}

else if(TEXT[x][y] =='-')

{

y++;

if(TEXT[x][y] == '-' && TEXT[x][y+1] == ')' )

{ // y--

y++;

return(0);

}

if(TEXT[x][y] == '-'&& TEXT[x][y+1] == '-') y+=2;

TERM();

}

else if(TEXT[x][y] ==NULL ) return(1);

else if(TEXT[x][y] != '+' && TEXT[x][y]!='*' && TEXT[x][y]!=')' && TEXT[x][y] != '/' && TEXT[x][y]!='-' && TEXT[x][y] != '<' && TEXT[x][y]!='>' && TEXT[x][y]!='!' && TEXT[x][y]!=' '&& TEXT[x][y]!='=')

{

mistake_number[7]=1;

AB();

}

return(1);

}

//----------------------------------------------------------------------------

//

//----------------------------------------------------------------------------

int O()

{

fprintf(fl_t," On");

if(TEXT[x][y] == '(')

{

y++;

if(TEXT[x][y] == ')')

{

mistake_number[4]=1;

y++;

}

else

{

AB();

if(TEXT[x][y] == '(')

{

AB();

}

if(TEXT[x][y] != ')')

{

mistake_number[3]=1;

y++;

}

else y++;

}

}

else

{

if(IDENT() == 0)

if(ZBZ() == 0)

if(f==0) mistake_number[11]=1;

return(0);

}

return(0);

}

//----------------------------------------------------------------------------

//

//----------------------------------------------------------------------------

int IDENT()

{

fprintf(fl_t," IDENT, - %cn",TEXT[x][y]);

if((isalpha(TEXT[x][y])) != NULL)

{

while(isalpha(TEXT[x][y]) || isdigit(TEXT[x][y]))

y++;

return(1);

}

else return(0);

}

//----------------------------------------------------------------------------

//

//----------------------------------------------------------------------------

int ZBZ()

{

fprintf(fl_t," , - %cn",TEXT[x][y]);

if((isdigit(TEXT[x][y])) != NULL)

{

y++;

while(1)

{

if((isalpha(TEXT[x][y])) != NULL)

{

/* ,*/ if(f==0) mistake_number[12]=1;

/* , */ else mistake_number[9]=1;

/* : */ while(isalpha(TEXT[x][y]) || isdigit(TEXT[x][y]))

/* f=0 */ y++;

/* f=1 */ return(1);

/* */ }

if((isdigit(TEXT[x][y])) == NULL) break;

y++;

}

return(1);

}

else return(0);

}

//----------------------------------------------------------------------------

//

//----------------------------------------------------------------------------

int FUNC()

{

f=1;

fprintf(fl_t," FUNC, - %cn",TEXT[x][y]);

for(;;y++)

if(TEXT[x][y] != ' ') break;

if(IDENT()==0)

{

mistake_number[6]=1;

while(isalpha(TEXT[x][y]) || isdigit(TEXT[x][y]))

y++;

}

if(mistake_number[6] ==0)

if(TEXT[x][y] =='(')

{

y++;

if(TEXT[x][y] == ')')

{

mistake_number[4]=1;

y++;

}

else while(6)

{

if(PAR() != 0)

{

if(TEXT[x][y] == ')')

{

y++;

break;

}

if(TEXT[x][y] == ';') break;

if(TEXT[x][y] == ',') y++;

}

else

{

mistake_number[13]=1;

break;

}

}

}

else

{

mistake_number[2]=1;

mistake_number[13]=1;

}

if(mistake_number[13]==1)

{

for(;;y++)

{

if(TEXT[x][y] == NULL)

{

mistake_number[5]=1;

mistake_number[3]=1;

break;

}

if(TEXT[x][y] == ';')

{

mistake_number[3]=1;

break;

}

if(TEXT[x][y] == ')')

{

y++;

break;

}

}

}

if(TEXT[x][y] != ';') mistake_number[5]=1;

return(1);

}

//----------------------------------------------------------------------------

//

//----------------------------------------------------------------------------

int PAR()

{

fprintf(fl_t," PAR, - %cn",TEXT[x][y]);

if(IDENT() == 0)

if(ZBZ() == 0)

{

mistake_number[13]=1;

return(0);

}

return(1);

}

:

1. . . ., , 1975.

2. .. . ., , 1975.

3. .., .. . , 1992.

L WHILE( ) []; WHILE - - - , - ,

 

 

 

! , , , .
. , :