. , , ,

,,,

FORTRAN — ,

, .

.

.

FORTRAN.

: .

: .

: -513.

: .

: .

: .

: 19 1997 .

: _______________________________

1997.


.

FORTRAN.

GOTO ½½

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

** .


.

G[<>]:

1.<> GOTO <>

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

3. ç* ç / ê**

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

5.<> { ç}[L]

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

L

()

**


.

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

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

G[<>] , . S - .


.

, -.

, (), , .

.

C++, .


.

. .

, , , (), .


.

¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

FORTRAN.

¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

GOTO A+B-DD**(CC/(23+34**R))+Y*((C))

¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

AB - .

SCAN - . 'A' 65.

T - .

O - .

IDENT - A.

SCAN - . '+' 43.

AB - .

SCAN - . 'B' 66.

T - .

O - .

IDENT - B.

SCAN - . '-' 45.

AB - .

SCAN - . 'D' 68.

T - .

O - .

IDENT - D.

SCAN - . 'D' 68.

SCAN - . '*' 42.

SCAN - . '*' 42.

SCAN - . '(' 40.

T - .

O - .

AB - .

SCAN - . 'C' 67.

T - .

O - .

IDENT - C.

SCAN - . 'C' 67.

SCAN - . '/' 47.

SCAN - . '(' 40.

T - .

O - .

AB - .

SCAN - . '2' 50.

T - .

O - .

IDENT - 2.

FLOAT - 2.

SCAN - . '3' 51.

SCAN - . '+' 43.

AB - .

SCAN - . '3' 51.

T - .

O - .

IDENT - 3.

FLOAT - 3.

SCAN - . '4' 52.

SCAN - . '*' 42.

SCAN - . '*' 42.

SCAN - . 'R' 82.

T - .

O - .

IDENT - R.

SCAN - . ')' 41.

SCAN - . ')' 41.

SCAN - . '+' 43.

AB - .

SCAN - . 'Y' 89.

T - .

O - .

IDENT - Y.

SCAN - . '*' 42.

SCAN - . '(' 40.

T - .

O - .

AB - .

SCAN - . '(' 40.

T - .

O - .

AB - .

SCAN - . 'C' 67.

T - .

O - .

IDENT - C.

SCAN - . ')' 41.

SCAN - . ')' 41.

SCAN - . NULL 0.

¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

GOTO A

¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

AB - .

SCAN - . 'A' 65.

T - .

O - .

IDENT - A.

SCAN - . NULL 0.

¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾


.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// FILE "KURSOVIK.CPP".

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// H 3.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// FORTRAN.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// : .

// : -513.

// : H.

// : , ,

// .

// : 29 1997.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

#include

#include

#include

#include

#include

#include

#include

#include"keyboard.h"

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

#define ERROR 0 // .

#define COL_STR 20 // .

#define STR_LEN 35 // .

#define MAX_STR_LEN 255 // .

#define FILENAME "TEST.TXT" // , .

#define YES 1

#define NO 2

#define OK 3

//#define TEST // , .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

int I_ReadKey(void); // .

void Welcome(void); // .

void Menu(void); // .

void Help(void); // .

void MyExit(int=0); // .

void Beep(int=500,int=100); // .

void Usage(void); // .

int OpenFile(void); // .

void DrawBox(int,int,int,int,char*); // .

void PrintText(void); // .

void Screen(void); // .

void Compile(void); // .

void Message(int); // .

void MyPuts(char*,int); // puts(char*);.

void Language(void); // .

void Grammar(void); // .

void GetFilename(void); // .

int ScanStr(char*); // GOTO.

int Scaner(char*); // .

void Scan(void); // .

void Delspace(char*); // .

int AB(void); // <>.

int T(void); // <>.

int O(void); // <>.

int IDENT(void); // .

int FLOAT(void); // .

void Error(int=0,char* =""); // .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

char filename[MAX_STR_LEN]; // .

char *text[COL_STR+1]; // .

char screen[4096]; // .

char mes[21][20][80]; // .

char nx; // .

int pos; // .

char STR[80]; // .

int ERR1; // .

int ERR2; // .

FILE *errors; // .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// MAIN.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

void main(int argc,char* argv[])

