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

@ -56,8 +56,8 @@ static FILE *s_fhOutput=NULL;
CTreeNode *s_baseTreeNode=NULL; CTreeNode *s_baseTreeNode=NULL;
static mylexer s_lexer; mylexer s_lexer;
static myparser s_parser; myparser s_parser;

View file

@ -28,7 +28,7 @@ Date: 07 December 2000
YYLEXNAME::YYLEXNAME() YYLEXNAME::YYLEXNAME()
{ {
yytables(); yytables();
#line 51 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 45 "C:\\spongebob\\Utils\\scripter\\lexer.l"
// place any extra initialisation code here // place any extra initialisation code here
@ -78,7 +78,7 @@ void YYLEXNAME::yyunput(int ch)
int YYLEXNAME::yyaction(int action) int YYLEXNAME::yyaction(int action)
{ {
#line 63 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 57 "C:\\spongebob\\Utils\\scripter\\lexer.l"
// extract yylval for use later on in actions // extract yylval for use later on in actions
YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr; YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
@ -88,155 +88,155 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
switch (action) { switch (action) {
case 1: case 1:
{ {
#line 70 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 64 "C:\\spongebob\\Utils\\scripter\\lexer.l"
if(preprocessorCmd(yytext+1)!=true)error(); if(preprocessorCmd(yytext+1)!=(int)true)error();
#line 94 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 94 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 2: case 2:
{ {
#line 71 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 65 "C:\\spongebob\\Utils\\scripter\\lexer.l"
printf("# commands must be at start of line! ( line %d )\n",getCurrentLine());error(); printf("# commands must be at start of line!\n");error();
#line 101 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 101 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 3: case 3:
{ {
#line 73 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 67 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return STOP; return STOP;
#line 108 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 108 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 4: case 4:
{ {
#line 74 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 68 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return IF; return IF;
#line 115 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 115 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 5: case 5:
{ {
#line 75 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 69 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return ELSE; return ELSE;
#line 122 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 122 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 6: case 6:
{ {
#line 76 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 70 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return PAUSE; return PAUSE;
#line 129 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 129 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 7: case 7:
{ {
#line 77 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 71 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return PRINT; return PRINT;
#line 136 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 136 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 8: case 8:
{ {
#line 78 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 72 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return ASSIGN; return ASSIGN;
#line 143 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 143 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 9: case 9:
{ {
#line 79 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 73 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return EQUAL; return EQUAL;
#line 150 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 150 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 10: case 10:
{ {
#line 80 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 74 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return NOTEQUAL; return NOTEQUAL;
#line 157 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 157 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 11: case 11:
{ {
#line 81 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 75 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return PLUS; return PLUS;
#line 164 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 164 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 12: case 12:
{ {
#line 82 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 76 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return END_STMT; return END_STMT;
#line 171 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 171 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 13: case 13:
{ {
#line 83 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 77 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return OPEN_PAR; return OPEN_PAR;
#line 178 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 178 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 14: case 14:
{ {
#line 84 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 78 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return CLOSE_PAR; return CLOSE_PAR;
#line 185 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 185 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 15: case 15:
{ {
#line 85 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 79 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return BEGIN_CS; return BEGIN_CS;
#line 192 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 192 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 16: case 16:
{ {
#line 86 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 80 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return END_CS; return END_CS;
#line 199 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 199 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 17: case 17:
{ {
#line 88 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 82 "C:\\spongebob\\Utils\\scripter\\lexer.l"
yylval.variableIdx=lookupVarName(yytext+1);return VARIABLE; yylval.variableIdx=lookupVarName(yytext+1);return VARIABLE;
#line 206 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 206 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 18: case 18:
{ {
#line 89 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 83 "C:\\spongebob\\Utils\\scripter\\lexer.l"
yylval.value=atoi(yytext);return VALUE; yylval.value=atoi(yytext);return VALUE;
#line 213 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 213 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 19: case 19:
{ {
#line 92 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 86 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 220 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 220 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 20: case 20:
{ {
#line 93 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 87 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 227 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 227 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 21: case 21:
{ {
#line 94 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 88 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 234 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 234 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
case 22: case 22:
{ {
#line 96 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 90 "C:\\spongebob\\Utils\\scripter\\lexer.l"
printf("UNEXPECTED CHAR: '%s' in line %d ( char %d )\n",yytext,getCurrentLine(),getCurrentCharOnLine());error(); unexpectedChar();
#line 241 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" #line 241 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
} }
break; break;
@ -253,7 +253,7 @@ printf("UNEXPECTED CHAR: '%s' in line %d ( char %d )\n",yytext,getCurrentLine(),
#pragma warn .rch // <warning: unreachable code> to the old state #pragma warn .rch // <warning: unreachable code> to the old state
#endif #endif
#endif #endif
#line 98 "C:\\spongebob\\Utils\\scripter\\lexer.l" #line 92 "C:\\spongebob\\Utils\\scripter\\lexer.l"

View file

@ -23,25 +23,19 @@ public:
void setCurrentParser(class myparser *_parser) {m_currentParser=_parser;} void setCurrentParser(class myparser *_parser) {m_currentParser=_parser;}
class myparser *getCurrentParser() {return m_currentParser;} class myparser *getCurrentParser() {return m_currentParser;}
int getCurrentLine() {return m_lineCount+1;}
int getCurrentCharOnLine() {return m_currentCharOnLine;}
int getErrorCount() {return m_errorCount;}
void error(); void error();
int getErrorCount();
// Overridden lexer functions // Overridden lexer functions
int yygetchar(); int yygetchar();
private: private:
// FILE *m_fhInput; void unexpectedChar();
int m_charCount;
int m_lineCount;
int m_currentCharOnLine;
int m_errorCount;
class myparser *m_currentParser; class myparser *m_currentParser;
#line 45 "C:\\spongebob\\Utils\\scripter\\lexer.h" #line 39 "C:\\spongebob\\Utils\\scripter\\lexer.h"
}; };
#ifndef YYLEXNAME #ifndef YYLEXNAME

View file

@ -28,21 +28,15 @@ Date: 07 December 2000
void setCurrentParser(class myparser *_parser) {m_currentParser=_parser;} void setCurrentParser(class myparser *_parser) {m_currentParser=_parser;}
class myparser *getCurrentParser() {return m_currentParser;} class myparser *getCurrentParser() {return m_currentParser;}
int getCurrentLine() {return m_lineCount+1;}
int getCurrentCharOnLine() {return m_currentCharOnLine;}
int getErrorCount() {return m_errorCount;}
void error(); void error();
int getErrorCount();
// Overridden lexer functions // Overridden lexer functions
int yygetchar(); int yygetchar();
private: private:
// FILE *m_fhInput; void unexpectedChar();
int m_charCount;
int m_lineCount;
int m_currentCharOnLine;
int m_errorCount;
class myparser *m_currentParser; class myparser *m_currentParser;
} }
@ -67,8 +61,8 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
// place your Lex rules here // place your Lex rules here
^#.* {if(preprocessorCmd(yytext+1)!=true)error();} ^#.* {if(preprocessorCmd(yytext+1)!=(int)true)error();}
# {printf("# commands must be at start of line! ( line %d )\n",getCurrentLine());error();} # {printf("# commands must be at start of line!\n");error();}
stop {return STOP;} stop {return STOP;}
if {return IF;} if {return IF;}
@ -93,7 +87,7 @@ print {return PRINT;}
[ \t]+ {} [ \t]+ {}
\n {} \n {}
. {printf("UNEXPECTED CHAR: '%s' in line %d ( char %d )\n",yytext,getCurrentLine(),getCurrentCharOnLine());error();} . {unexpectedChar();}
%% %%

View file

@ -28,11 +28,16 @@
#include "pfile.h" #include "pfile.h"
#endif #endif
#ifndef __PREPRO_H__
#include "prepro.h"
#endif
/* Std Lib /* Std Lib
------- */ ------- */
#include <yacc.h> #include <yacc.h>
#include <string.h>
/* Data /* Data
@ -86,8 +91,27 @@ int mylexer::closeInputFile()
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
void mylexer::error() void mylexer::error()
{ {
fprintf(yyerr,"ERROR AT LINE %d, COLUMN %d\n",getCurrentLine(),getCurrentCharOnLine()); CPFile::getCurrentFile()->error(yyerr);
m_errorCount++; }
/*----------------------------------------------------------------------
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() int mylexer::yygetchar()
{ {
char c; CPFile *cpf;
int ret; int ret;
FILE *fh;
fh=getPFileFh(); cpf=CPFile::getCurrentFile();
if(fh) if(cpf)
{ {
if(fread(&c,sizeof(c),1,fh)==1) ret=cpf->readChar();
{
m_charCount++;
m_currentCharOnLine++;
if(c=='\n')
{
m_lineCount++;
m_currentCharOnLine=0;
}
ret=c;
} }
else else
{ {
ret=-1; ret=-1;
if(ferror(fh))
{
printf("FATAL: Read error!\n");
}
else
{
closePFile();
return yygetchar();
}
} }
// Force compilation to stop after finding errors ( hmm.. ) // Force compilation to stop after finding errors ( hmm.. )
if(m_errorCount) cpf=CPFile::getCurrentFile();
if(cpf)
{
if(cpf->getErrorCount())
{ {
printf("Stopping compilation due to errors!\n"); printf("Stopping compilation due to errors!\n");
ret=-1; ret=-1;
} }
} }
else
{
ret=-1;
}
return ret; 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 */ end */

View file

@ -82,8 +82,8 @@ void myparser::setBaseNode(class CTreeNode *_baseNode)
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
void myparser::yyerror(const char *_text) void myparser::yyerror(const char *_text)
{ {
fprintf(yyparseerr,"ERROR: %s\n",_text); fprintf(yyparseerr,"PARSER ERROR: %s\n",_text);
fprintf(yyparseerr," line %d char %d\n",m_currentLexer->getCurrentLine(),m_currentLexer->getCurrentCharOnLine()); // fprintf(yyparseerr," line %d char %d\n",m_currentLexer->getCurrentLine(),m_currentLexer->getCurrentCharOnLine());
m_currentLexer->error(); m_currentLexer->error();
} }

View file

@ -37,32 +37,6 @@
Structure defintions Structure defintions
-------------------- */ -------------------- */
class CPFile
{
public:
CPFile();
int open(char *_filename);
int close();
FILE *getFh() {return m_fh;}
static class CPFile *getCurrentFile() {return s_stack;}
private:
FILE *m_fh;
char *m_filename;
int m_charCount;
int m_lineCount;
int m_currentCharOnLine;
int m_errorCount;
class CPFile *m_next;
static class CPFile *s_stack;
};
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
Function Prototypes Function Prototypes
------------------- */ ------------------- */
@ -105,26 +79,6 @@ extern int closePFile()
} }
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
extern FILE *getPFileFh()
{
CPFile*pf;
pf=CPFile::getCurrentFile();
if(pf)
return pf->getFh();
else
return NULL;
}
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
@ -154,10 +108,9 @@ int CPFile::open(char *_filename)
{ {
int ret; int ret;
printf("Opening %s..\n",_filename);
if((m_fh=fopen(_filename,"rt"))==NULL) if((m_fh=fopen(_filename,"rt"))==NULL)
{ {
printf("FATAL: Couldn't open file for reading\n"); printf("FATAL: Couldn't open %sfor reading\n",_filename);
ret=false; ret=false;
} }
else else
@ -181,7 +134,7 @@ int CPFile::open(char *_filename)
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
int CPFile::close() int CPFile::close()
{ {
printf("Processed %d char(s), %d line(s) in file %s\n",m_charCount,m_lineCount,m_filename); printf("Processed %d char(s) on %d line(s) in file %s\n",m_charCount,m_lineCount,m_filename);
if(m_errorCount) if(m_errorCount)
{ {
printf("Found %d error(s) :(\n",m_errorCount); printf("Found %d error(s) :(\n",m_errorCount);
@ -200,5 +153,60 @@ int CPFile::close()
} }
/*----------------------------------------------------------------------
Function:
Purpose:
Params: Returns ASCII code, or -1 for eof, as per yygetchar()
Returns:
---------------------------------------------------------------------- */
int CPFile::readChar()
{
int ret;
char c;
if(fread(&c,sizeof(c),1,m_fh)==1)
{
m_charCount++;
m_currentCharOnLine++;
if(c=='\n')
{
m_lineCount++;
m_currentCharOnLine=0;
}
ret=c;
}
else
{
ret=-1;
if(ferror(m_fh))
{
printf("FATAL: Read error!\n");
}
else
{
closePFile();
if(getCurrentFile())
{
return getCurrentFile()->readChar();
}
}
}
return ret;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params: Returns ASCII code, or -1 for eof, as per yygetchar()
Returns:
---------------------------------------------------------------------- */
void CPFile::error(FILE *_fh)
{
fprintf(_fh,"ERROR IN %s LINE %d, COLUMN %d\n",m_filename,m_lineCount+1,m_currentCharOnLine);
m_errorCount++;
}
/*=========================================================================== /*===========================================================================
end */ end */

View file

@ -32,6 +32,34 @@
Structure defintions Structure defintions
-------------------- */ -------------------- */
class CPFile
{
public:
CPFile();
int open(char *_filename);
int close();
static class CPFile *getCurrentFile() {return s_stack;}
int readChar();
void error(FILE *_fh);
int getErrorCount() {return m_errorCount;}
private:
FILE *m_fh;
char *m_filename;
int m_charCount;
int m_lineCount;
int m_currentCharOnLine;
int m_errorCount;
class CPFile *m_next;
static class CPFile *s_stack;
};
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
Globals Globals
------- */ ------- */
@ -42,7 +70,6 @@
extern int openPFile(char *_filename); extern int openPFile(char *_filename);
extern int closePFile(); extern int closePFile();
extern FILE *getPFileFh();
/*---------------------------------------------------------------------- */ /*---------------------------------------------------------------------- */

View file

@ -81,7 +81,7 @@ static PreproCmd s_preproCmds[]=
}; };
static int s_numPreproCmds=sizeof(s_preproCmds)/sizeof(PreproCmd); static int s_numPreproCmds=sizeof(s_preproCmds)/sizeof(PreproCmd);
// Macro list ( alphabetically sorted from lowest to highest )
static Macro *s_macros; static Macro *s_macros;
static char s_seps[]=" \t"; static char s_seps[]=" \t";
@ -194,12 +194,13 @@ static int ppf_undefine(char *_cmd)
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
static int addMacro(char *_name,char *_replacement) static int addMacro(char *_name,char *_replacement)
{ {
Macro *mac,*newMac; Macro *mac,*newMac,*prev;
// Is the macro already there?
mac=s_macros; mac=s_macros;
while(mac) while(mac)
{ {
if(strcmp(_name,mac->m_name)==0) if(strcmp(_name,mac->m_name)==0) // pkg
{ {
printf("MACRO '%s' ALREADY DEFINED\n",_name); printf("MACRO '%s' ALREADY DEFINED\n",_name);
return false; return false;
@ -207,13 +208,31 @@ static int addMacro(char *_name,char *_replacement)
mac=mac->m_next; mac=mac->m_next;
} }
// Create new macro
newMac=(Macro*)malloc(sizeof(Macro)); newMac=(Macro*)malloc(sizeof(Macro));
newMac->m_name=(char*)malloc(strlen(_name)+1); newMac->m_name=(char*)malloc(strlen(_name)+1);
newMac->m_replacement=(char*)malloc(strlen(_replacement)+1); newMac->m_replacement=(char*)malloc(strlen(_replacement)+1);
strcpy(newMac->m_name,_name); strcpy(newMac->m_name,_name);
strcpy(newMac->m_replacement,_replacement); strcpy(newMac->m_replacement,_replacement);
// Insert it into the list
mac=s_macros;
prev=NULL;
while(mac&&strcmp(_name,mac->m_name)>0)
{
prev=mac;
mac=mac->m_next;
};
if(prev)
{
prev->m_next=newMac;
newMac->m_next=mac;
}
else
{
newMac->m_next=s_macros; newMac->m_next=s_macros;
s_macros=newMac; s_macros=newMac;
}
return true; return true;
} }
@ -228,12 +247,14 @@ static int addMacro(char *_name,char *_replacement)
static int removeMacro(char *_name) static int removeMacro(char *_name)
{ {
Macro *mac,*prev; Macro *mac,*prev;
int cmpResult;
mac=s_macros; mac=s_macros;
prev=NULL; prev=NULL;
while(mac) while(mac)
{ {
if(strcmp(_name,mac->m_name)==0) cmpResult=strcmp(_name,mac->m_name);
if(cmpResult==0)
{ {
if(prev) if(prev)
{ {
@ -248,6 +269,10 @@ static int removeMacro(char *_name)
free(mac); free(mac);
return true; return true;
} }
else if(cmpResult<0)
{
break;
}
prev=mac; prev=mac;
mac=mac->m_next; mac=mac->m_next;
} }
@ -263,8 +288,38 @@ static int removeMacro(char *_name)
Params: Params:
Returns: Returns:
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
extern char *lookupMacro(char *_name) extern char *lookupMacro(char *_name,int *_result)
{ {
Macro *mac;
size_t nameLength;
int cmpResult;
mac=s_macros;
nameLength=strlen(_name);
while(mac)
{
cmpResult=strncmp(_name,mac->m_name,nameLength);
if(cmpResult==0)
{
if(nameLength==strlen(mac->m_name))
{
*_result=KNOWN_MACRO;
return mac->m_replacement;
}
else
{
*_result=POSSIBLE_KNOWN_MACRO;
return NULL;
}
}
else if(cmpResult<0)
{
break;
}
mac=mac->m_next;
}
*_result=UNKNOWN_MACRO;
return NULL; return NULL;
} }

View file

@ -25,6 +25,14 @@
Tyepdefs && Defines Tyepdefs && Defines
------------------- */ ------------------- */
// lookupMacro results
enum
{
UNKNOWN_MACRO,
POSSIBLE_KNOWN_MACRO,
KNOWN_MACRO,
};
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
Structure defintions Structure defintions
-------------------- */ -------------------- */
@ -39,7 +47,7 @@
extern int preprocessorCmd(char *_cmd); extern int preprocessorCmd(char *_cmd);
extern char *lookupMacro(char *_name); extern char *lookupMacro(char *_name,int *_result);
/*---------------------------------------------------------------------- */ /*---------------------------------------------------------------------- */

View file

@ -18,6 +18,10 @@
#include "var.h" #include "var.h"
#ifndef _LEXER_H
#include "lexer.h"
#endif
/* Std Lib /* Std Lib
------- */ ------- */
@ -65,6 +69,7 @@ static int s_numLocalVarNames=sizeof(s_localVarNames)/sizeof(char *);
Params: Params:
Returns: Returns:
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
extern mylexer s_lexer;
extern int lookupVarName(char *_name) extern int lookupVarName(char *_name)
{ {
int i,vnum; int i,vnum;
@ -90,7 +95,7 @@ extern int lookupVarName(char *_name)
} }
printf("Unknown variable $%s\n",_name); printf("Unknown variable $%s\n",_name);
// s_errorCount++; s_lexer.error();
return -1; return -1;
} }

View file

@ -1,24 +1,25 @@
// Crappy test program // Crappy test program
// Prints a number based upon another one ( eh? ) // Prints a number based upon another one ( eh? )
#include defs.scr //#print something..
#include data/scripts/defs.scr
// No switch statements here.. // No switch statements here..
if($tmp1==1) if($tmp1==ONE)
{ {
$tmp2=11; $tmp2=11;
} }
else if($tmp1==2) else if($tmp1==TWO)
{ {
$tmp2=22; $tmp2=22;
} }
else if($tmp1==3) else if($tmp1==THREE)
{ {
$tmp2=33; $tmp2=30+3;
} }
else if($tmp1==4) else if($tmp1==FOUR)
{ {
// Stop here! // Stop here!
stop; stop;
@ -31,6 +32,6 @@ pause;
if($tmp2!=0) if($tmp2!=0)
print($tmp2); print($tmp2);
else else
print(12345); print(5432);
stop; stop;

View file

@ -78,6 +78,10 @@
#include "frontend\scrollbg.h" #include "frontend\scrollbg.h"
#endif #endif
#ifndef __PAUL_SCRIPT_H__
#include "paul\script.h"
#endif
/* Std Lib /* Std Lib
------- */ ------- */
@ -110,6 +114,8 @@ static CScrollyBackground *s_bg1;
static CScrollyBackground *s_bg2; static CScrollyBackground *s_bg2;
static CScrollyBackground *s_bg3; static CScrollyBackground *s_bg3;
CScript *testScript;
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
Function: Function:
@ -255,6 +261,8 @@ PAUL_DBGMSG("change=%d",mem-(MainRam.TotalRam-MainRam.RamUsed));
s_bg3->setSpeed(0,-2); s_bg3->setSpeed(0,-2);
s_bg3->setOt(1002); s_bg3->setOt(1002);
*/ */
testScript->initialise(SCRIPTS_TEST_DAT);
} }
@ -299,6 +307,18 @@ void CPaulScene::render()
} }
} }
if(testScript->isFinished())
{
if(PadGetDown(0)&PAD_START)
{
testScript->reset();
}
}
else
{
testScript->run();
}
/* /*
if(baseGUIObject) if(baseGUIObject)
baseGUIObject->render(); baseGUIObject->render();

Binary file not shown.

View file

@ -588,6 +588,18 @@ SOURCE=..\..\..\makefile.gfx
SOURCE=..\..\..\data\translations\text.dat SOURCE=..\..\..\data\translations\text.dat
# End Source File # End Source File
# End Group # End Group
# Begin Group "scripts"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\..\data\scripts\defs.scr
# End Source File
# Begin Source File
SOURCE=..\..\..\data\scripts\test.scr
# End Source File
# End Group
# Begin Source File # Begin Source File
SOURCE=..\..\..\data\DataCache.scr SOURCE=..\..\..\data\DataCache.scr