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;
static mylexer s_lexer;
static myparser s_parser;
mylexer s_lexer;
myparser s_parser;

View File

@ -28,7 +28,7 @@ Date: 07 December 2000
YYLEXNAME::YYLEXNAME()
{
yytables();
#line 51 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 45 "C:\\spongebob\\Utils\\scripter\\lexer.l"
// place any extra initialisation code here
@ -78,7 +78,7 @@ void YYLEXNAME::yyunput(int ch)
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
YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
@ -88,155 +88,155 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
switch (action) {
case 1:
{
#line 70 "C:\\spongebob\\Utils\\scripter\\lexer.l"
if(preprocessorCmd(yytext+1)!=true)error();
#line 64 "C:\\spongebob\\Utils\\scripter\\lexer.l"
if(preprocessorCmd(yytext+1)!=(int)true)error();
#line 94 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 2:
{
#line 71 "C:\\spongebob\\Utils\\scripter\\lexer.l"
printf("# commands must be at start of line! ( line %d )\n",getCurrentLine());error();
#line 65 "C:\\spongebob\\Utils\\scripter\\lexer.l"
printf("# commands must be at start of line!\n");error();
#line 101 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 3:
{
#line 73 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 67 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return STOP;
#line 108 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 4:
{
#line 74 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 68 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return IF;
#line 115 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 5:
{
#line 75 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 69 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return ELSE;
#line 122 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 6:
{
#line 76 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 70 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return PAUSE;
#line 129 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 7:
{
#line 77 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 71 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return PRINT;
#line 136 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 8:
{
#line 78 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 72 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return ASSIGN;
#line 143 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 9:
{
#line 79 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 73 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return EQUAL;
#line 150 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 10:
{
#line 80 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 74 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return NOTEQUAL;
#line 157 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 11:
{
#line 81 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 75 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return PLUS;
#line 164 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 12:
{
#line 82 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 76 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return END_STMT;
#line 171 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 13:
{
#line 83 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 77 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return OPEN_PAR;
#line 178 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 14:
{
#line 84 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 78 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return CLOSE_PAR;
#line 185 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 15:
{
#line 85 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 79 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return BEGIN_CS;
#line 192 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 16:
{
#line 86 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 80 "C:\\spongebob\\Utils\\scripter\\lexer.l"
return END_CS;
#line 199 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
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;
#line 206 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
case 18:
{
#line 89 "C:\\spongebob\\Utils\\scripter\\lexer.l"
#line 83 "C:\\spongebob\\Utils\\scripter\\lexer.l"
yylval.value=atoi(yytext);return VALUE;
#line 213 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
break;
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"
}
break;
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"
}
break;
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"
}
break;
case 22:
{
#line 96 "C:\\spongebob\\Utils\\scripter\\lexer.l"
printf("UNEXPECTED CHAR: '%s' in line %d ( char %d )\n",yytext,getCurrentLine(),getCurrentCharOnLine());error();
#line 90 "C:\\spongebob\\Utils\\scripter\\lexer.l"
unexpectedChar();
#line 241 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
}
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
#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;}
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
int yygetchar();
int yygetchar();
private:
// FILE *m_fhInput;
int m_charCount;
int m_lineCount;
int m_currentCharOnLine;
int m_errorCount;
void unexpectedChar();
class myparser *m_currentParser;
#line 45 "C:\\spongebob\\Utils\\scripter\\lexer.h"
#line 39 "C:\\spongebob\\Utils\\scripter\\lexer.h"
};
#ifndef YYLEXNAME

View File

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

View File

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

View File

@ -37,32 +37,6 @@
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
------------------- */
@ -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;
printf("Opening %s..\n",_filename);
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;
}
else
@ -181,7 +134,7 @@ int CPFile::open(char *_filename)
---------------------------------------------------------------------- */
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)
{
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 */

View File

@ -32,6 +32,34 @@
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
------- */
@ -42,7 +70,6 @@
extern int openPFile(char *_filename);
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);
// Macro list ( alphabetically sorted from lowest to highest )
static Macro *s_macros;
static char s_seps[]=" \t";
@ -194,12 +194,13 @@ static int ppf_undefine(char *_cmd)
---------------------------------------------------------------------- */
static int addMacro(char *_name,char *_replacement)
{
Macro *mac,*newMac;
Macro *mac,*newMac,*prev;
// Is the macro already there?
mac=s_macros;
while(mac)
{
if(strcmp(_name,mac->m_name)==0)
if(strcmp(_name,mac->m_name)==0) // pkg
{
printf("MACRO '%s' ALREADY DEFINED\n",_name);
return false;
@ -207,13 +208,31 @@ static int addMacro(char *_name,char *_replacement)
mac=mac->m_next;
}
// Create new macro
newMac=(Macro*)malloc(sizeof(Macro));
newMac->m_name=(char*)malloc(strlen(_name)+1);
newMac->m_replacement=(char*)malloc(strlen(_replacement)+1);
strcpy(newMac->m_name,_name);
strcpy(newMac->m_replacement,_replacement);
newMac->m_next=s_macros;
s_macros=newMac;
// 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;
s_macros=newMac;
}
return true;
}
@ -228,12 +247,14 @@ static int addMacro(char *_name,char *_replacement)
static int removeMacro(char *_name)
{
Macro *mac,*prev;
int cmpResult;
mac=s_macros;
prev=NULL;
while(mac)
{
if(strcmp(_name,mac->m_name)==0)
cmpResult=strcmp(_name,mac->m_name);
if(cmpResult==0)
{
if(prev)
{
@ -248,6 +269,10 @@ static int removeMacro(char *_name)
free(mac);
return true;
}
else if(cmpResult<0)
{
break;
}
prev=mac;
mac=mac->m_next;
}
@ -263,8 +288,38 @@ static int removeMacro(char *_name)
Params:
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;
}

View File

@ -25,6 +25,14 @@
Tyepdefs && Defines
------------------- */
// lookupMacro results
enum
{
UNKNOWN_MACRO,
POSSIBLE_KNOWN_MACRO,
KNOWN_MACRO,
};
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
@ -39,7 +47,7 @@
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"
#ifndef _LEXER_H
#include "lexer.h"
#endif
/* Std Lib
------- */
@ -65,6 +69,7 @@ static int s_numLocalVarNames=sizeof(s_localVarNames)/sizeof(char *);
Params:
Returns:
---------------------------------------------------------------------- */
extern mylexer s_lexer;
extern int lookupVarName(char *_name)
{
int i,vnum;
@ -90,7 +95,7 @@ extern int lookupVarName(char *_name)
}
printf("Unknown variable $%s\n",_name);
// s_errorCount++;
s_lexer.error();
return -1;
}

View File

@ -1,24 +1,25 @@
// Crappy test program
// Prints a number based upon another one ( eh? )
#include defs.scr
//#print something..
#include data/scripts/defs.scr
// No switch statements here..
if($tmp1==1)
if($tmp1==ONE)
{
$tmp2=11;
}
else if($tmp1==2)
else if($tmp1==TWO)
{
$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;
@ -31,6 +32,6 @@ pause;
if($tmp2!=0)
print($tmp2);
else
print(12345);
print(5432);
stop;

View File

@ -78,6 +78,10 @@
#include "frontend\scrollbg.h"
#endif
#ifndef __PAUL_SCRIPT_H__
#include "paul\script.h"
#endif
/* Std Lib
------- */
@ -110,6 +114,8 @@ static CScrollyBackground *s_bg1;
static CScrollyBackground *s_bg2;
static CScrollyBackground *s_bg3;
CScript *testScript;
/*----------------------------------------------------------------------
Function:
@ -255,6 +261,8 @@ PAUL_DBGMSG("change=%d",mem-(MainRam.TotalRam-MainRam.RamUsed));
s_bg3->setSpeed(0,-2);
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)
baseGUIObject->render();

Binary file not shown.

View File

@ -588,6 +588,18 @@ SOURCE=..\..\..\makefile.gfx
SOURCE=..\..\..\data\translations\text.dat
# End Source File
# 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
SOURCE=..\..\..\data\DataCache.scr