{

textcolor(LIGHTGRAY);

textbackground(BLACK);

_setcursortype(_NOCURSOR);

clrscr();

if(argc>2)

{

Usage();

MyExit();

}

if(argc==2)

strcpy(filename,argv[1]);

else

{

Welcome();

gettext(20,7,60,17,screen);

GetFilename();

}

while(OpenFile())

{

puttext(20,7,60,17,screen);

GetFilename();

}

Menu();

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

void Message(int j)

{

window(42,3,79,23);

textcolor(BLUE);

textbackground(CYAN);

clrscr();

for(int i=0;i

cprintf("%-30srn",mes[j][i]);

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// p .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

void Grammar(void)

{

window(1,25,80,25);

textattr(112);

MyPuts(" ~F1~ Help ~F2~ Grammar ~F3~ Language ~F9~ Compile ~F10~ Quit ~Alt-X~

Quit ~Esc~ Quit",DARKGRAY);

window(10,5,70,20);

textcolor(WHITE);

textbackground(MAGENTA);

clrscr();

DrawBox(2,1,60,16,"p ");

window(12,6,78,19);

textcolor(YELLOW);

cputs("rn");

cputs(" 1. -> GOTO

rn");

cputs(" 2.

-> T |

+T |

-Trn");

cputs(" 3. T -> O | T*O | T/O | T**Orn");

cputs(" 4. O -> (

) |

| <>rn");

cputs(" 5.

-> {|}[L]rn");

cputs(" 6. <> -> {}[.{}][L]rnn");

cputs(" T - p;rn");

cputs(" O - p;rn");

cputs(" - ;rn");

cputs(" ֠ - p;rn");

cputs(" Ǡ - ;rn");

cputs(" ** - .");

I_ReadKey();

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

void Language(void)

{

window(1,25,80,25);

textattr(112);

MyPuts(" ~F1~ Help ~F2~ Grammar ~F3~ Language ~F9~ Compile ~F10~ Quit ~Alt-X~

Quit ~Esc~ Quit",DARKGRAY);

window(20,8,60,18);

textcolor(WHITE);

textbackground(GREEN);

clrscr();

DrawBox(2,1,40,11," ");

window(22,9,58,17);

textcolor(BLACK);

cputs("rn");

cputs(" GOTO CONST | VAR | rnn");

cputs(" CONST - ,rn");

cputs(" VAR - p,rn");

cputs("   - p p.");

I_ReadKey();

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

void Compile(void)

{

static int compile=0;

window(1,25,80,25);

textattr(112);

MyPuts(" ~F1~ Help ~F2~ Grammar ~F3~ Language ~F9~ Compile ~F10~ Quit ~Alt-X~

Quit ~Esc~ Quit",DARKGRAY);

window(20,8,60,18);

textcolor(WHITE);

textbackground(RED);

clrscr();

DrawBox(2,1,40,11,"");

window(22,9,58,17);

textcolor(YELLOW);

cputs("rn");

if(compile>0)

{

cputs(" !!!");

Beep(900,1000);

return;

}

errors=fopen("PROTOCOL.TXT","wt");

cputs(" .rnn , ...");

#ifdef TEST

window(1,1,80,25);

textattr(78);

clrscr();

#endif

fprintf(errors,"/*******************************************************n");

fprintf(errors,"n");

fprintf(errors,"ç çn");

fprintf(errors,"ç FORTRAN. çn");

fprintf(errors,"n");

for(int i=0;text[i] != NULL;i++)

Scaner(text[i]);

fprintf(errors,"n");

fprintf(errors,"ç . çn");

fprintf(errors,"n");

fprintf(errors,"*******************************************************/n");

Beep(900,100);

compile++;

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

int Scaner(char* string)

{

char tmpstr[STR_LEN];

strcpy(tmpstr,string);

Delspace(tmpstr);

ScanStr(tmpstr);

return 0;

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// GOTO.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

int ScanStr(char* string)

{

int j;

int i=0;

int k=0;

static int a=0;

char tmp[80];

char label=NO;

strcpy(STR,string);

fprintf(errors,"n");

fprintf(errors,"%sn",string);

fprintf(errors,"n");

do

{

tmp[0]=NULL;

j=0;

while(!isspace(string[k++]) && string[k-1]!=NULL)

{

tmp[j++]=string[k-1];

}

tmp[j]=NULL;

if((strcmp(tmp,"GOTO") != 0) && !isdigit(tmp[0]))

{

#ifdef TEST

cprintf(" %s.rn",tmp);

#endif

ERR1=a;

ERR2=i;

i++;

Error(5,tmp);

}

else if(!isdigit(tmp[0]))

{

label=YES;

ERR1=a;

ERR2=i;

pos=k;

while(AB()!=OK);

break;

}

}

while(string[k] != NULL);

if(label==NO)

{

#ifdef TEST

cprintf(" GOTO.rn .rn");

#endif

Error(6);

}

a++;

return(OK);

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

void Delspace(char* string)

{

char str[STR_LEN];

int j=0;

int i=0;

while(isspace(string[i]) && string[i] != NULL)

i++;

for(;string[i] != NULL;i++)

{

if(islower(string[i]))

string[i]=toupper(string[i]);

str[j++]=string[i];

}

str[j]=NULL;

sprintf(string,"%s",str);

string[j-1]=NULL;

#ifdef TEST

textattr(30);

clreol();

cputs(string);

textattr(78);

cputs("rn");

#endif

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// < >.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

int AB(void)

{

#ifdef TEST

cprintf("AB - .rn");

#endif

fprintf(errors,"AB - .n");

Scan();

T();

if(nx=='+')

{

AB();

}

else if(nx=='-')

{

AB();

}

if(nx==NULL)

return(OK);

else if(nx!='*' && nx!='/' && nx!=')')

Error(1);

return(YES);

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// <>.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

int T(void)

{

#ifdef TEST

cprintf("T - .rn");

#endif

fprintf(errors,"T - .n");

O();

if(nx=='/')

{

Scan();

T();

}

else if(nx=='*')

{

Scan();

if(nx=='*')

{

Scan();

T();

}

else T();

}

if(nx==NULL)

return(OK);

else if(nx!='+' && nx!='-' && nx!=')')

Error(2);

return(OK);

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// <>.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

int O(void)

{

#ifdef TEST

cprintf("O - .rn");

#endif

fprintf(errors,"O - .n");

if(nx=='(')

{

AB();

if(nx!=')')

Error(3);

else

{

Scan();

return(OK);

}

}

else

if(IDENT() == NO)

{

if(FLOAT() == NO)

Error(4);

}

return(OK);

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// <>.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

int IDENT(void)

{

#ifdef TEST

cprintf("IDENT - %c.rn",nx);

getch();

#endif

fprintf(errors,"IDENT - %c.n",nx);

if(isalpha(nx))

{

while(isalpha(nx) || isdigit(nx))

Scan();

return(YES);

}

return(NO);

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// < >.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

int FLOAT(void)

{

#ifdef TEST

cprintf("FLOAT - %c.rn",nx);

getch();

#endif

fprintf(errors,"FLOAT - %c.n",nx);

if(isdigit(nx))

{

while(isdigit(nx))

Scan();

if(nx=='.')

{

Scan();

while(isdigit(nx))

Scan();

}

return(YES);

}

return(NO);

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

void Scan(void)

{

#ifdef TEST

cprintf("SCAN - . '%c' %d.rn",STR[pos],STR[pos]);

getch();

#endif

fprintf(errors,"SCAN - . '%c'

%d.n",STR[pos],STR[pos]);

nx=STR[pos];

pos++;

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

void Error(int num,char* s)

{

char *E[40]=

{

" '+' '-'",

" '*', '/' '**'",

" ')'",

" ",

" ",

" GOTOrn ",

NULL

};

sprintf(mes[ERR1][ERR2],"%s%s",E[num-1],s);

fprintf(errors,"n");

fprintf(errors,"Error - %d, # %d.n",ERR1,ERR2);

#ifdef TEST

cprintf("Error - : # %d, # %d.rn",ERR1,ERR2);

cprintf("%srn",mes[ERR1][ERR2]);

Beep(1000,200);

getch();

#endif

fprintf(errors,"%sn",mes[ERR1][ERR2]);

fprintf(errors,"n");

ERR2++;

mes[ERR1][ERR2][0]=NULL;

}

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

#include"intface.h" // .

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

// Ó 1997 H. E-mail: ANDREY@RedHouse.nstu.nsk.su.

//¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾


.

1. .

2. C .

, . . .

 

 

 

! , , , .
. , :