This commit is contained in:
Paul 2000-12-12 20:51:59 +00:00
parent 5e18b667ef
commit bf7bd6c3ea
15 changed files with 350 additions and 161 deletions

View file

@ -28,11 +28,16 @@
#include "pfile.h"
#endif
#ifndef __PREPRO_H__
#include "prepro.h"
#endif
/* Std Lib
------- */
#include <yacc.h>
#include <string.h>
/* Data
@ -86,8 +91,27 @@ int mylexer::closeInputFile()
---------------------------------------------------------------------- */
void mylexer::error()
{
fprintf(yyerr,"ERROR AT LINE %d, COLUMN %d\n",getCurrentLine(),getCurrentCharOnLine());
m_errorCount++;
CPFile::getCurrentFile()->error(yyerr);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int mylexer::getErrorCount()
{
CPFile *cpf;
cpf=CPFile::getCurrentFile();
if(cpf)
{
return cpf->getErrorCount();
}
else
{
return 0;
}
}
@ -99,54 +123,95 @@ void mylexer::error()
---------------------------------------------------------------------- */
int mylexer::yygetchar()
{
char c;
CPFile *cpf;
int ret;
FILE *fh;
fh=getPFileFh();
if(fh)
cpf=CPFile::getCurrentFile();
if(cpf)
{
if(fread(&c,sizeof(c),1,fh)==1)
{
m_charCount++;
m_currentCharOnLine++;
if(c=='\n')
{
m_lineCount++;
m_currentCharOnLine=0;
}
ret=c;
}
else
{
ret=-1;
if(ferror(fh))
{
printf("FATAL: Read error!\n");
}
else
{
closePFile();
return yygetchar();
}
}
ret=cpf->readChar();
// Force compilation to stop after finding errors ( hmm.. )
if(m_errorCount)
{
printf("Stopping compilation due to errors!\n");
ret=-1;
}
}
else
{
ret=-1;
}
// Force compilation to stop after finding errors ( hmm.. )
cpf=CPFile::getCurrentFile();
if(cpf)
{
if(cpf->getErrorCount())
{
printf("Stopping compilation due to errors!\n");
ret=-1;
}
}
return ret;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void mylexer::unexpectedChar()
{
int result;
char name[256]="\0";
char *replacement;
int nextChar;
char c[2]="*"; // Err...
strcat(name,yytext);
do
{
replacement=lookupMacro(name,&result);
if(replacement)
{
break;
}
nextChar=yygetchar();
if(nextChar!=-1)
{
if(strlen(name)>=255)
{
printf("OVERFLOW WHILE LOOKING UP MACRO\n");
error();
return;
}
c[0]=(char)nextChar;
strcat(name,c);
}
else
{
printf("END OF FILE WHILE LOOKING FOR MACRO\n");
error();
return;
}
}
while(result==POSSIBLE_KNOWN_MACRO);
if(result==KNOWN_MACRO)
{
// Err.. shove the string into the input buffer ( is this good? )
char *ptr;
ptr=replacement+strlen(replacement);
while(ptr!=replacement)
{
yyunput(*--ptr);
}
}
else
{
printf("UNEXPECTED STRING: '%s'\n",name);
error();
}
}
/*===========================================================================
end */