This commit is contained in:
parent
f6a49831f1
commit
c83e9cbd5a
12 changed files with 786 additions and 471 deletions
|
@ -17,6 +17,8 @@
|
|||
-------- */
|
||||
|
||||
#include "codegen.h"
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
|
||||
|
||||
/* Std Lib
|
||||
|
@ -49,6 +51,38 @@ static FILE *s_fhOutput=NULL;
|
|||
CTreeNode *s_baseTreeNode=NULL;
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
extern int parseFile(char *_filename,CTreeNode *_baseNode)
|
||||
{
|
||||
int ret;
|
||||
mylexer lexer;
|
||||
myparser parser;
|
||||
|
||||
ret=YYEXIT_FAILURE;
|
||||
if(parser.yycreate(&lexer))
|
||||
{
|
||||
if(lexer.yycreate(&parser))
|
||||
{
|
||||
if(lexer.openInputFile(_filename))
|
||||
{
|
||||
parser.setCurrentLexer(&lexer);
|
||||
parser.setBaseNode(_baseNode);
|
||||
ret=parser.yyparse();
|
||||
lexer.closeInputFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
|
@ -160,8 +194,8 @@ int CTreeNode::generateCode(int _write)
|
|||
switch(m_type)
|
||||
{
|
||||
case STMT_LIST: // list of statements [left-part, right-part] (left-part may be another list)
|
||||
if(m_children[0])codeSize=m_children[0]->generateCode(_write);
|
||||
if(m_children[1])codeSize=m_children[1]->generateCode(_write);
|
||||
if(m_children[0])codeSize+=m_children[0]->generateCode(_write);
|
||||
if(m_children[1])codeSize+=m_children[1]->generateCode(_write);
|
||||
break;
|
||||
|
||||
case EMPTY_STMT: // empty statement
|
||||
|
|
|
@ -112,6 +112,8 @@ extern CTreeNode *s_baseTreeNode;
|
|||
Functions
|
||||
--------- */
|
||||
|
||||
extern int parseFile(char *_filename,class CTreeNode *_baseNode);
|
||||
|
||||
extern int openOutputFile(char *_filename);
|
||||
extern int closeOutputFile();
|
||||
|
||||
|
|
|
@ -11,11 +11,12 @@ Date: 07 December 2000
|
|||
|
||||
#include "parser.h"
|
||||
#include "var.h"
|
||||
#include "prepro.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
#line 19 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 20 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
// repeated because of possible precompiled header
|
||||
#include <clex.h>
|
||||
|
||||
|
@ -27,11 +28,11 @@ Date: 07 December 2000
|
|||
YYLEXNAME::YYLEXNAME()
|
||||
{
|
||||
yytables();
|
||||
#line 28 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
#line 52 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
|
||||
// place any extra initialisation code here
|
||||
|
||||
#line 35 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 36 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
|
||||
#ifndef YYTEXT_SIZE
|
||||
|
@ -77,159 +78,166 @@ void YYLEXNAME::yyunput(int ch)
|
|||
|
||||
int YYLEXNAME::yyaction(int action)
|
||||
{
|
||||
#line 40 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
#line 64 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
|
||||
// extract yylval for use later on in actions
|
||||
YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
|
||||
|
||||
#line 86 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 87 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
yyreturnflg = 1;
|
||||
switch (action) {
|
||||
case 1:
|
||||
{
|
||||
#line 47 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
/*preprocess(yytext);*/
|
||||
#line 93 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 71 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
if(preprocessorCmd(yytext+1)!=0)error();
|
||||
#line 94 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
#line 49 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return STOP;
|
||||
#line 100 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 72 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
printf("# commands must be at start of line! ( line %d )\n",getCurrentLine());error();
|
||||
#line 101 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
#line 50 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return IF;
|
||||
#line 107 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 74 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return STOP;
|
||||
#line 108 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
#line 51 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return ELSE;
|
||||
#line 114 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 75 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return IF;
|
||||
#line 115 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
{
|
||||
#line 52 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return PAUSE;
|
||||
#line 121 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 76 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return ELSE;
|
||||
#line 122 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
#line 53 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return PRINT;
|
||||
#line 128 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 77 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return PAUSE;
|
||||
#line 129 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
#line 54 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return ASSIGN;
|
||||
#line 135 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 78 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return PRINT;
|
||||
#line 136 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
{
|
||||
#line 55 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return EQUAL;
|
||||
#line 142 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 79 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return ASSIGN;
|
||||
#line 143 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
{
|
||||
#line 56 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return NOTEQUAL;
|
||||
#line 149 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 80 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return EQUAL;
|
||||
#line 150 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
{
|
||||
#line 57 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return PLUS;
|
||||
#line 156 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 81 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return NOTEQUAL;
|
||||
#line 157 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
{
|
||||
#line 58 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return END_STMT;
|
||||
#line 163 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 82 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return PLUS;
|
||||
#line 164 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 12:
|
||||
{
|
||||
#line 59 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return OPEN_PAR;
|
||||
#line 170 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 83 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return END_STMT;
|
||||
#line 171 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 13:
|
||||
{
|
||||
#line 60 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return CLOSE_PAR;
|
||||
#line 177 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 84 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return OPEN_PAR;
|
||||
#line 178 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
{
|
||||
#line 61 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return BEGIN_CS;
|
||||
#line 184 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 85 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return CLOSE_PAR;
|
||||
#line 185 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
{
|
||||
#line 62 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return END_CS;
|
||||
#line 191 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 86 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return BEGIN_CS;
|
||||
#line 192 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
{
|
||||
#line 63 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
yylval.variableIdx=lookupVarName(yytext+1);return VARIABLE;
|
||||
#line 198 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 87 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
return END_CS;
|
||||
#line 199 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 17:
|
||||
{
|
||||
#line 64 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
|
||||
#line 205 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 89 "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 65 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
#line 90 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
yylval.value=atoi(yytext);return VALUE;
|
||||
#line 212 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 213 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 19:
|
||||
{
|
||||
#line 66 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
#line 93 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
|
||||
#line 219 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 220 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 20:
|
||||
{
|
||||
#line 67 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
/*s_linesProcessed++;*/
|
||||
#line 226 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 94 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
|
||||
#line 227 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 21:
|
||||
{
|
||||
#line 68 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
printf("?\n");/*printf("line:%d\n",yylineno);printf("-%s-\n",yytext);yyerror("Unexpected character in source");*/
|
||||
#line 233 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 95 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
|
||||
#line 234 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
case 22:
|
||||
{
|
||||
#line 97 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
printf("UNEXPECTED CHAR: '%s' in line %d ( char %d )\n",yytext,getCurrentLine(),getCurrentCharOnLine());error();
|
||||
#line 241 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -245,7 +253,7 @@ printf("?\n");/*printf("line:%d\n",yylineno);printf("-%s-\n",yytext);yyerror("Un
|
|||
#pragma warn .rch // <warning: unreachable code> to the old state
|
||||
#endif
|
||||
#endif
|
||||
#line 71 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
#line 99 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
|
||||
|
||||
|
||||
|
@ -253,7 +261,7 @@ printf("?\n");/*printf("line:%d\n",yylineno);printf("-%s-\n",yytext);yyerror("Un
|
|||
// programs section
|
||||
|
||||
|
||||
#line 257 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
#line 265 "C:\\spongebob\\Utils\\scripter\\lexer.cpp"
|
||||
|
||||
void YYLEXNAME::yytables()
|
||||
{
|
||||
|
@ -277,10 +285,8 @@ void YYLEXNAME::yytables()
|
|||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 18, 1 },
|
||||
{ 40, 40 },
|
||||
{ 18, 18 },
|
||||
{ 0, 29 },
|
||||
{ 19, 19 },
|
||||
{ 0, 30 },
|
||||
{ 0, 41 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
|
@ -300,11 +306,12 @@ void YYLEXNAME::yytables()
|
|||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 18, 1 },
|
||||
{ 40, 40 },
|
||||
{ 18, 18 },
|
||||
{ 20, 1 },
|
||||
{ 41, 40 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 19, 19 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 3, 1 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
|
@ -315,145 +322,146 @@ void YYLEXNAME::yytables()
|
|||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 29, 16 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 0, 0 },
|
||||
{ 30, 18 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 26, 7 },
|
||||
{ 27, 8 },
|
||||
{ 28, 9 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 28, 28 },
|
||||
{ 29, 29 },
|
||||
{ 0, 0 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 28, 28 },
|
||||
{ 0, 15 },
|
||||
{ 0, 15 },
|
||||
{ 0, 15 },
|
||||
{ 0, 15 },
|
||||
{ 0, 15 },
|
||||
{ 0, 15 },
|
||||
{ 0, 15 },
|
||||
{ 0, 15 },
|
||||
{ 0, 15 },
|
||||
{ 0, 15 },
|
||||
{ 40, 2 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 29, 29 },
|
||||
{ 0, 16 },
|
||||
{ 0, 16 },
|
||||
{ 0, 16 },
|
||||
{ 0, 16 },
|
||||
{ 0, 16 },
|
||||
{ 0, 16 },
|
||||
{ 0, 16 },
|
||||
{ 0, 16 },
|
||||
{ 0, 16 },
|
||||
{ 0, 16 },
|
||||
{ 19, 2 },
|
||||
{ 32, 24 },
|
||||
{ 39, 37 },
|
||||
{ 21, 3 },
|
||||
{ 24, 6 },
|
||||
{ 31, 23 },
|
||||
{ 36, 32 },
|
||||
{ 34, 30 },
|
||||
{ 30, 21 },
|
||||
{ 37, 33 },
|
||||
{ 23, 5 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 25, 6 },
|
||||
{ 40, 2 },
|
||||
{ 8, 2 },
|
||||
{ 20, 2 },
|
||||
{ 33, 25 },
|
||||
{ 41, 2 },
|
||||
{ 15, 2 },
|
||||
{ 40, 38 },
|
||||
{ 22, 4 },
|
||||
{ 25, 7 },
|
||||
{ 32, 24 },
|
||||
{ 37, 33 },
|
||||
{ 35, 31 },
|
||||
{ 38, 36 },
|
||||
{ 11, 2 },
|
||||
{ 12, 2 },
|
||||
{ 0, 0 },
|
||||
{ 31, 22 },
|
||||
{ 38, 34 },
|
||||
{ 24, 6 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 17, 17 },
|
||||
{ 26, 7 },
|
||||
{ 19, 2 },
|
||||
{ 9, 2 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 34, 26 },
|
||||
{ 41, 2 },
|
||||
{ 16, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 23, 5 },
|
||||
{ 36, 32 },
|
||||
{ 39, 37 },
|
||||
{ 12, 2 },
|
||||
{ 13, 2 },
|
||||
{ 0, 0 },
|
||||
{ 10, 2 },
|
||||
{ 0, 0 },
|
||||
{ 7, 2 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 18, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 17, 2 },
|
||||
{ 0, 0 },
|
||||
{ 11, 2 },
|
||||
{ 0, 0 },
|
||||
{ 8, 2 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
|
@ -493,21 +501,21 @@ void YYLEXNAME::yytables()
|
|||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 5, 2 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 4, 2 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 6, 2 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 3, 2 },
|
||||
{ 0, 0 },
|
||||
{ 5, 2 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 7, 2 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 4, 2 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
|
@ -515,55 +523,55 @@ void YYLEXNAME::yytables()
|
|||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 0, 0 },
|
||||
{ 13, 2 },
|
||||
{ 14, 2 },
|
||||
{ 0, 0 },
|
||||
{ 14, 2 }
|
||||
{ 15, 2 }
|
||||
};
|
||||
yytransition = transition;
|
||||
|
||||
static const yystate_t YYNEARFAR YYBASED_CODE state[] = {
|
||||
{ 0, 0, 0 },
|
||||
{ 2, 1, 0 },
|
||||
{ -20, 125, 0 },
|
||||
{ 37, 22, 21 },
|
||||
{ 0, 60, 21 },
|
||||
{ 0, 37, 21 },
|
||||
{ 0, 42, 21 },
|
||||
{ 8, 1, 7 },
|
||||
{ 0, 2, 21 },
|
||||
{ 0, 0, 10 },
|
||||
{ -21, 125, 0 },
|
||||
{ 0, 0, 2 },
|
||||
{ 38, 22, 22 },
|
||||
{ 0, 60, 22 },
|
||||
{ 0, 37, 22 },
|
||||
{ 0, 42, 22 },
|
||||
{ 9, 1, 8 },
|
||||
{ 0, 2, 22 },
|
||||
{ 0, 0, 11 },
|
||||
{ 0, 0, 12 },
|
||||
{ 0, 0, 13 },
|
||||
{ 0, 0, 14 },
|
||||
{ 0, 0, 15 },
|
||||
{ 28, 76, 21 },
|
||||
{ 0, 1, 21 },
|
||||
{ 0, 0, 16 },
|
||||
{ 29, 76, 22 },
|
||||
{ 0, 98, 18 },
|
||||
{ 0, 3, 19 },
|
||||
{ 0, 0, 20 },
|
||||
{ 0, 1, 22 },
|
||||
{ 0, 1, 20 },
|
||||
{ 0, 0, 21 },
|
||||
{ 0, 0, 22 },
|
||||
{ 0, 32, 0 },
|
||||
{ 0, 0, 3 },
|
||||
{ 32, 25, 0 },
|
||||
{ 0, 0, 4 },
|
||||
{ 33, 25, 0 },
|
||||
{ 0, 19, 0 },
|
||||
{ 0, 54, 0 },
|
||||
{ 0, 0, 8 },
|
||||
{ 0, 0, 9 },
|
||||
{ 37, 1, 16 },
|
||||
{ -29, 3, 17 },
|
||||
{ 0, 0, 10 },
|
||||
{ 38, 1, 17 },
|
||||
{ -30, 1, 19 },
|
||||
{ 0, 30, 0 },
|
||||
{ 36, 62, 0 },
|
||||
{ 37, 62, 0 },
|
||||
{ 0, 26, 0 },
|
||||
{ 0, 34, 0 },
|
||||
{ 0, 0, 2 },
|
||||
{ 0, 0, 4 },
|
||||
{ 0, 0, 3 },
|
||||
{ 0, 0, 5 },
|
||||
{ 0, 63, 0 },
|
||||
{ 0, 21, 0 },
|
||||
{ 0, 0, 5 },
|
||||
{ 0, 0, 6 },
|
||||
{ 18, 2, 19 },
|
||||
{ -41, 4, 1 }
|
||||
{ 0, 0, 7 },
|
||||
{ -41, 2, 1 }
|
||||
};
|
||||
yystate = state;
|
||||
|
||||
|
@ -589,6 +597,7 @@ void YYLEXNAME::yytables()
|
|||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
yybackup = backup;
|
||||
|
|
|
@ -15,11 +15,34 @@ protected:
|
|||
virtual int yyaction(int action);
|
||||
|
||||
public:
|
||||
#line 23 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
#line 24 "C:\\spongebob\\Utils\\scripter\\lexer.l"
|
||||
|
||||
// place any extra class members here
|
||||
int openInputFile(char *_filename);
|
||||
int closeInputFile();
|
||||
|
||||
#line 23 "C:\\spongebob\\Utils\\scripter\\lexer.h"
|
||||
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() {m_errorCount++;}
|
||||
|
||||
|
||||
// Overridden lexer functions
|
||||
int yygetchar();
|
||||
|
||||
private:
|
||||
FILE *m_fhInput;
|
||||
int m_charCount;
|
||||
int m_lineCount;
|
||||
int m_currentCharOnLine;
|
||||
int m_errorCount;
|
||||
|
||||
class myparser *m_currentParser;
|
||||
|
||||
#line 46 "C:\\spongebob\\Utils\\scripter\\lexer.h"
|
||||
};
|
||||
|
||||
#ifndef YYLEXNAME
|
||||
|
|
|
@ -8,6 +8,7 @@ Date: 07 December 2000
|
|||
|
||||
#include "parser.h"
|
||||
#include "var.h"
|
||||
#include "prepro.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
@ -21,7 +22,30 @@ Date: 07 December 2000
|
|||
|
||||
// class definition
|
||||
{
|
||||
// place any extra class members here
|
||||
int openInputFile(char *_filename);
|
||||
int closeInputFile();
|
||||
|
||||
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() {m_errorCount++;}
|
||||
|
||||
|
||||
// Overridden lexer functions
|
||||
int yygetchar();
|
||||
|
||||
private:
|
||||
FILE *m_fhInput;
|
||||
int m_charCount;
|
||||
int m_lineCount;
|
||||
int m_currentCharOnLine;
|
||||
int m_errorCount;
|
||||
|
||||
class myparser *m_currentParser;
|
||||
}
|
||||
|
||||
// constructor
|
||||
|
@ -44,8 +68,9 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
|
|||
|
||||
// place your Lex rules here
|
||||
|
||||
^[ \t]*#.* {/*preprocess(yytext);*/}
|
||||
//# {yyerror("# commands must be at start of line!");}
|
||||
^#.* {if(preprocessorCmd(yytext+1)!=0)error();}
|
||||
# {printf("# commands must be at start of line! ( line %d )\n",getCurrentLine());error();}
|
||||
|
||||
stop {return STOP;}
|
||||
if {return IF;}
|
||||
else {return ELSE;}
|
||||
|
@ -60,13 +85,16 @@ print {return PRINT;}
|
|||
\) {return CLOSE_PAR;}
|
||||
\{ {return BEGIN_CS;}
|
||||
\} {return END_CS;}
|
||||
\$[a-zA-Z_][a-zA-Z_0-9]* {yylval.variableIdx=lookupVarName(yytext+1);return VARIABLE;}
|
||||
\/\/.* {}
|
||||
[0-9]+ {yylval.value=atoi(yytext);return VALUE;}
|
||||
[ \t]+ {}
|
||||
\n {/*s_linesProcessed++;*/}
|
||||
. {printf("?\n");/*printf("line:%d\n",yylineno);printf("-%s-\n",yytext);yyerror("Unexpected character in source");*/}
|
||||
|
||||
\$[a-zA-Z_][a-zA-Z_0-9]* {yylval.variableIdx=lookupVarName(yytext+1);return VARIABLE;}
|
||||
[0-9]+ {yylval.value=atoi(yytext);return VALUE;}
|
||||
// \"[^\"]*\" {printf("s:%s\n",yytext);return STRING;}
|
||||
|
||||
\/\/.* {}
|
||||
[ \t]+ {}
|
||||
\n {}
|
||||
|
||||
. {printf("UNEXPECTED CHAR: '%s' in line %d ( char %d )\n",yytext,getCurrentLine(),getCurrentCharOnLine());error();}
|
||||
|
||||
%%
|
||||
|
||||
|
|
|
@ -17,11 +17,20 @@
|
|||
-------- */
|
||||
|
||||
#include "main.h"
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
|
||||
#ifndef __CODEGEN_H__
|
||||
#include "codegen.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* Std Lib
|
||||
------- */
|
||||
|
||||
#include <yacc.h>
|
||||
|
||||
|
||||
/* Data
|
||||
---- */
|
||||
|
||||
|
@ -42,24 +51,6 @@
|
|||
---- */
|
||||
|
||||
|
||||
int openInputFile(char *_filename)
|
||||
{
|
||||
int ret=1;
|
||||
|
||||
if((yyin=fopen(_filename,"rt"))==NULL)
|
||||
{
|
||||
ret=0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int closeInputFile()
|
||||
{
|
||||
fclose(yyin);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
|
@ -68,84 +59,73 @@ int closeInputFile()
|
|||
---------------------------------------------------------------------- */
|
||||
extern int main(int argc, char *argv[])
|
||||
{
|
||||
int ret=-1;
|
||||
int ret;
|
||||
|
||||
|
||||
// Process args
|
||||
if(argc!=3)
|
||||
{
|
||||
printf("Script compiler thingy\n");
|
||||
printf("Usage: yl infile outfile\n");
|
||||
printf("So there..\n\n");
|
||||
ret=-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *inputfile;
|
||||
char *outputfile;
|
||||
char *infile;
|
||||
char *outfile;
|
||||
|
||||
inputfile=argv[1];
|
||||
outputfile=argv[2];
|
||||
infile=argv[1];
|
||||
outfile=argv[2];
|
||||
|
||||
// Parse file
|
||||
printf("Parsing file: %s\n",inputfile);
|
||||
if(!openInputFile(inputfile))
|
||||
if(parseFile(infile,s_baseTreeNode)==YYEXIT_SUCCESS&&s_baseTreeNode)
|
||||
{
|
||||
printf("Cannot open input file!\n");
|
||||
}
|
||||
else
|
||||
if(openOutputFile(outfile))
|
||||
{
|
||||
if(yyparse()!=YYEXIT_SUCCESS)
|
||||
{
|
||||
s_errorCount++;
|
||||
}
|
||||
closeInputFile();
|
||||
printf("%d line(s) parsed, %d error(s) found\n",s_linesProcessed,s_errorCount);
|
||||
|
||||
// Generate code
|
||||
if(s_baseTreeNode&&!s_errorCount)
|
||||
{
|
||||
printf("Creating output file: %s\n",outputfile);
|
||||
if(!openOutputFile(outputfile))
|
||||
{
|
||||
printf("Couldn't open output file!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
int codeSize=0;
|
||||
|
||||
codeSize=genCode(s_baseTreeNode,true);
|
||||
int byteCount;
|
||||
byteCount=s_baseTreeNode->generateCode(true);
|
||||
closeOutputFile();
|
||||
printf("Generated %d instructions(s)\n",codeSize);
|
||||
ret=0; // Huzzah!
|
||||
printf("Generated %d bytes of code\n",byteCount*2);
|
||||
ret=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret=-1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret=-1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
int n=1;
|
||||
|
||||
openOutputFile("test.dat");
|
||||
mylexer lexer;
|
||||
myparser parser;
|
||||
if(parser.yycreate(&lexer))
|
||||
{
|
||||
if(lexer.yycreate(&parser))
|
||||
{
|
||||
n=parser.yyparse();
|
||||
}
|
||||
}
|
||||
|
||||
if(s_baseTreeNode)
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
int mylexer::openInputFile(char *_filename)
|
||||
{
|
||||
s_baseTreeNode->generateCode(true);
|
||||
int ret=1;
|
||||
|
||||
printf("Opening %s..\n",_filename);
|
||||
if((m_fhInput=fopen(_filename,"rt"))==NULL)
|
||||
{
|
||||
printf("FATAL: Couldn't open file for reading\n");
|
||||
ret=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_charCount=0;
|
||||
m_lineCount=0;
|
||||
m_currentCharOnLine=0;
|
||||
m_errorCount=0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
closeOutputFile();
|
||||
|
||||
return n;
|
||||
*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
|
@ -154,6 +134,16 @@ closeOutputFile();
|
|||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
int mylexer::closeInputFile()
|
||||
{
|
||||
printf("Processed %d char(s), %d line(s)\n",m_charCount,m_lineCount);
|
||||
if(m_errorCount)
|
||||
{
|
||||
printf("Found %d error(s) :(\n",m_errorCount);
|
||||
}
|
||||
fclose(m_fhInput);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
|
@ -162,6 +152,40 @@ closeOutputFile();
|
|||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
int mylexer::yygetchar()
|
||||
{
|
||||
char c;
|
||||
int ret;
|
||||
|
||||
if(fread(&c,sizeof(c),1,m_fhInput)==1)
|
||||
{
|
||||
m_charCount++;
|
||||
m_currentCharOnLine++;
|
||||
if(c=='\n')
|
||||
{
|
||||
m_lineCount++;
|
||||
m_currentCharOnLine=0;
|
||||
}
|
||||
ret=c;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ferror(m_fhInput))
|
||||
{
|
||||
printf("FATAL: Read error!\n");
|
||||
}
|
||||
ret=-1;
|
||||
}
|
||||
|
||||
// Force compilation to stop after finding errors ( hmm.. )
|
||||
if(m_errorCount)
|
||||
{
|
||||
printf("Stopping compilation!\n");
|
||||
ret=-1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
|
@ -170,6 +194,10 @@ closeOutputFile();
|
|||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
void myparser::setCurrentLexer(mylexer *_lexer)
|
||||
{
|
||||
m_currentLexer=_lexer;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
|
@ -178,6 +206,45 @@ closeOutputFile();
|
|||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
void myparser::setBaseNode(class CTreeNode *_baseNode)
|
||||
{
|
||||
m_baseNode=_baseNode;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
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());
|
||||
m_currentLexer->error();
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
int myparser::yyparse()
|
||||
{
|
||||
int ret=YYEXIT_FAILURE;
|
||||
|
||||
if(yysetup()==0&&
|
||||
yywork()==YYEXIT_SUCCESS&&
|
||||
m_currentLexer->getErrorCount()==0)
|
||||
{
|
||||
ret=YYEXIT_SUCCESS;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
|
|
|
@ -26,7 +26,7 @@ Date: 07 December 2000
|
|||
YYPARSENAME::YYPARSENAME()
|
||||
{
|
||||
yytables();
|
||||
#line 27 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 38 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
|
||||
// place any extra initialisation code here
|
||||
|
||||
|
@ -75,7 +75,7 @@ void YYPARSENAME::yyaction(int action)
|
|||
yyinitdebug((void YYFAR**)yya, 2);
|
||||
#endif
|
||||
{
|
||||
#line 80 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 92 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
s_baseTreeNode=yyattribute(1 - 1).treenode;
|
||||
#line 81 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 3);
|
||||
#endif
|
||||
{
|
||||
#line 84 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 96 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(STMT_LIST,yyattribute(1 - 2).treenode,yyattribute(2 - 2).treenode);
|
||||
#line 94 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
break;
|
||||
case 2:
|
||||
{
|
||||
#line 85 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 97 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(EMPTY_STMT);
|
||||
#line 102 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 2);
|
||||
#endif
|
||||
{
|
||||
#line 89 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 101 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(EMPTY_STMT);
|
||||
#line 114 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 3);
|
||||
#endif
|
||||
{
|
||||
#line 90 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 102 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(STOP_STMT);
|
||||
#line 127 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 3);
|
||||
#endif
|
||||
{
|
||||
#line 91 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 103 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(PAUSE_STMT);
|
||||
#line 140 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 6);
|
||||
#endif
|
||||
{
|
||||
#line 92 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 104 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(PRINT_STMT,yyattribute(3 - 5).treenode);
|
||||
#line 153 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 3);
|
||||
#endif
|
||||
{
|
||||
#line 93 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 105 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(1 - 2).treenode;
|
||||
#line 166 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 6);
|
||||
#endif
|
||||
{
|
||||
#line 94 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 106 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(IF_STMT,yyattribute(3 - 5).treenode,yyattribute(5 - 5).treenode);
|
||||
#line 179 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 8);
|
||||
#endif
|
||||
{
|
||||
#line 95 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 107 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(IFELSE_STMT,yyattribute(3 - 7).treenode,yyattribute(5 - 7).treenode,yyattribute(7 - 7).treenode);
|
||||
#line 192 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 4);
|
||||
#endif
|
||||
{
|
||||
#line 96 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 108 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(STMT_LIST,yyattribute(2 - 3).treenode);
|
||||
#line 205 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 4);
|
||||
#endif
|
||||
{
|
||||
#line 101 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 113 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(ASSIGN_EXPR,yyattribute(1 - 3).treenode,yyattribute(3 - 3).treenode);
|
||||
#line 218 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 4);
|
||||
#endif
|
||||
{
|
||||
#line 106 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 118 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(2 - 3).treenode;
|
||||
#line 231 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 2);
|
||||
#endif
|
||||
{
|
||||
#line 107 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 119 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(1 - 1).treenode;
|
||||
#line 244 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 2);
|
||||
#endif
|
||||
{
|
||||
#line 108 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 120 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(1 - 1).treenode;
|
||||
#line 257 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 4);
|
||||
#endif
|
||||
{
|
||||
#line 112 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 124 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(EQUAL_EXPR,yyattribute(1 - 3).treenode,yyattribute(3 - 3).treenode);
|
||||
#line 270 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 4);
|
||||
#endif
|
||||
{
|
||||
#line 116 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 128 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(NOTEQUAL_EXPR,yyattribute(1 - 3).treenode,yyattribute(3 - 3).treenode);
|
||||
#line 283 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 2);
|
||||
#endif
|
||||
{
|
||||
#line 121 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 133 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(VARIABLE_EXPR,yyattribute(1 - 1).variableIdx);
|
||||
#line 296 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 2);
|
||||
#endif
|
||||
{
|
||||
#line 125 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 137 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(VALUE_EXPR,yyattribute(1 - 1).value);
|
||||
#line 309 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 2);
|
||||
#endif
|
||||
{
|
||||
#line 126 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 138 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(VARIABLE_EXPR,yyattribute(1 - 1).variableIdx);
|
||||
#line 322 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
yyinitdebug((void YYFAR**)yya, 4);
|
||||
#endif
|
||||
{
|
||||
#line 127 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 139 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(PLUS_EXPR,yyattribute(1 - 3).treenode,yyattribute(3 - 3).treenode);
|
||||
#line 335 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
}
|
||||
|
@ -340,39 +340,14 @@ s_baseTreeNode=yyattribute(1 - 1).treenode;
|
|||
break;
|
||||
}
|
||||
}
|
||||
#line 130 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 144 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// programs section
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int n=1;
|
||||
|
||||
openOutputFile("test.dat");
|
||||
mylexer lexer;
|
||||
myparser parser;
|
||||
if(parser.yycreate(&lexer))
|
||||
{
|
||||
if(lexer.yycreate(&parser))
|
||||
{
|
||||
n=parser.yyparse();
|
||||
}
|
||||
}
|
||||
|
||||
if(s_baseTreeNode)
|
||||
{
|
||||
s_baseTreeNode->generateCode(true);
|
||||
}
|
||||
closeOutputFile();
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
#line 376 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
#line 351 "C:\\spongebob\\Utils\\scripter\\parser.cpp"
|
||||
void YYPARSENAME::yytables()
|
||||
{
|
||||
yyattribute_size = sizeof(YYSTYPE);
|
||||
|
|
|
@ -21,9 +21,20 @@ protected:
|
|||
public:
|
||||
#line 22 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
|
||||
// place any extra class members here
|
||||
public:
|
||||
void setCurrentLexer(class mylexer *_lexer);
|
||||
void setBaseNode(class CTreeNode *_baseNode);
|
||||
|
||||
#line 27 "C:\\spongebob\\Utils\\scripter\\parser.h"
|
||||
// Overridden parser functions
|
||||
void yyerror(const char *_text);
|
||||
int yyparse();
|
||||
|
||||
private:
|
||||
class mylexer *m_currentLexer;
|
||||
class CTreeNode *m_baseNode;
|
||||
|
||||
|
||||
#line 38 "C:\\spongebob\\Utils\\scripter\\parser.h"
|
||||
};
|
||||
|
||||
#ifndef YYPARSENAME
|
||||
|
@ -32,13 +43,13 @@ public:
|
|||
|
||||
#ifndef YYSTYPE
|
||||
union tagYYSTYPE {
|
||||
#line 38 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
#line 49 "C:\\spongebob\\Utils\\scripter\\parser.y"
|
||||
|
||||
int variableIdx;
|
||||
signed short value;
|
||||
class CTreeNode *treenode;
|
||||
|
||||
#line 42 "C:\\spongebob\\Utils\\scripter\\parser.h"
|
||||
#line 53 "C:\\spongebob\\Utils\\scripter\\parser.h"
|
||||
};
|
||||
|
||||
#define YYSTYPE union tagYYSTYPE
|
||||
|
|
|
@ -20,7 +20,18 @@ Date: 07 December 2000
|
|||
|
||||
// class definition
|
||||
{
|
||||
// place any extra class members here
|
||||
public:
|
||||
void setCurrentLexer(class mylexer *_lexer);
|
||||
void setBaseNode(class CTreeNode *_baseNode);
|
||||
|
||||
// Overridden parser functions
|
||||
void yyerror(const char *_text);
|
||||
int yyparse();
|
||||
|
||||
private:
|
||||
class mylexer *m_currentLexer;
|
||||
class CTreeNode *m_baseNode;
|
||||
|
||||
}
|
||||
|
||||
// constructor
|
||||
|
@ -45,6 +56,7 @@ Date: 07 December 2000
|
|||
|
||||
// place any declarations here
|
||||
|
||||
|
||||
%token STOP
|
||||
%token IF
|
||||
%token ELSE
|
||||
|
@ -127,33 +139,10 @@ value
|
|||
|value PLUS value {$$=new CTreeNode(PLUS_EXPR,$1,$3);}
|
||||
;
|
||||
|
||||
|
||||
|
||||
%%
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// programs section
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int n=1;
|
||||
|
||||
openOutputFile("test.dat");
|
||||
mylexer lexer;
|
||||
myparser parser;
|
||||
if(parser.yycreate(&lexer))
|
||||
{
|
||||
if(lexer.yycreate(&parser))
|
||||
{
|
||||
n=parser.yyparse();
|
||||
}
|
||||
}
|
||||
|
||||
if(s_baseTreeNode)
|
||||
{
|
||||
s_baseTreeNode->generateCode(true);
|
||||
}
|
||||
closeOutputFile();
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
/* Std Lib
|
||||
------- */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -36,14 +37,49 @@
|
|||
/*----------------------------------------------------------------------
|
||||
Structure defintions
|
||||
-------------------- */
|
||||
typedef struct
|
||||
{
|
||||
char *m_cmd;
|
||||
int (*m_func)(char *_cmd);
|
||||
} PreproCmd;
|
||||
|
||||
|
||||
typedef struct _macro
|
||||
{
|
||||
char *m_name;
|
||||
char *m_replacement;
|
||||
_macro *m_next;
|
||||
} Macro;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function Prototypes
|
||||
------------------- */
|
||||
|
||||
static int ppf_define(char *_cmd);
|
||||
static int ppf_include(char *_cmd);
|
||||
static int ppf_print(char *_cmd);
|
||||
|
||||
static int addMacro(char *_name,char *_replacement);
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Vars
|
||||
---- */
|
||||
static PreproCmd s_preproCmds[]=
|
||||
{
|
||||
{ "define", ppf_define },
|
||||
{ "include", ppf_include },
|
||||
{ "print", ppf_print },
|
||||
};
|
||||
static int s_numPreproCmds=sizeof(s_preproCmds)/sizeof(PreproCmd);
|
||||
|
||||
|
||||
static Macro *s_macros;
|
||||
|
||||
static char s_seps[]=" \t";
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
|
@ -51,6 +87,129 @@
|
|||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
extern int preprocessorCmd(char *_cmd)
|
||||
{
|
||||
int i;
|
||||
PreproCmd *pp;
|
||||
|
||||
pp=s_preproCmds;
|
||||
for(i=0;i<s_numPreproCmds;i++)
|
||||
{
|
||||
if(strnicmp(_cmd,pp->m_cmd,strlen(pp->m_cmd))==0)
|
||||
{
|
||||
return pp->m_func(_cmd);
|
||||
}
|
||||
pp++;
|
||||
}
|
||||
|
||||
printf("UNKNOWN PREPROCESSOR CMD '%s'\n",_cmd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
static int ppf_define(char *_cmd)
|
||||
{
|
||||
char *macroName;
|
||||
char *macroReplacement;
|
||||
|
||||
macroName=strtok(_cmd,s_seps);
|
||||
macroName=strtok(NULL,s_seps);
|
||||
macroReplacement=strtok(NULL,s_seps);
|
||||
|
||||
return addMacro(macroName,macroReplacement);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
static int ppf_include(char *_cmd)
|
||||
{
|
||||
char *includeFile;
|
||||
|
||||
includeFile=strtok(_cmd,s_seps);
|
||||
includeFile=strtok(NULL,s_seps);
|
||||
|
||||
// printf("include: '%s'\n",includeFile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
static int ppf_print(char *_cmd)
|
||||
{
|
||||
char *printMessage;
|
||||
|
||||
printMessage=strtok(_cmd,s_seps);
|
||||
printMessage=strtok(NULL,s_seps);
|
||||
|
||||
printf("#print %s\n",printMessage);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
static int addMacro(char *_name,char *_replacement)
|
||||
{
|
||||
Macro *mac,*newMac;
|
||||
|
||||
mac=s_macros;
|
||||
while(mac&&mac->m_next)
|
||||
{
|
||||
if(strcmp(_name,mac->m_replacement)==0)
|
||||
{
|
||||
printf("MACRO '%s' ALREADY DEFINED\n",_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
newMac=(Macro*)malloc(sizeof(Macro));
|
||||
newMac->m_name=(char*)malloc(strlen(_name+1));
|
||||
newMac->m_replacement=(char*)malloc(strlen(_name+1));
|
||||
strcpy(newMac->m_name,_name);
|
||||
strcpy(newMac->m_replacement,_replacement);
|
||||
newMac->m_next=s_macros;
|
||||
s_macros=newMac;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
extern char *lookupMacro(char *_name)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
end */
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
|
||||
extern int preprocessorCmd(char *_cmd);
|
||||
|
||||
extern char *lookupMacro(char *_name);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------- */
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ CFG=scripter - Win32 Debug
|
|||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
# PROP Scc_ProjName ""$/Utils/scripter", YFEAAAAA"
|
||||
# PROP Scc_LocalPath "."
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
|
@ -132,6 +132,22 @@ SOURCE=.\codegen.h
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\prepro.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\prepro.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\var.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue