SBSPSS/Utils/Scripter/mylexer.cpp

153 lines
2.7 KiB
C++
Raw Normal View History

2000-12-11 23:25:12 +01:00
/*=========================================================================
mylexer.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
2000-12-12 17:29:42 +01:00
#ifndef _LEXER_H
2000-12-11 23:25:12 +01:00
#include "lexer.h"
2000-12-12 17:29:42 +01:00
#endif
#ifndef _PARSER_H
2000-12-11 23:25:12 +01:00
#include "parser.h"
2000-12-12 17:29:42 +01:00
#endif
#ifndef __PFILE_H__
#include "pfile.h"
#endif
2000-12-11 23:25:12 +01:00
/* Std Lib
------- */
#include <yacc.h>
/* Data
---- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int mylexer::openInputFile(char *_filename)
{
return openPFile(_filename);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int mylexer::closeInputFile()
{
return closePFile();
}
2000-12-12 17:29:42 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void mylexer::error()
{
fprintf(yyerr,"ERROR AT LINE %d, COLUMN %d\n",getCurrentLine(),getCurrentCharOnLine());
m_errorCount++;
}
2000-12-11 23:25:12 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int mylexer::yygetchar()
{
char c;
int ret;
FILE *fh;
fh=getPFileFh();
if(fh)
{
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();
}
}
// Force compilation to stop after finding errors ( hmm.. )
if(m_errorCount)
{
2000-12-12 17:29:42 +01:00
printf("Stopping compilation due to errors!\n");
2000-12-11 23:25:12 +01:00
ret=-1;
}
}
else
{
ret=-1;
}
return ret;
}
/*===========================================================================
end */