. , , ,

,,,

FORTRAN — ,

, .

.

.

FORTRAN.

: .

: .

: -513.

: .

: .

: .

: 10 1997 .

: _______________________________

1997.


.

FORTRAN.

=

, *, /, -, +, **, ( ).

** .

.

G[<>]:

1.<> <> = <>

2.<> ç<>+ ç <>-

3. ç* ç / ê**

4. (<>) ç<> ç<>

5.<> { ç}[L]

6.<> {}[.{}][L]

L

()

**


.

G[<>], , -, , , .

A a, AÎVn, aÎV*.

G[<>] , . S - .

.

, -.

, (), , .

.

C++, .


.

. .

, , , (), .

.

12=1

.

---------------------------------------------------------

s223=(s)+(((d)))

!!!!!

---------------------------------------------------------

sdsds=skshj**mxnx dc

.

---------------------------------------------------------

;;=0

.

.

---------------------------------------------------------

as=115/3

!!!!!

---------------------------------------------------------

32=-*=

.

.

.

.

.

---------------------------------------------------------

sdvsf+gsdf=0

a '=' .

---------------------------------------------------------

jhg=321+321/54*4(s+25)

.

---------------------------------------------------------

d56gfsdfg=(ld+5

6.

')'.

---------------------------------------------------------

.

// SP_KURS.CPP: . //

// "" //

// ࠠ test

#include

#include

#include

#include

#include

#include

#include

#define UP 72 /* */

#define DOWN 80 /* 砠 */

#define EXIT '33' /* Esc */

#define END 100

enum LEX{ERROR,CBZ,ID,PLUS,MIN,DIV,MUL,STEP,SKL,SKR,RAV,_EOLN_,_EOF_};

int next,number=0,num=0,temp,line=1,err[80],sum;

int mistake[15][80],ofset=0;

char cordinat[80][80],filename[80];

char* type_mis[]={" !!!!!",

" .",

" .",

"a '=' .",

" ( '=').",

" 6.",

" ')'.",

" .",

" .",

" '('.",

" .",

" (=?) . ",

" (?=B).",

" ",};

const int X1=2,Y1=20,X2=80,Y2=25;

const int YWINDOW=Y2-Y1+1;

void viewwin(int ,int );

void putmistake(int );

int MENU(char *);

void identif();

void ravno();

void expr(void);

void term(void);

void operand(void);

int scaner(void);

void error(int);

void makefile(void);

FILE *in,*out;

void main(void)

{strcpy(cordinat[0],"n");

mistake[0][0]=13;mistake[0][1]=END;

clrscr();

printf(" :");

gets(filename);

if((in=fopen(filename,"r"))==NULL)

{printf("n !!! !!!");

exit(-1);

}

while(!feof(in))

{ravno();

mistake[line][ofset]=END;

line++;

ofset=0;

}

fcloseall();

makefile();

num=0;

window(1,1,80,25);

clrscr();

gotoxy(1,1);

MENU(" /""/""n");

clrscr();

window(1,1,80,25);

clrscr();

printf("nnnnnnnnnn /""ERRORS.TXT/""!!!!!");

printf("nnnnnnnnnn !!!!!! ");

fcloseall();

exit(1);

}

void ravno()

{temp=0;

num=0;

sum=0;

next=scaner();

if((next!=_EOLN_)&&(next!=_EOF_))

{if(next==RAV)

{error(12);

err[0]=END;

}

else identif();

if(next!=RAV) error(4);

else

{temp=1;

if(err[0]!=END)

{if(err[0]!=ID) error(1);

for(int i=1;i

{next=err[i];

identif();

}

}

temp=2;

next=scaner();

if((next==_EOF_)||(next==_EOLN_)) error(11);

else

{while(1)

{expr();

if(next==SKL) error(10);

else

{if(next==SKR)

{error(9);

next=scaner();

}

if(next==ID)

{error(10);

next=scaner();

}

if(next==ERROR) error(7);

if((next==_EOF_)||(next==_EOLN_)) break;

next=scaner();

}//else

} //while

} //else

}//else

}//if

else mistake[line][ofset++]=13;

}

int scaner(void)

{int liter;

liter=fgetc(in);

num++;

if((isspace(liter))||(liter=='t'))

{while((isspace(liter))||(liter=='t'))

{if(liter=='n') return(11);

liter=fgetc(in);

}

}

if(isdigit(liter))

{while(isdigit(liter))

{liter=fgetc(in);

num++;

}

if(liter=='.')

{liter=fgetc(in);

while(isdigit(liter))

{liter=fgetc(in);

num++;

}

ungetc(liter,in);

num--;

return(1);

}

else

{if(isalpha(liter))

{number=0;

while(isalnum(liter))

{number++;

num++;

liter=fgetc(in);

}

ungetc(liter,in);

num--;

return(2);

}

else switch(liter)

{case '+':num=0;return(3);

case '-':num=0;return(4);

case '/':num=0;return(5);

case '*':num=0;

if((liter=fgetc(in))=='*') return(7);

else

{ungetc(liter,in);

return(6);

}

case '(':return(8);

case ')':return(9);

case '=':return(10);

case 'n':return(11);

case EOF:return(12);

default:return(0);

}

}//else

}

// .

void identif(void)

{if(temp==0)

{while((next!=RAV)&&(next!=_EOLN_)&&(next!=_EOF_))

{err[sum]=next;

sum++;

next=scaner();

}

}

if(temp==1)

{if((next!=CBZ)&&(next!=ID))

{if(next==ERROR) error(2);

else error(3);

}

number=num-1;

num=0;

}

if(number>6) error(5);

}

// "O" <>

void operand()

{if(next==SKL)

{next=scaner();

expr();

if(next!=SKR) error(6);

else next=scaner();

}

else

{if(next==ID){identif();next=scaner();}

else

{if(next!=CBZ)

{if((next!=_EOLN_)&&(next!=_EOF_))

{if(next==ERROR)

{error(7);

next=scaner();

operand();

}

else

{if(next==RAV) error(7);

else error(8);

}

}

else error(8);

}

else next=scaner();

}//else

}//else

}

// E "" <>

void expr(void)

{term();

while((next==PLUS)||(next==MIN))

{next=scaner();

expr();

}

}

// "T" <>

void term(void)

{operand();

while((next==DIV)||(next==MUL)||(next==STEP))

{next=scaner();

term();

}

}

void error(int choice)

{switch(choice)

{case 1:mistake[line][ofset++]=1; break;

case 2:mistake[line][ofset++]=2; break;

case 3:mistake[line][ofset++]=3; break;

case 4:mistake[line][ofset++]=4; break;

case 5:mistake[line][ofset++]=5; break;

case 6:mistake[line][ofset++]=6; break;

case 7:mistake[line][ofset++]=7; break;

case 8:mistake[line][ofset++]=8; break;

case 9:mistake[line][ofset++]=9; break;

case 10:mistake[line][ofset++]=10; break;

case 12:mistake[line][ofset++]=12; break;

case 11:mistake[line][ofset++]=11; break;

default:break;

}

}

void makefile(void)

{char *s;

int num_str=0,oftemp,rep;

if((out=fopen("errors.txt","w"))==NULL)

{printf("n !!! !!!");

exit(-1);

}

if((in=fopen(filename,"r"))==NULL)

{printf("n !!! !!!");

exit(-1);

}

while(num_str++,fgets(s,80,in)!=NULL)

{fputs("\---------------------------------------------------------\",out);

fputc('n',out);

fputs(s,out);

fputc('n',out);

rep=strlen(s);

s[rep-1]='';

strcpy(cordinat[num_str],s);

if((oftemp=mistake[num_str][0])==END)

{fputs(type_mis[0],out);

fputc('n',out);

}

else

{for(int k=0;mistake[num_str][k]!=END;k++)

{oftemp=mistake[num_str][k];

fputs(type_mis[oftemp],out);

fputc('n',out);

}

}

}

fputs("\---------------------------------------------------------\",out);

fputc('n',out);

fcloseall();

}

// MENU

int MENU(char *s)

{int dy,n;

dy=line-1;

textbackground(WHITE);

textcolor(YELLOW);

window(1,1,80,25);

clrscr();

gotoxy(2,1);

cprintf(" SDenisn ");

gotoxy(2,2);

cputs(s);

gotoxy(2,3);

cprintf(" / .n");

gotoxy(2,4);

cprintf(" - ( ). n");

gotoxy(2,5);

cprintf(" - .n");

gotoxy(2,6);

textbackground(WHITE);

textcolor(RED);

cprintf("******************** Ƞ   ՠ *************************n");

textbackground(WHITE);

textcolor(YELLOW);

gotoxy(2,19);

cprintf("******************* Ƞ Π ****************************n");

window(X1,Y1,X2,Y2);

textcolor(BLACK);

viewwin(0,YWINDOW);

n = 0;

int Y=1;

while(1)

{char c;

gotoxy(1,Y);

textbackground(GREEN);

cprintf("%s",cordinat[n]);

textbackground(WHITE);

c=(c=getch())==0?c=getch():c;

gotoxy(1,Y);

cprintf("%s",cordinat[n]);

switch (c)

{case EXIT:

return(-1);

case 'r': /*enter*/

window(2,7,80,18);

clrscr();

putmistake(n);

window(X1,Y1,X2,Y2);

break;

case UP:

if (Y==1) viewwin(n>0?n-1:n,YWINDOW);

else Y--;

if(n>0) n--;

break;

case DOWN:

if(Y==YWINDOW) viewwin((n==dy?n:n+1)-YWINDOW+1,YWINDOW);

else Y++;

if(n+1==dy)

{n=0;

Y=1;

viewwin(n,YWINDOW);

}

else n++;

break;

}

}

}

void viewwin(int num,int numline)

{clrscr();

for(int a=0;a

{gotoxy(1,a+1);

cprintf("%s",cordinat[num++]);

}

}

void putmistake(int n)

{int offtemp,x=1,y=1;

if((offtemp=mistake[n][0])==END)

{cprintf("%s",type_mis[0]);

}

else

{for(int k=0;mistake[n][k]!=END;k++)

{offtemp=mistake[n][k];

if(offtemp==13) cprintf("%sn",type_mis[offtemp]);

else

{cprintf("%d.%sn",k+1,type_mis[offtemp]);

x++;

y++;

gotoxy(x,y);

}

}

}

}


.

1. .

2. C .

3. ..

, . . . FORTRAN. : .

 

 

 

! , , , .
. , :