Разработка транслятора с языка PROST на язык С++, страница 4

continue;

}

if(lex[i][0] == 10 && lex[i][1] == 18)

{

i+=2;

fprintf(out," continue;\n");

continue;

}

if(lex[i][0] == 10 && lex[i][1] == 1)

{

pop(&stack);

i++;

if(i == K_lex-1)fprintf(out,"  getch();\n}");

else

fprintf(out,"  }\n");

continue;

}

case CODE:

if(lex[i][0] == 10 &&lex[i][1] == 4)

{

pop(&stack);

push(&stack,OPERATORS);

i++;

continue;

}

case as:

if(lex[i][0] == 10 && lex[i][1] == 2)

{

pop(&stack);

i++;

continue;

}

case TZ:

if(lex[i][0] == 20 && lex[i][1] == 2)

{

pop(&stack);

i++;

if(flag ==1){fprintf(out,": "); flag = 0;}

else

if(i==K_lex)continue;

else

fprintf(out,";\n");

continue;

}

case PRISV:

if(lex[i][0] == 20 && lex[i][1] == 12)

{

pop(&stack);

i++;

fprintf(out," = ");

continue;

}

case ID:

if(lex[i][0] == 30)

{

pop(&stack);

i++;

if(flag == 1)fprintf(out,"  %s",T_id[lex[i-1][1]]);

else

fprintf(out,"%s",T_id[lex[i-1][1]]);

continue;

}

case OS:

if(lex[i][0] == 20 && lex[i][1] == 0)

{

pop(&stack);

i++;

fprintf(out,"(");

continue;

}

case CS:

if(lex[i][0] == 20 && lex[i][1] == 1)

{

pop(&stack);

i++;

fprintf(out,")");

continue;

}

case then:

if(lex[i][0] == 10 && lex[i][1] == 8)

{

pop(&stack);

i++;

fprintf(out,"{ ");

continue;

}

case STRC:

if(lex[i][0] == 50)

{

pop(&stack);

i++;

fprintf(out,"\"%s\"",T_strc[lex[i-1][1]]);

continue;

}

case Do:

if(lex[i][0] == 10 &&lex[i][1] == 13)

{

pop(&stack);

i++;

fprintf(out,"{\n");

continue;

}

case DNO:

if (lex[i][0] == 60)

{

printf("\nOshibok na sintaksicheskom urovne ne obnarugeno!");

return;

}

}

printf("\nSintaksicheskaya oshibka ");

if(lex[i][0] == 10)printf("v klyuchevom slove %s. Leksema nomer - %d", T_ks[lex[i][1]],i);

if(lex[i][0] == 20)printf("v razdelitele %s. Leksema nomer - %d - (%d,%d)", T_r[lex[i][1]],i,lex[i][0],lex[i][1]);

if(lex[i][0] == 30)printf("v identifikatore %s. Leksema nomer - %d", T_id[lex[i][1]],i);

if(lex[i][0] == 40)printf("v postoyannoy %s. Leksema nomer - %d", T_const[lex[i][1]],i);

if(lex[i][0] == 50)printf("v strokovoy postoyannoy %s. Leksema nomer - %d",T_strc[lex[i][1]],i);

return;

}

}

Файл VStack.h (подключаемыйфайл):

#include <alloc.h>

#define STACK struct stack

STACK

{

int info ;

STACK *next ;

};

extern void push( STACK **s, int item);

extern int pop ( STACK **s);

extern int peek( STACK **s);

void push ( STACK **s, int item )

{

STACK *new_item;

new_item = (STACK * ) malloc (sizeof(STACK) );

new_item -> info = item;

new_item -> next = *s ;  *s = new_item;

}

int pop ( STACK **s)

{

//int error;

STACK *old_item = *s;

int old_info = 0;

if ( *s )

{

old_info = old_item -> info;

*s = ( *s ) -> next;

free (old_item );

//error = 0;

}

//else error = 1;

return ( old_info );

}

int peek (STACK **s)

{

//int error;

if (*s )

{

//error = 0;

return (*s) -> info;

}

else

{

//error = 1;

return 0;

}

}

int isempty( STACK **s)

{

if (*s) return 0;   

else return 1;

}