/****************************************************/
/* File: util.c */
/* Utility function implementation */
/* for the TINY compiler */
/* Compiler Construction: Principles and Practice */
/* Kenneth C. Louden */
/****************************************************/
#include "globals.h"
#include "util.h"
void printToken( TokenType token, const char* tokenString )
{ switch (token)
{ case IF:
case RETURN:
case ELSE:
case VOID:
case INT:
case WHILE:
fprintf(listing,
"reserved word: %s\n",tokenString);
break;
case ASSIGN: fprintf(listing,"!=\n"); break;
case LT: fprintf(listing," case EQ: fprintf(listing,"=\n"); break;
case EQQ: fprintf(listing,"==\n"); break;
case LTT: fprintf(listing," case RT: fprintf(listing,">\n"); break;
case RTT: fprintf(listing,">=\n"); break;
case LPAREN: fprintf(listing,"(\n"); break;
case RPAREN: fprintf(listing,")\n"); break;
case LPARENZ: fprintf(listing,"[\n"); break;
case RPARENZ: fprintf(listing,"]\n"); break;
case LPAREND: fprintf(listing,"{\n"); break;
case RPAREND: fprintf(listing,"}\n"); break;
case SEMI: fprintf(listing,";\n"); break;
case PLUS: fprintf(listing,"+\n"); break;
case MINUS: fprintf(listing,"-\n"); break;
case TIMES: fprintf(listing,"*\n"); break;
case OVER: fprintf(listing,"/\n"); break;
case ENDFILE: fprintf(listing,"EOF\n"); break;
case COMMA: fprintf(listing,",\n"); break;
case NUM:
fprintf(listing,
"NUM, val= %s\n",tokenString);
break;
case ID:
fprintf(listing,
"ID, name= %s\n",tokenString);
break;
case ERROR:
fprintf(listing,
"ERROR: %s\n",tokenString);
break;
default: /* should never happen */
fprintf(listing,"Unknown token: %d\n",token);
}
}