Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Homework from programming language processor class... I really need help with the codes... Thank you very much getsource h /**************getSource.c************/ #include #include #include getSource.h #define
Homework from programming language processor class... I really need help with the codes... Thank you very much
getsource h
/**************getSource.c************/
#include
#include
#include "getSource.h"
#define MAXLINE 120 /**/
#define MAXERROR 30 /**/
#define MAXNUM 14 /**/
#define TAB 5 /**/
#define INSERT_C "#0000FF" /* */
#define DELETE_C "#FF0000" /* */
#define TYPE_C "#00FF00" /* */
static FILE *fpi; /**/
static FILE *fptex; /*LaTeX*/
static char line[MAXLINE]; /**/
static int lineIndex; /**/
static char ch; /**/
static Token cToken; /**/
static KindT idKind; /*(Id)*/
static int spaces; /**/
static int CR; /*CR*/
static int printed; /**/
static int errorNo = 0; /**/
static char nextChar(); /**/
static int isKeySym(KeyId k); /*t*/
static int isKeyWd(KeyId k); /*t*/
static void printSpaces(); /**/
static void printcToken(); /**/
struct keyWd { /*(KeyId)*/
char *word;
KeyId keyId;
};
static struct keyWd KeyWdT[] = { /*(KeyId)*/
{"begin", Begin},
{"end", End},
{"if", If},
{"then", Then},
{"while", While},
{"do", Do},
{"return", Ret},
{"function", Func},
{"var", Var},
{"const", Const},
{"odd", Odd},
{"write", Write},
{"writeln",WriteLn},
{"$dummy1",end_of_KeyWd},
/*(KeyId)*/
{"+", Plus},
{"-", Minus},
{"*", Mult},
{"/", Div},
{"(", Lparen},
{")", Rparen},
{"=", Equal},
{"
{">", Gtr},
{"", NotEq},
{"
{">=", GtrEq},
{",", Comma},
{".", Period},
{";", Semicolon},
{":=", Assign},
{"$dummy2",end_of_KeySym}
};
int isKeyWd(KeyId k) /*k*/
{
return (k
}
int isKeySym(KeyId k) /*k*/
{
if (k
return 0;
return (k
}
static KeyId charClassT[256]; /**/
static void initCharClassT() /**/
{
int i;
for (i=0; i
charClassT[i] = others;
for (i='0'; i
charClassT[i] = digit;
for (i='A'; i
charClassT[i] = letter;
for (i='a'; i
charClassT[i] = letter;
charClassT['+'] = Plus; charClassT['-'] = Minus;
charClassT['*'] = Mult; charClassT['/'] = Div;
charClassT['('] = Lparen; charClassT[')'] = Rparen;
charClassT['='] = Equal; charClassT['
charClassT['>'] = Gtr; charClassT[','] = Comma;
charClassT['.'] = Period; charClassT[';'] = Semicolon;
charClassT[':'] = colon;
}
int openSource(char fileName[]) /*open*/
{
char fileNameO[30];
if ( (fpi = fopen(fileName,"r")) == NULL ) {
printf("can't open %s ", fileName);
return 0;
}
strcpy(fileNameO, fileName);
strcat(fileNameO,".html"); /* strcat(fileNameO,".tex"); */
if ( (fptex = fopen(fileNameO,"w")) == NULL ) { /*.html.tex*/
printf("can't open %s ", fileNameO);
return 0;
}
return 1;
}
void closeSource() /*.html.texlose*/
{
fclose(fpi);
fclose(fptex);
}
void initSource()
{
lineIndex = -1; /**/
ch = ' ';
printed = 1;
initCharClassT();
fprintf(fptex," "); /*html*/
fprintf(fptex," compiled source program ");
fprintf(fptex,"
");
/* LaTeX
fprintf(fptex,"\\documentstyle[12pt]{article} ");
fprintf(fptex,"\\begin{document} ");
fprintf(fptex,"\\fboxsep=0pt ");
fprintf(fptex,"\\def\\insert#1{$\\fbox{#1}$} ");
fprintf(fptex,"\\def\\delete#1{$\\fboxrule=.5mm\\fbox{#1}$} ");
fprintf(fptex,"\ m ");
*/
}
void finalSource()
{
if (cToken.kind==Period)
printcToken();
else
errorInsert(Period);
fprintf(fptex," ");
/* fprintf(fptex," \\end{document} "); */
}
/**/
/*
void error(char *m)
{
if (lineIndex > 0)
printf("%*s ", lineIndex, "***^");
else
printf("^ ");
printf("*** error *** %s ", m);
errorNo++;
if (errorNo > MAXERROR){
printf("too many errors ");
printf("abort compilation ");
exit (1);
}
}
*/
void errorNoCheck() /**/
{
if (errorNo++ > MAXERROR){
fprintf(fptex, "too many errors
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started