else
if (isspace (c) != 0) c = fgetc (in);
else
if (c == '\'') strc();
else
pr_razd();
}
lex[K_lex][0]=60;
fclose (in);
syntax();
fclose (out);
getch();
}
Файл Syntax.cpp (подключаемыйфайл):
#include "VStack.H"
#define DNO 1
#define PROGRAM 2
#define TZ 3
#define CODE 4
#define DEFS 5
#define TYPE 6
#define as 7
#define VARDEFS 8
#define VARDEF 9
#define EXPR 10
#define EXPRESSION 11
#define CS 12
#define OS 13
#define ID 14
#define BINOP 15
#define OPERATORS 16
#define PRISV 17
#define Do 18
#define CONDITION 19
#define STRC 20
#define ELSE 21
#define then 22
#define OPERATOR 23
int flag = 0;
char iden[9];
void syntax (void)
{
int i = 0,s;
STACK *stack;
push (&stack,DNO);
push (&stack,PROGRAM);
while (1)
{
s=peek(&stack);
switch(s)
{
case PROGRAM:
if (lex[i][0] == 10 && lex[i][1] == 0)
{
pop(&stack);
push(&stack,TZ);
push(&stack,CODE);
push(&stack,DEFS);
fprintf(out,"#include <conio.h>\n#include <iostream.h>\nvoid main(void)\n{\n clrscr();\n");
continue;
}
case TYPE:
if(lex[i][0] == 10 && ( lex[i][1] == 3 ||
lex[i][1] == 15 ||
lex[i][1] == 5) )
{
pop(&stack);
i++;
if(lex[i-1][1] == 3)fprintf(out," int %s",iden);
if(lex[i-1][1] == 15)fprintf(out," float %s",iden);
continue;
}
case VARDEF:
if(lex[i+1][0] == 30)
{
pop(&stack);
push(&stack,TZ);
push(&stack,TYPE);
push(&stack,as);
i++;
i++;
strcpy(iden,T_id[lex[i-1][1]]);
continue;
}
case VARDEFS:
{
if(lex[i][0]==10 && lex[i][1]==16 && lex[i+1][0] == 30)
{
pop(&stack);
push(&stack,VARDEFS);
push(&stack,VARDEF);
continue;
}
if(lex[i][0] == 10 && lex[i][1] == 1)
{
pop(&stack);
i++;
continue;
}
}
case DEFS:
if(lex[i][0] == 10 && lex[i][1] == 0)
{
pop(&stack);
push(&stack,VARDEFS);
i++;
continue;
}
case BINOP:
if(lex[i][0] == 20 && ( lex[i][1] == 3 ||
lex[i][1] == 4 ||
lex[i][1] == 5 ||
lex[i][1] == 6) )
{
pop(&stack);
i++;
if(lex[i-1][1] == 3)fprintf(out,"+");
if(lex[i-1][1] == 4)fprintf(out,"-");
if(lex[i-1][1] == 5)fprintf(out,"*");
if(lex[i-1][1] == 6)fprintf(out,"/");
continue;
}
case CONDITION:
if(lex[i][0] == 20 && ( lex[i][1] == 7 ||
lex[i][1] == 8 ||
lex[i][1] == 13 ||
lex[i][1] == 11 ||
lex[i][1] == 10 ||
lex[i][1] == 9) )
{
pop(&stack);
i++;
if(lex[i-1][1] == 7)fprintf(out,"<");
if(lex[i-1][1] == 8)fprintf(out,">");
if(lex[i-1][1] == 13)fprintf(out,"==");
if(lex[i-1][1] == 11)fprintf(out,"!=");
if(lex[i-1][1] == 10)fprintf(out,"<=");
if(lex[i-1][1] == 9)fprintf(out,">=");
continue;
}
case EXPRESSION:
{
if(lex[i][0] == 30 || lex[i][0] == 40)
{
pop(&stack);
push(&stack,EXPR);
i++;
if(lex[i-1][0] == 40)fprintf(out,"%s",T_const[lex[i-1][1]]);
else
fprintf(out,"%s",T_id[lex[i-1][1]]);
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.