diff --git a/Utils/Scripter/codegen.cpp b/Utils/Scripter/codegen.cpp index 246488a4e..bffe91dd9 100644 --- a/Utils/Scripter/codegen.cpp +++ b/Utils/Scripter/codegen.cpp @@ -26,6 +26,10 @@ #include "parser.h" #endif +#ifndef __FUNCTION_H__ +#include "function.h" +#endif + /* Std Lib ------- */ @@ -76,7 +80,7 @@ extern int parseFile(char *_filename,CTreeNode *_baseNode) { if(s_lexer.yycreate(&s_parser)) { - if(s_lexer.openInputFile(_filename)==true) + if(s_lexer.openInputFile(_filename)==(int)true) { s_parser.setCurrentLexer(&s_lexer); s_parser.setBaseNode(_baseNode); @@ -180,6 +184,9 @@ CTreeNode::CTreeNode(NodeType _type,int _data) case VALUE_EXPR: m_value=_data; break; + case FUNCTION_EXPR: + m_functionNumber=_data; + break; default: printf("ARSE\n"); break; @@ -240,7 +247,11 @@ int CTreeNode::generateCode(int _write) codeSize+=emit(OP_JMP,_write); codeSize+=m_children[2]->generateCode(_write); break; - + + case POP_STMT: // pop + codeSize+=emit(OP_POP,_write); + break; + case ASSIGN_EXPR: // assign [ variable, number ] codeSize+=m_children[1]->generateCode(_write); codeSize+=emit(OP_PUSHVALUE,_write); @@ -274,6 +285,12 @@ int CTreeNode::generateCode(int _write) codeSize+=emit(OP_ADD,_write); break; + case FUNCTION_EXPR: // function [functionNumber] + codeSize+=emit(OP_CALL_FUNCTION,_write); + codeSize+=emit(getFunctionNumber(),_write); + codeSize+=emit(getFunctionArgCount(getFunctionNumber()),_write); + break; + default: printf("UNHANDLED CASE %d\n",m_type); break; diff --git a/Utils/Scripter/codegen.h b/Utils/Scripter/codegen.h index 92c64d6a5..58faf9eab 100644 --- a/Utils/Scripter/codegen.h +++ b/Utils/Scripter/codegen.h @@ -35,6 +35,7 @@ typedef enum PAUSE_STMT, // pause IF_STMT, // if [expression, ifcode] IFELSE_STMT, // if [expression, ifcode, elsecode] + POP_STMT, // pop // Expressions ASSIGN_EXPR, // assignment [variable, value] @@ -43,6 +44,7 @@ typedef enum VARIABLE_EXPR, // variable VALUE_EXPR, // value PLUS_EXPR, // + [value, value] + FUNCTION_EXPR, // function [functionNumber] }NodeType; @@ -64,26 +66,29 @@ public: int getVariableIdx() {return m_variableIdx;} int getValue() {return m_value;} int getType() {return m_type;} + int getFunctionNumber() {return m_functionNumber;} private: // Nothing else needs to know these so we may as well protect them enum { - // args stack data result + // args stack data result OP_NOP=0x1100, // OP_STOP, // OP_PAUSE, // OP_PUSHVALUE, // value OP_PUSHVARVALUE, // varidx - OP_JMP, // jump - OP_JMPF, // jump, value - OP_JMPT, // jump, value - OP_IS_EQUAL_VALUE, // value, value pushes result ( 0 or 1 ) to stack - OP_IS_NOTEQUAL_VALUE, // value, value pushes result ( 0 or 1 ) to stack - OP_ASSIGN, // varidx, value - OP_ADD, // value, value pushes result to stack - OP_PRINT, // value + OP_POP, // value + OP_JMP, // jump + OP_JMPF, // jump, value + OP_JMPT, // jump, value + OP_IS_EQUAL_VALUE, // value, value pushes result ( 0 or 1 ) to stack + OP_IS_NOTEQUAL_VALUE, // value, value pushes result ( 0 or 1 ) to stack + OP_ASSIGN, // varidx, value + OP_ADD, // value, value pushes result to stack + OP_PRINT, // value + OP_CALL_FUNCTION, // functionNumber, argcount args pushes return value to stack }; enum{MAX_CHILD_NODES=3}; @@ -95,6 +100,7 @@ private: NodeType m_type; CTreeNode *m_children[MAX_CHILD_NODES]; int m_numChildren; + int m_functionNumber; signed short m_variableIdx; signed short m_value; diff --git a/Utils/Scripter/function.cpp b/Utils/Scripter/function.cpp index 5a0073f9e..69429487e 100644 --- a/Utils/Scripter/function.cpp +++ b/Utils/Scripter/function.cpp @@ -45,6 +45,13 @@ Structure defintions -------------------- */ +struct FunctionDef +{ + char *m_name; + int m_argCount; +}; + + /*---------------------------------------------------------------------- Function Prototypes ------------------- */ @@ -54,7 +61,8 @@ ---- */ static FunctionDef s_functionNames[]= { - { 0, "print", 1, }, + { "setCharacterExpression", 2, }, // character, expression + { "setText", 1, }, // textId }; static int s_functionCount=sizeof(s_functionNames)/sizeof(FunctionDef); @@ -68,7 +76,7 @@ extern myparser s_parser; Params: Returns: ---------------------------------------------------------------------- */ -extern FunctionDef *lookupFunctionName(char *_name) +extern int lookupFunctionName(char *_name) { int i; FunctionDef *fp; @@ -78,14 +86,14 @@ extern FunctionDef *lookupFunctionName(char *_name) { if(strcmp(fp->m_name,_name)==0) { - return fp; + return i; } fp++; } printf("Unknown function name _%s\n",_name); s_lexer.error(); - return NULL; + return -1; } @@ -107,38 +115,63 @@ extern int getFunctionArgCount(int _functionNumber) Params: Returns: A treenode that contains all of the functions arguments ---------------------------------------------------------------------- */ -extern CTreeNode *getFunctionArgs(int _argCount) +extern CTreeNode *getFunctionArgs(int _functionNumber) { - int i; + int argCount,i; int tokenType; - if(_argCount) + argCount=s_functionNames[_functionNumber].m_argCount; + if(argCount) { CTreeNode *base; -// base=new CTreeNode(STMT_LIST - for(i=0;i<_argCount;i++) + base=NULL; + for(i=0;i -#line 20 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 21 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" // repeated because of possible precompiled header #include @@ -28,11 +29,11 @@ Date: 07 December 2000 YYLEXNAME::YYLEXNAME() { yytables(); -#line 45 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 46 "C:\\spongebob\\Utils\\scripter\\lexer.l" // place any extra initialisation code here -#line 36 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 37 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } #ifndef YYTEXT_SIZE @@ -78,166 +79,180 @@ void YYLEXNAME::yyunput(int ch) int YYLEXNAME::yyaction(int action) { -#line 57 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 58 "C:\\spongebob\\Utils\\scripter\\lexer.l" // extract yylval for use later on in actions YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr; -#line 87 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 88 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" yyreturnflg = 1; switch (action) { case 1: { -#line 64 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 65 "C:\\spongebob\\Utils\\scripter\\lexer.l" if(preprocessorCmd(yytext+1)!=(int)true)error(); -#line 94 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 95 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 2: { -#line 65 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 66 "C:\\spongebob\\Utils\\scripter\\lexer.l" printf("# commands must be at start of line!\n");error(); -#line 101 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 102 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 3: { -#line 67 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 68 "C:\\spongebob\\Utils\\scripter\\lexer.l" return STOP; -#line 108 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 109 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 4: { -#line 68 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 69 "C:\\spongebob\\Utils\\scripter\\lexer.l" return IF; -#line 115 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 116 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 5: { -#line 69 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 70 "C:\\spongebob\\Utils\\scripter\\lexer.l" return ELSE; -#line 122 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 123 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 6: { -#line 70 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 71 "C:\\spongebob\\Utils\\scripter\\lexer.l" return PAUSE; -#line 129 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 130 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 7: { -#line 71 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 72 "C:\\spongebob\\Utils\\scripter\\lexer.l" return PRINT; -#line 136 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 137 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 8: { -#line 72 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 73 "C:\\spongebob\\Utils\\scripter\\lexer.l" return ASSIGN; -#line 143 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 144 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 9: { -#line 73 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 74 "C:\\spongebob\\Utils\\scripter\\lexer.l" return EQUAL; -#line 150 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 151 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 10: { -#line 74 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 75 "C:\\spongebob\\Utils\\scripter\\lexer.l" return NOTEQUAL; -#line 157 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 158 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 11: { -#line 75 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 76 "C:\\spongebob\\Utils\\scripter\\lexer.l" return PLUS; -#line 164 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 165 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 12: { -#line 76 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 77 "C:\\spongebob\\Utils\\scripter\\lexer.l" return END_STMT; -#line 171 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 172 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 13: { -#line 77 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 78 "C:\\spongebob\\Utils\\scripter\\lexer.l" return OPEN_PAR; -#line 178 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 179 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 14: { -#line 78 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 79 "C:\\spongebob\\Utils\\scripter\\lexer.l" return CLOSE_PAR; -#line 185 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 186 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 15: { -#line 79 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 80 "C:\\spongebob\\Utils\\scripter\\lexer.l" return BEGIN_CS; -#line 192 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 193 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 16: { -#line 80 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 81 "C:\\spongebob\\Utils\\scripter\\lexer.l" return END_CS; -#line 199 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 200 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 17: { #line 82 "C:\\spongebob\\Utils\\scripter\\lexer.l" -yylval.variableIdx=lookupVarName(yytext+1);return VARIABLE; -#line 206 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +return COMMA; +#line 207 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 18: { -#line 83 "C:\\spongebob\\Utils\\scripter\\lexer.l" -yylval.value=atoi(yytext);return VALUE; -#line 213 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 85 "C:\\spongebob\\Utils\\scripter\\lexer.l" +yylval.variableIdx=lookupVarName(yytext+1);return VARIABLE; +#line 214 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 19: { #line 86 "C:\\spongebob\\Utils\\scripter\\lexer.l" - -#line 220 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +yylval.value=atoi(yytext);return VALUE; +#line 221 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 20: { -#line 87 "C:\\spongebob\\Utils\\scripter\\lexer.l" - -#line 227 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 89 "C:\\spongebob\\Utils\\scripter\\lexer.l" +yylval.functionNumber=lookupFunctionName(yytext+1);return FUNCTION; +#line 228 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 21: { -#line 88 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 91 "C:\\spongebob\\Utils\\scripter\\lexer.l" -#line 234 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 235 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; case 22: { -#line 90 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 92 "C:\\spongebob\\Utils\\scripter\\lexer.l" + +#line 242 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" + } + break; + case 23: + { +#line 93 "C:\\spongebob\\Utils\\scripter\\lexer.l" + +#line 249 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" + } + break; + case 24: + { +#line 95 "C:\\spongebob\\Utils\\scripter\\lexer.l" unexpectedChar(); -#line 241 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 256 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" } break; default: @@ -253,7 +268,7 @@ unexpectedChar(); #pragma warn .rch // to the old state #endif #endif -#line 92 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 97 "C:\\spongebob\\Utils\\scripter\\lexer.l" @@ -261,7 +276,7 @@ unexpectedChar(); // programs section -#line 265 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" +#line 280 "C:\\spongebob\\Utils\\scripter\\lexer.cpp" void YYLEXNAME::yytables() { @@ -273,7 +288,7 @@ void YYLEXNAME::yytables() }; yymatch = match; - yytransitionmax = 251; + yytransitionmax = 336; static const yytransition_t YYNEARFAR YYBASED_CODE transition[] = { { 0, 0 }, { 0, 0 }, @@ -285,9 +300,9 @@ void YYLEXNAME::yytables() { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 19, 19 }, - { 0, 30 }, - { 0, 41 }, + { 21, 21 }, + { 0, 33 }, + { 0, 44 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, @@ -308,7 +323,7 @@ void YYLEXNAME::yytables() { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 19, 19 }, + { 21, 21 }, { 0, 0 }, { 0, 0 }, { 3, 1 }, @@ -323,141 +338,226 @@ void YYLEXNAME::yytables() { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 30, 18 }, - { 29, 29 }, - { 29, 29 }, - { 29, 29 }, - { 29, 29 }, - { 29, 29 }, - { 29, 29 }, - { 29, 29 }, - { 29, 29 }, - { 29, 29 }, - { 29, 29 }, + { 33, 20 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 27, 8 }, - { 28, 9 }, + { 29, 8 }, + { 30, 9 }, { 0, 0 }, { 0, 0 }, - { 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 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 29, 29 }, + { 31, 31 }, { 0, 0 }, - { 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 }, - { 20, 2 }, - { 33, 25 }, - { 40, 38 }, - { 22, 4 }, - { 25, 7 }, - { 32, 24 }, - { 37, 33 }, - { 35, 31 }, - { 31, 22 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 31, 31 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 36, 27 }, + { 43, 41 }, + { 24, 4 }, + { 35, 26 }, + { 40, 36 }, { 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 }, + { 34, 24 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 41, 37 }, + { 26, 6 }, + { 37, 28 }, + { 25, 5 }, + { 32, 32 }, + { 39, 35 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 32, 32 }, + { 0, 17 }, + { 0, 17 }, + { 0, 17 }, + { 0, 17 }, + { 0, 17 }, + { 0, 17 }, + { 0, 17 }, + { 0, 17 }, + { 0, 17 }, + { 0, 17 }, + { 0, 19 }, + { 0, 19 }, + { 0, 19 }, + { 0, 19 }, + { 0, 19 }, + { 0, 19 }, + { 0, 19 }, + { 0, 19 }, + { 0, 19 }, + { 0, 19 }, + { 21, 2 }, + { 22, 2 }, + { 27, 7 }, + { 18, 18 }, + { 18, 18 }, + { 18, 18 }, + { 18, 18 }, + { 18, 18 }, + { 18, 18 }, + { 18, 18 }, + { 18, 18 }, + { 18, 18 }, + { 18, 18 }, + { 42, 40 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 28, 7 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 21, 2 }, { 9, 2 }, - { 34, 26 }, - { 41, 2 }, - { 16, 2 }, - { 23, 5 }, - { 36, 32 }, - { 39, 37 }, + { 0, 0 }, + { 44, 2 }, + { 17, 2 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, { 12, 2 }, { 13, 2 }, { 0, 0 }, { 10, 2 }, + { 16, 2 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, + { 20, 2 }, + { 18, 2 }, + { 18, 2 }, + { 18, 2 }, + { 18, 2 }, + { 18, 2 }, + { 18, 2 }, + { 18, 2 }, + { 18, 2 }, + { 18, 2 }, { 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 }, @@ -495,7 +595,7 @@ void YYLEXNAME::yytables() { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, + { 19, 2 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, @@ -532,46 +632,49 @@ void YYLEXNAME::yytables() static const yystate_t YYNEARFAR YYBASED_CODE state[] = { { 0, 0, 0 }, { 2, 1, 0 }, - { -21, 125, 0 }, + { -23, 210, 0 }, { 0, 0, 2 }, - { 38, 22, 22 }, - { 0, 60, 22 }, - { 0, 37, 22 }, - { 0, 42, 22 }, + { 41, 20, 24 }, + { 0, 68, 24 }, + { 0, 60, 24 }, + { 0, 124, 24 }, { 9, 1, 8 }, - { 0, 2, 22 }, + { 0, 2, 24 }, { 0, 0, 11 }, { 0, 0, 12 }, { 0, 0, 13 }, { 0, 0, 14 }, { 0, 0, 15 }, { 0, 0, 16 }, - { 29, 76, 22 }, - { 0, 98, 18 }, + { 0, 0, 17 }, + { 31, 151, 24 }, + { 0, 174, 19 }, + { 32, 161, 24 }, + { 0, 1, 24 }, { 0, 1, 22 }, - { 0, 1, 20 }, - { 0, 0, 21 }, - { 0, 0, 22 }, - { 0, 32, 0 }, + { 0, 0, 23 }, + { 0, 0, 24 }, + { 0, 29, 0 }, { 0, 0, 4 }, - { 33, 25, 0 }, - { 0, 19, 0 }, - { 0, 54, 0 }, + { 36, 22, 0 }, + { 0, 17, 0 }, + { 0, 64, 0 }, { 0, 0, 9 }, { 0, 0, 10 }, - { 38, 1, 17 }, - { -30, 1, 19 }, - { 0, 30, 0 }, - { 37, 62, 0 }, - { 0, 26, 0 }, - { 0, 34, 0 }, + { 41, 1, 18 }, + { 41, 76, 20 }, + { -33, 1, 21 }, + { 0, 27, 0 }, + { 40, 71, 0 }, + { 0, 23, 0 }, + { 0, 57, 0 }, { 0, 0, 3 }, { 0, 0, 5 }, - { 0, 63, 0 }, - { 0, 21, 0 }, + { 0, 131, 0 }, + { 0, 19, 0 }, { 0, 0, 6 }, { 0, 0, 7 }, - { -41, 2, 1 } + { -44, 2, 1 } }; yystate = state; @@ -598,6 +701,8 @@ void YYLEXNAME::yytables() 0, 0, 0, + 0, + 0, 0 }; yybackup = backup; diff --git a/Utils/Scripter/lexer.h b/Utils/Scripter/lexer.h index 4fb28b7fa..aebafc298 100644 --- a/Utils/Scripter/lexer.h +++ b/Utils/Scripter/lexer.h @@ -15,7 +15,7 @@ protected: virtual int yyaction(int action); public: -#line 24 "C:\\spongebob\\Utils\\scripter\\lexer.l" +#line 25 "C:\\spongebob\\Utils\\scripter\\lexer.l" int openInputFile(char *_filename); int closeInputFile(); diff --git a/Utils/Scripter/lexer.l b/Utils/Scripter/lexer.l index 009a60c50..533b209ac 100644 --- a/Utils/Scripter/lexer.l +++ b/Utils/Scripter/lexer.l @@ -8,6 +8,7 @@ Date: 07 December 2000 #include "parser.h" #include "var.h" +#include "function.h" #include "prepro.h" #include @@ -78,11 +79,15 @@ print {return PRINT;} \) {return CLOSE_PAR;} \{ {return BEGIN_CS;} \} {return END_CS;} +, {return COMMA;} + \$[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;} +_[a-zA-Z_][a-zA-Z_0-9]* {yylval.functionNumber=lookupFunctionName(yytext+1);return FUNCTION;} + \/\/.* {} [ \t]+ {} \n {} diff --git a/Utils/Scripter/parser.cpp b/Utils/Scripter/parser.cpp index 37a229a96..5dc6a322e 100644 --- a/Utils/Scripter/parser.cpp +++ b/Utils/Scripter/parser.cpp @@ -9,12 +9,13 @@ ParserWizard generated YACC file. Date: 07 December 2000 ****************************************************************************/ +#include "function.h" #include "lexer.h" #include "codegen.h" -#line 18 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 19 "C:\\spongebob\\Utils\\scripter\\parser.cpp" // repeated because of possible precompiled header #include @@ -26,11 +27,11 @@ Date: 07 December 2000 YYPARSENAME::YYPARSENAME() { yytables(); -#line 38 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 43 "C:\\spongebob\\Utils\\scripter\\parser.y" // place any extra initialisation code here -#line 34 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 35 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } #ifndef YYSTYPE @@ -75,9 +76,9 @@ void YYPARSENAME::yyaction(int action) yyinitdebug((void YYFAR**)yya, 2); #endif { -#line 92 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 102 "C:\\spongebob\\Utils\\scripter\\parser.y" s_baseTreeNode=yyattribute(1 - 1).treenode; -#line 81 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 82 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -88,17 +89,17 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 3); #endif { -#line 96 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 106 "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" +#line 95 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; case 2: { -#line 97 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 107 "C:\\spongebob\\Utils\\scripter\\parser.y" (*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(EMPTY_STMT); -#line 102 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 103 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } break; case 3: @@ -108,9 +109,9 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 2); #endif { -#line 101 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 111 "C:\\spongebob\\Utils\\scripter\\parser.y" (*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(EMPTY_STMT); -#line 114 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 115 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -121,9 +122,9 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 3); #endif { -#line 102 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 112 "C:\\spongebob\\Utils\\scripter\\parser.y" (*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(STOP_STMT); -#line 127 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 128 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -134,9 +135,9 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 3); #endif { -#line 103 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 113 "C:\\spongebob\\Utils\\scripter\\parser.y" (*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(PAUSE_STMT); -#line 140 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 141 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -147,9 +148,9 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 6); #endif { -#line 104 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 114 "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" +#line 154 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -160,9 +161,9 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 3); #endif { -#line 105 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 115 "C:\\spongebob\\Utils\\scripter\\parser.y" (*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(1 - 2).treenode; -#line 166 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 167 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -173,9 +174,9 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 6); #endif { -#line 106 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 116 "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" +#line 180 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -186,9 +187,9 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 8); #endif { -#line 107 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 117 "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" +#line 193 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -199,22 +200,22 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 4); #endif { -#line 108 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 118 "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" +#line 206 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; case 11: { #ifdef YYDEBUG - YYSTYPE YYFAR* yya[4]; - yyinitdebug((void YYFAR**)yya, 4); + YYSTYPE YYFAR* yya[3]; + yyinitdebug((void YYFAR**)yya, 3); #endif { -#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" +#line 119 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(STMT_LIST,yyattribute(1 - 2).treenode,new CTreeNode(POP_STMT)); +#line 219 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -225,22 +226,22 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 4); #endif { -#line 118 "C:\\spongebob\\Utils\\scripter\\parser.y" -(*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(2 - 3).treenode; -#line 231 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 124 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(ASSIGN_EXPR,yyattribute(1 - 3).treenode,yyattribute(3 - 3).treenode); +#line 232 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; case 13: { #ifdef YYDEBUG - YYSTYPE YYFAR* yya[2]; - yyinitdebug((void YYFAR**)yya, 2); + YYSTYPE YYFAR* yya[4]; + yyinitdebug((void YYFAR**)yya, 4); #endif { -#line 119 "C:\\spongebob\\Utils\\scripter\\parser.y" -(*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(1 - 1).treenode; -#line 244 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 129 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(2 - 3).treenode; +#line 245 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -251,22 +252,22 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 2); #endif { -#line 120 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 130 "C:\\spongebob\\Utils\\scripter\\parser.y" (*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(1 - 1).treenode; -#line 257 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 258 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; case 15: { #ifdef YYDEBUG - YYSTYPE YYFAR* yya[4]; - yyinitdebug((void YYFAR**)yya, 4); + YYSTYPE YYFAR* yya[2]; + yyinitdebug((void YYFAR**)yya, 2); #endif { -#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" +#line 131 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(1 - 1).treenode; +#line 271 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -277,22 +278,22 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 4); #endif { -#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" +#line 135 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(EQUAL_EXPR,yyattribute(1 - 3).treenode,yyattribute(3 - 3).treenode); +#line 284 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; case 17: { #ifdef YYDEBUG - YYSTYPE YYFAR* yya[2]; - yyinitdebug((void YYFAR**)yya, 2); + YYSTYPE YYFAR* yya[4]; + yyinitdebug((void YYFAR**)yya, 4); #endif { -#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" +#line 139 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(NOTEQUAL_EXPR,yyattribute(1 - 3).treenode,yyattribute(3 - 3).treenode); +#line 297 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -303,9 +304,9 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 2); #endif { -#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" +#line 144 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(VARIABLE_EXPR,yyattribute(1 - 1).variableIdx); +#line 310 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -316,22 +317,74 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; yyinitdebug((void YYFAR**)yya, 2); #endif { -#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" +#line 148 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(VALUE_EXPR,yyattribute(1 - 1).value); +#line 323 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; case 20: { +#ifdef YYDEBUG + YYSTYPE YYFAR* yya[2]; + yyinitdebug((void YYFAR**)yya, 2); +#endif + { +#line 149 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(VARIABLE_EXPR,yyattribute(1 - 1).variableIdx); +#line 336 "C:\\spongebob\\Utils\\scripter\\parser.cpp" + } + } + break; + case 21: + { #ifdef YYDEBUG YYSTYPE YYFAR* yya[4]; yyinitdebug((void YYFAR**)yya, 4); #endif { -#line 139 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 150 "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" +#line 349 "C:\\spongebob\\Utils\\scripter\\parser.cpp" + } + } + break; + case 22: + { +#ifdef YYDEBUG + YYSTYPE YYFAR* yya[2]; + yyinitdebug((void YYFAR**)yya, 2); +#endif + { +#line 151 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=yyattribute(1 - 1).treenode; +#line 362 "C:\\spongebob\\Utils\\scripter\\parser.cpp" + } + } + break; + case 23: + { +#ifdef YYDEBUG + YYSTYPE YYFAR* yya[3]; + yyinitdebug((void YYFAR**)yya, 3); +#endif + { +#line 156 "C:\\spongebob\\Utils\\scripter\\parser.y" +if(yyattribute(1 - 2).functionNumber!=-1){m_functionNumber=yyattribute(1 - 2).functionNumber;m_functionArgs=getFunctionArgs(yyattribute(1 - 2).functionNumber);} +#line 375 "C:\\spongebob\\Utils\\scripter\\parser.cpp" + } + } + break; + case 24: + { +#ifdef YYDEBUG + YYSTYPE YYFAR* yya[5]; + yyinitdebug((void YYFAR**)yya, 5); +#endif + { +#line 157 "C:\\spongebob\\Utils\\scripter\\parser.y" +(*(YYSTYPE YYFAR*)yyvalptr).treenode=new CTreeNode(STMT_LIST,m_functionArgs,new CTreeNode(FUNCTION_EXPR,m_functionNumber)); +#line 388 "C:\\spongebob\\Utils\\scripter\\parser.cpp" } } break; @@ -340,14 +393,14 @@ s_baseTreeNode=yyattribute(1 - 1).treenode; break; } } -#line 144 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 162 "C:\\spongebob\\Utils\\scripter\\parser.y" ///////////////////////////////////////////////////////////////////////////// // programs section -#line 351 "C:\\spongebob\\Utils\\scripter\\parser.cpp" +#line 404 "C:\\spongebob\\Utils\\scripter\\parser.cpp" void YYPARSENAME::yytables() { yyattribute_size = sizeof(YYSTYPE); @@ -371,8 +424,9 @@ void YYPARSENAME::yytables() { "CLOSE_PAR", 268 }, { "BEGIN_CS", 269 }, { "END_CS", 270 }, - { "VARIABLE", 271 }, - { "VALUE", 272 }, + { "VARIABLE", 272 }, + { "VALUE", 273 }, + { "FUNCTION", 274 }, { NULL, 0 } }; yysymbol = symbol; @@ -390,6 +444,7 @@ void YYPARSENAME::yytables() "statement: IF OPEN_PAR expression CLOSE_PAR statement", "statement: IF OPEN_PAR expression CLOSE_PAR statement ELSE statement", "statement: BEGIN_CS statement_list END_CS", + "statement: function END_STMT", "assign_expression: variable ASSIGN value", "expression: OPEN_PAR expression CLOSE_PAR", "expression: equal_expression", @@ -399,7 +454,10 @@ void YYPARSENAME::yytables() "variable: VARIABLE", "value: VALUE", "value: VARIABLE", - "value: value PLUS value" + "value: value PLUS value", + "value: function", + "$$1:", + "function: FUNCTION OPEN_PAR $$1 CLOSE_PAR" }; yyrule = rule; #endif @@ -417,155 +475,179 @@ void YYPARSENAME::yytables() { 3, 5, 8 }, { 3, 7, 9 }, { 3, 3, 10 }, - { 4, 3, 11 }, - { 5, 3, 12 }, - { 5, 1, 13 }, + { 3, 2, 11 }, + { 4, 3, 12 }, + { 5, 3, 13 }, { 5, 1, 14 }, - { 6, 3, 15 }, - { 7, 3, 16 }, - { 8, 1, 17 }, - { 9, 1, 18 }, + { 5, 1, 15 }, + { 6, 3, 16 }, + { 7, 3, 17 }, + { 8, 1, 18 }, { 9, 1, 19 }, - { 9, 3, 20 } + { 9, 1, 20 }, + { 9, 3, 21 }, + { 9, 1, 22 }, + { 11, 0, 23 }, + { 10, 4, 24 } }; yyreduction = reduction; static const yytokenaction_t YYNEARFAR YYBASED_CODE tokenaction[] = { - { 42, YYAT_SHIFT, 3 }, - { 42, YYAT_SHIFT, 4 }, - { 27, YYAT_SHIFT, 34 }, - { 42, YYAT_SHIFT, 5 }, - { 42, YYAT_SHIFT, 6 }, - { 27, YYAT_SHIFT, 35 }, - { 40, YYAT_SHIFT, 34 }, + { 49, YYAT_SHIFT, 3 }, + { 49, YYAT_SHIFT, 4 }, + { 32, YYAT_SHIFT, 40 }, + { 49, YYAT_SHIFT, 5 }, + { 49, YYAT_SHIFT, 6 }, + { 32, YYAT_SHIFT, 41 }, + { 47, YYAT_SHIFT, 40 }, { 2, YYAT_SHIFT, 3 }, { 2, YYAT_SHIFT, 4 }, - { 42, YYAT_SHIFT, 7 }, + { 49, YYAT_SHIFT, 7 }, { 2, YYAT_SHIFT, 5 }, { 2, YYAT_SHIFT, 6 }, - { 42, YYAT_SHIFT, 8 }, - { 39, YYAT_SHIFT, 34 }, - { 42, YYAT_SHIFT, 9 }, - { 38, YYAT_SHIFT, 34 }, + { 49, YYAT_SHIFT, 8 }, + { 30, YYAT_SHIFT, 38 }, + { 30, YYAT_SHIFT, 39 }, + { 49, YYAT_SHIFT, 9 }, { 2, YYAT_SHIFT, 7 }, - { 26, YYAT_SHIFT, 32 }, - { 26, YYAT_SHIFT, 33 }, + { 49, YYAT_SHIFT, 10 }, + { 30, YYAT_ERROR, 0 }, { 2, YYAT_SHIFT, 8 }, - { 37, YYAT_SHIFT, 42 }, + { 46, YYAT_SHIFT, 40 }, + { 45, YYAT_SHIFT, 40 }, { 2, YYAT_SHIFT, 9 }, - { 26, YYAT_ERROR, 0 }, - { 34, YYAT_SHIFT, 21 }, - { 34, YYAT_SHIFT, 22 }, - { 35, YYAT_SHIFT, 41 }, - { 30, YYAT_SHIFT, 36 }, - { 29, YYAT_SHIFT, 34 }, - { 23, YYAT_SHIFT, 31 }, - { 20, YYAT_SHIFT, 20 }, - { 17, YYAT_SHIFT, 28 }, - { 12, YYAT_SHIFT, 19 }, - { 11, YYAT_SHIFT, 18 }, - { 6, YYAT_SHIFT, 16 }, - { 5, YYAT_SHIFT, 15 }, - { 4, YYAT_SHIFT, 14 }, - { 3, YYAT_SHIFT, 13 }, + { 44, YYAT_SHIFT, 49 }, + { 2, YYAT_SHIFT, 10 }, + { 40, YYAT_SHIFT, 25 }, + { 40, YYAT_SHIFT, 26 }, + { 40, YYAT_SHIFT, 10 }, + { 41, YYAT_SHIFT, 48 }, + { 36, YYAT_SHIFT, 43 }, + { 35, YYAT_SHIFT, 40 }, + { 34, YYAT_SHIFT, 42 }, + { 27, YYAT_SHIFT, 37 }, + { 24, YYAT_SHIFT, 24 }, + { 19, YYAT_SHIFT, 33 }, + { 14, YYAT_SHIFT, 23 }, + { 13, YYAT_SHIFT, 22 }, + { 12, YYAT_SHIFT, 21 }, + { 10, YYAT_SHIFT, 20 }, + { 6, YYAT_SHIFT, 18 }, + { 5, YYAT_SHIFT, 17 }, + { 4, YYAT_SHIFT, 16 }, + { 3, YYAT_SHIFT, 15 }, { 1, YYAT_ACCEPT, 0 } }; yytokenaction = tokenaction; - yytokenaction_size = 38; + yytokenaction_size = 44; static const yystateaction_t YYNEARFAR YYBASED_CODE stateaction[] = { { 0, 0, YYAT_REDUCE, 3 }, - { 37, 1, YYAT_ERROR, 0 }, + { 43, 1, YYAT_ERROR, 0 }, { -250, 1, YYAT_REDUCE, 1 }, - { -230, 1, YYAT_DEFAULT, 35 }, - { -232, 1, YYAT_DEFAULT, 6 }, - { -232, 1, YYAT_DEFAULT, 35 }, - { -234, 1, YYAT_ERROR, 0 }, + { -224, 1, YYAT_DEFAULT, 41 }, + { -226, 1, YYAT_DEFAULT, 10 }, + { -226, 1, YYAT_DEFAULT, 41 }, + { -228, 1, YYAT_DEFAULT, 10 }, { 0, 0, YYAT_REDUCE, 4 }, { 0, 0, YYAT_REDUCE, 3 }, - { 0, 0, YYAT_REDUCE, 18 }, - { 0, 0, YYAT_REDUCE, 2 }, - { -234, 1, YYAT_DEFAULT, 35 }, - { -231, 1, YYAT_ERROR, 0 }, - { 0, 0, YYAT_REDUCE, 5 }, - { 0, 0, YYAT_DEFAULT, 20 }, - { 0, 0, YYAT_REDUCE, 6 }, - { 0, 0, YYAT_DEFAULT, 34 }, - { -240, 1, YYAT_DEFAULT, 42 }, - { 0, 0, YYAT_REDUCE, 8 }, - { 0, 0, YYAT_DEFAULT, 34 }, - { -238, 1, YYAT_DEFAULT, 34 }, - { 0, 0, YYAT_REDUCE, 20 }, { 0, 0, YYAT_REDUCE, 19 }, - { -240, 1, YYAT_DEFAULT, 30 }, - { 0, 0, YYAT_REDUCE, 14 }, + { -229, 1, YYAT_ERROR, 0 }, + { 0, 0, YYAT_REDUCE, 2 }, + { -229, 1, YYAT_DEFAULT, 41 }, + { -226, 1, YYAT_ERROR, 0 }, + { -231, 1, YYAT_DEFAULT, 41 }, + { 0, 0, YYAT_REDUCE, 5 }, + { 0, 0, YYAT_DEFAULT, 24 }, + { 0, 0, YYAT_REDUCE, 6 }, + { 0, 0, YYAT_DEFAULT, 40 }, + { -236, 1, YYAT_DEFAULT, 49 }, + { 0, 0, YYAT_REDUCE, 24 }, + { 0, 0, YYAT_REDUCE, 8 }, + { 0, 0, YYAT_DEFAULT, 40 }, + { 0, 0, YYAT_REDUCE, 12 }, + { -234, 1, YYAT_DEFAULT, 40 }, + { 0, 0, YYAT_REDUCE, 21 }, + { 0, 0, YYAT_REDUCE, 20 }, + { -236, 1, YYAT_DEFAULT, 36 }, { 0, 0, YYAT_REDUCE, 15 }, - { -246, 1, YYAT_DEFAULT, 27 }, - { -263, 1, YYAT_DEFAULT, 30 }, + { 0, 0, YYAT_REDUCE, 16 }, + { -250, 1, YYAT_DEFAULT, 32 }, + { 0, 0, YYAT_REDUCE, 23 }, + { -263, 1, YYAT_DEFAULT, 36 }, { 0, 0, YYAT_REDUCE, 11 }, - { -238, 1, YYAT_REDUCE, 12 }, - { -242, 1, YYAT_ERROR, 0 }, - { 0, 0, YYAT_DEFAULT, 42 }, - { 0, 0, YYAT_DEFAULT, 34 }, - { 0, 0, YYAT_DEFAULT, 34 }, - { -248, 1, YYAT_ERROR, 0 }, - { -241, 1, YYAT_ERROR, 0 }, - { 0, 0, YYAT_REDUCE, 13 }, - { -239, 1, YYAT_REDUCE, 9 }, - { -250, 1, YYAT_REDUCE, 16 }, - { -252, 1, YYAT_REDUCE, 17 }, - { -259, 1, YYAT_REDUCE, 21 }, + { -237, 1, YYAT_DEFAULT, 36 }, + { -235, 1, YYAT_REDUCE, 13 }, + { -239, 1, YYAT_ERROR, 0 }, + { 0, 0, YYAT_DEFAULT, 49 }, + { 0, 0, YYAT_DEFAULT, 40 }, + { 0, 0, YYAT_DEFAULT, 40 }, + { -247, 1, YYAT_ERROR, 0 }, + { -238, 1, YYAT_ERROR, 0 }, + { 0, 0, YYAT_REDUCE, 25 }, + { 0, 0, YYAT_REDUCE, 14 }, + { -236, 1, YYAT_REDUCE, 9 }, + { -244, 1, YYAT_REDUCE, 17 }, + { -245, 1, YYAT_REDUCE, 18 }, + { -259, 1, YYAT_REDUCE, 22 }, { 0, 0, YYAT_REDUCE, 7 }, - { -257, 1, YYAT_DEFAULT, 35 }, + { -257, 1, YYAT_DEFAULT, 41 }, { 0, 0, YYAT_REDUCE, 10 } }; yystateaction = stateaction; static const yynontermgoto_t YYNEARFAR YYBASED_CODE nontermgoto[] = { - { 20, 30 }, - { 20, 24 }, - { 20, 25 }, - { 34, 40 }, - { 20, 26 }, - { 42, 43 }, - { 42, 11 }, + { 49, 50 }, + { 49, 12 }, + { 24, 36 }, + { 24, 28 }, + { 24, 29 }, + { 49, 13 }, + { 24, 30 }, + { 49, 14 }, + { 40, 47 }, + { 40, 31 }, { 0, 1 }, { 0, 2 }, - { 33, 39 }, - { 42, 12 }, - { 32, 38 }, - { 31, 37 }, - { 19, 29 }, - { 17, 10 }, + { 39, 46 }, + { 38, 45 }, + { 37, 44 }, + { 22, 35 }, + { 20, 34 }, + { 19, 11 }, + { 18, 32 }, { 16, 27 }, - { 14, 23 }, - { 8, 17 } + { 8, 19 } }; yynontermgoto = nontermgoto; - yynontermgoto_size = 18; + yynontermgoto_size = 21; static const yystategoto_t YYNEARFAR YYBASED_CODE stategoto[] = { - { 6, -1 }, + { 9, -1 }, { 0, -1 }, - { 0, 17 }, + { 0, 19 }, { 0, -1 }, { 0, -1 }, { 0, -1 }, { 0, -1 }, { 0, -1 }, - { 15, -1 }, + { 18, -1 }, { 0, -1 }, { 0, -1 }, { 0, -1 }, { 0, -1 }, { 0, -1 }, - { 11, 20 }, { 0, -1 }, - { 6, -1 }, - { 11, 42 }, { 0, -1 }, - { 4, -1 }, - { -5, -1 }, + { 14, 24 }, + { 0, -1 }, + { 9, 40 }, + { 14, 49 }, + { 5, -1 }, + { 0, -1 }, + { 6, 40 }, + { 0, -1 }, + { -3, 40 }, { 0, -1 }, { 0, -1 }, { 0, -1 }, @@ -576,10 +658,12 @@ void YYPARSENAME::yytables() { 0, -1 }, { 0, -1 }, { 0, -1 }, - { 9, 42 }, - { 2, -1 }, { 0, -1 }, - { -6, -1 }, + { 0, -1 }, + { 11, 49 }, + { 4, 40 }, + { 3, 40 }, + { -1, -1 }, { 0, -1 }, { 0, -1 }, { 0, -1 }, @@ -587,7 +671,8 @@ void YYPARSENAME::yytables() { 0, -1 }, { 0, -1 }, { 0, -1 }, - { 2, -1 }, + { 0, -1 }, + { -3, -1 }, { 0, -1 } }; yystategoto = stategoto; diff --git a/Utils/Scripter/parser.h b/Utils/Scripter/parser.h index 20b9f36ca..e54ddf7bd 100644 --- a/Utils/Scripter/parser.h +++ b/Utils/Scripter/parser.h @@ -19,7 +19,7 @@ protected: #endif public: -#line 22 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 23 "C:\\spongebob\\Utils\\scripter\\parser.y" public: void setCurrentLexer(class mylexer *_lexer); @@ -33,8 +33,12 @@ private: class mylexer *m_currentLexer; class CTreeNode *m_baseNode; + // Ugh! (pkg) + class CTreeNode *m_functionArgs; + int m_functionNumber; -#line 38 "C:\\spongebob\\Utils\\scripter\\parser.h" + +#line 42 "C:\\spongebob\\Utils\\scripter\\parser.h" }; #ifndef YYPARSENAME @@ -43,13 +47,14 @@ private: #ifndef YYSTYPE union tagYYSTYPE { -#line 49 "C:\\spongebob\\Utils\\scripter\\parser.y" +#line 54 "C:\\spongebob\\Utils\\scripter\\parser.y" - int variableIdx; - signed short value; - class CTreeNode *treenode; + int variableIdx; + signed short value; + int functionNumber; + class CTreeNode *treenode; -#line 53 "C:\\spongebob\\Utils\\scripter\\parser.h" +#line 58 "C:\\spongebob\\Utils\\scripter\\parser.h" }; #define YYSTYPE union tagYYSTYPE @@ -69,6 +74,8 @@ union tagYYSTYPE { #define CLOSE_PAR 268 #define BEGIN_CS 269 #define END_CS 270 -#define VARIABLE 271 -#define VALUE 272 +#define COMMA 271 +#define VARIABLE 272 +#define VALUE 273 +#define FUNCTION 274 #endif diff --git a/Utils/Scripter/parser.v b/Utils/Scripter/parser.v index d1e9bc5c8..95f2ce3e3 100644 --- a/Utils/Scripter/parser.v +++ b/Utils/Scripter/parser.v @@ -13,22 +13,28 @@ 9 | IF OPEN_PAR expression CLOSE_PAR statement 10 | IF OPEN_PAR expression CLOSE_PAR statement ELSE statement 11 | BEGIN_CS statement_list END_CS + 12 | function END_STMT - 12 assign_expression : variable ASSIGN value + 13 assign_expression : variable ASSIGN value - 13 expression : OPEN_PAR expression CLOSE_PAR - 14 | equal_expression - 15 | notequal_expression + 14 expression : OPEN_PAR expression CLOSE_PAR + 15 | equal_expression + 16 | notequal_expression - 16 equal_expression : value EQUAL value + 17 equal_expression : value EQUAL value - 17 notequal_expression : value NOTEQUAL value + 18 notequal_expression : value NOTEQUAL value - 18 variable : VARIABLE + 19 variable : VARIABLE - 19 value : VALUE - 20 | VARIABLE - 21 | value PLUS value + 20 value : VALUE + 21 | VARIABLE + 22 | value PLUS value + 23 | function + + 24 $$1 : + + 25 function : FUNCTION OPEN_PAR $$1 CLOSE_PAR state 0 @@ -58,36 +64,38 @@ state 2 END_STMT shift 7 BEGIN_CS shift 8 VARIABLE shift 9 + FUNCTION shift 10 . reduce 1 - statement goto 10 - assign_expression goto 11 - variable goto 12 + statement goto 11 + assign_expression goto 12 + variable goto 13 + function goto 14 state 3 statement : STOP . END_STMT - END_STMT shift 13 + END_STMT shift 15 state 4 statement : IF . OPEN_PAR expression CLOSE_PAR statement statement : IF . OPEN_PAR expression CLOSE_PAR statement ELSE statement - OPEN_PAR shift 14 + OPEN_PAR shift 16 state 5 statement : PAUSE . END_STMT - END_STMT shift 15 + END_STMT shift 17 state 6 statement : PRINT . OPEN_PAR value CLOSE_PAR END_STMT - OPEN_PAR shift 16 + OPEN_PAR shift 18 state 7 @@ -102,69 +110,85 @@ state 8 . reduce 3 - statement_list goto 17 + statement_list goto 19 state 9 - variable : VARIABLE . (18) + variable : VARIABLE . (19) - . reduce 18 + . reduce 19 state 10 + function : FUNCTION . OPEN_PAR $$1 CLOSE_PAR + + OPEN_PAR shift 20 + + +state 11 statement_list : statement_list statement . (2) . reduce 2 -state 11 +state 12 statement : assign_expression . END_STMT - END_STMT shift 18 - - -state 12 - assign_expression : variable . ASSIGN value - - ASSIGN shift 19 + END_STMT shift 21 state 13 + assign_expression : variable . ASSIGN value + + ASSIGN shift 22 + + +state 14 + statement : function . END_STMT + + END_STMT shift 23 + + +state 15 statement : STOP END_STMT . (5) . reduce 5 -state 14 +state 16 statement : IF OPEN_PAR . expression CLOSE_PAR statement statement : IF OPEN_PAR . expression CLOSE_PAR statement ELSE statement - OPEN_PAR shift 20 - VARIABLE shift 21 - VALUE shift 22 + OPEN_PAR shift 24 + VARIABLE shift 25 + VALUE shift 26 + FUNCTION shift 10 - expression goto 23 - equal_expression goto 24 - notequal_expression goto 25 - value goto 26 + expression goto 27 + equal_expression goto 28 + notequal_expression goto 29 + value goto 30 + function goto 31 -state 15 +state 17 statement : PAUSE END_STMT . (6) . reduce 6 -state 16 +state 18 statement : PRINT OPEN_PAR . value CLOSE_PAR END_STMT - VARIABLE shift 21 - VALUE shift 22 + VARIABLE shift 25 + VALUE shift 26 + FUNCTION shift 10 - value goto 27 + value goto 32 + function goto 31 -state 17 +state 19 statement_list : statement_list . statement statement : BEGIN_CS statement_list . END_CS @@ -174,112 +198,145 @@ state 17 PRINT shift 6 END_STMT shift 7 BEGIN_CS shift 8 - END_CS shift 28 + END_CS shift 33 VARIABLE shift 9 + FUNCTION shift 10 - statement goto 10 - assign_expression goto 11 - variable goto 12 + statement goto 11 + assign_expression goto 12 + variable goto 13 + function goto 14 -state 18 +state 20 + function : FUNCTION OPEN_PAR . $$1 CLOSE_PAR + $$1 : . (24) + + . reduce 24 + + $$1 goto 34 + + +state 21 statement : assign_expression END_STMT . (8) . reduce 8 -state 19 +state 22 assign_expression : variable ASSIGN . value - VARIABLE shift 21 - VALUE shift 22 + VARIABLE shift 25 + VALUE shift 26 + FUNCTION shift 10 - value goto 29 + value goto 35 + function goto 31 -state 20 +state 23 + statement : function END_STMT . (12) + + . reduce 12 + + +state 24 expression : OPEN_PAR . expression CLOSE_PAR - OPEN_PAR shift 20 - VARIABLE shift 21 - VALUE shift 22 + OPEN_PAR shift 24 + VARIABLE shift 25 + VALUE shift 26 + FUNCTION shift 10 - expression goto 30 - equal_expression goto 24 - notequal_expression goto 25 - value goto 26 + expression goto 36 + equal_expression goto 28 + notequal_expression goto 29 + value goto 30 + function goto 31 -state 21 - value : VARIABLE . (20) +state 25 + value : VARIABLE . (21) + + . reduce 21 + + +state 26 + value : VALUE . (20) . reduce 20 -state 22 - value : VALUE . (19) - - . reduce 19 - - -state 23 +state 27 statement : IF OPEN_PAR expression . CLOSE_PAR statement statement : IF OPEN_PAR expression . CLOSE_PAR statement ELSE statement - CLOSE_PAR shift 31 + CLOSE_PAR shift 37 -state 24 - expression : equal_expression . (14) - - . reduce 14 - - -state 25 - expression : notequal_expression . (15) +state 28 + expression : equal_expression . (15) . reduce 15 -state 26 +state 29 + expression : notequal_expression . (16) + + . reduce 16 + + +state 30 equal_expression : value . EQUAL value notequal_expression : value . NOTEQUAL value value : value . PLUS value - EQUAL shift 32 - NOTEQUAL shift 33 - PLUS shift 34 + EQUAL shift 38 + NOTEQUAL shift 39 + PLUS shift 40 -state 27 +state 31 + value : function . (23) + + . reduce 23 + + +state 32 statement : PRINT OPEN_PAR value . CLOSE_PAR END_STMT value : value . PLUS value - PLUS shift 34 - CLOSE_PAR shift 35 + PLUS shift 40 + CLOSE_PAR shift 41 -state 28 +state 33 statement : BEGIN_CS statement_list END_CS . (11) . reduce 11 -state 29 - assign_expression : variable ASSIGN value . (12) +state 34 + function : FUNCTION OPEN_PAR $$1 . CLOSE_PAR + + CLOSE_PAR shift 42 + + +state 35 + assign_expression : variable ASSIGN value . (13) value : value . PLUS value - PLUS shift 34 - . reduce 12 + PLUS shift 40 + . reduce 13 -state 30 +state 36 expression : OPEN_PAR expression . CLOSE_PAR - CLOSE_PAR shift 36 + CLOSE_PAR shift 43 -state 31 +state 37 statement : IF OPEN_PAR expression CLOSE_PAR . statement statement : IF OPEN_PAR expression CLOSE_PAR . statement ELSE statement @@ -290,92 +347,106 @@ state 31 END_STMT shift 7 BEGIN_CS shift 8 VARIABLE shift 9 + FUNCTION shift 10 - statement goto 37 - assign_expression goto 11 - variable goto 12 - - -state 32 - equal_expression : value EQUAL . value - - VARIABLE shift 21 - VALUE shift 22 - - value goto 38 - - -state 33 - notequal_expression : value NOTEQUAL . value - - VARIABLE shift 21 - VALUE shift 22 - - value goto 39 - - -state 34 - value : value PLUS . value - - VARIABLE shift 21 - VALUE shift 22 - - value goto 40 - - -state 35 - statement : PRINT OPEN_PAR value CLOSE_PAR . END_STMT - - END_STMT shift 41 - - -state 36 - expression : OPEN_PAR expression CLOSE_PAR . (13) - - . reduce 13 - - -37: shift-reduce conflict (shift 42, reduce 9) on ELSE -state 37 - statement : IF OPEN_PAR expression CLOSE_PAR statement . (9) - statement : IF OPEN_PAR expression CLOSE_PAR statement . ELSE statement - - ELSE shift 42 - . reduce 9 + statement goto 44 + assign_expression goto 12 + variable goto 13 + function goto 14 state 38 - equal_expression : value EQUAL value . (16) - value : value . PLUS value + equal_expression : value EQUAL . value - PLUS shift 34 - . reduce 16 + VARIABLE shift 25 + VALUE shift 26 + FUNCTION shift 10 + + value goto 45 + function goto 31 state 39 - notequal_expression : value NOTEQUAL value . (17) - value : value . PLUS value + notequal_expression : value NOTEQUAL . value - PLUS shift 34 - . reduce 17 + VARIABLE shift 25 + VALUE shift 26 + FUNCTION shift 10 + + value goto 46 + function goto 31 -40: shift-reduce conflict (shift 34, reduce 21) on PLUS state 40 - value : value PLUS value . (21) - value : value . PLUS value + value : value PLUS . value - PLUS shift 34 - . reduce 21 + VARIABLE shift 25 + VALUE shift 26 + FUNCTION shift 10 + + value goto 47 + function goto 31 state 41 + statement : PRINT OPEN_PAR value CLOSE_PAR . END_STMT + + END_STMT shift 48 + + +state 42 + function : FUNCTION OPEN_PAR $$1 CLOSE_PAR . (25) + + . reduce 25 + + +state 43 + expression : OPEN_PAR expression CLOSE_PAR . (14) + + . reduce 14 + + +44: shift-reduce conflict (shift 49, reduce 9) on ELSE +state 44 + statement : IF OPEN_PAR expression CLOSE_PAR statement . (9) + statement : IF OPEN_PAR expression CLOSE_PAR statement . ELSE statement + + ELSE shift 49 + . reduce 9 + + +state 45 + equal_expression : value EQUAL value . (17) + value : value . PLUS value + + PLUS shift 40 + . reduce 17 + + +state 46 + notequal_expression : value NOTEQUAL value . (18) + value : value . PLUS value + + PLUS shift 40 + . reduce 18 + + +47: shift-reduce conflict (shift 40, reduce 22) on PLUS +state 47 + value : value PLUS value . (22) + value : value . PLUS value + + PLUS shift 40 + . reduce 22 + + +state 48 statement : PRINT OPEN_PAR value CLOSE_PAR END_STMT . (7) . reduce 7 -state 42 +state 49 statement : IF OPEN_PAR expression CLOSE_PAR statement ELSE . statement STOP shift 3 @@ -385,21 +456,23 @@ state 42 END_STMT shift 7 BEGIN_CS shift 8 VARIABLE shift 9 + FUNCTION shift 10 - statement goto 43 - assign_expression goto 11 - variable goto 12 + statement goto 50 + assign_expression goto 12 + variable goto 13 + function goto 14 -state 43 +state 50 statement : IF OPEN_PAR expression CLOSE_PAR statement ELSE statement . (10) . reduce 10 -State 37 contains 1 shift-reduce conflict -State 40 contains 1 shift-reduce conflict +State 44 contains 1 shift-reduce conflict +State 47 contains 1 shift-reduce conflict -18 tokens, 10 nonterminals -22 grammar rules, 44 states +19 tokens, 12 nonterminals +26 grammar rules, 51 states diff --git a/Utils/Scripter/parser.y b/Utils/Scripter/parser.y index a56339f81..95d327029 100644 --- a/Utils/Scripter/parser.y +++ b/Utils/Scripter/parser.y @@ -6,6 +6,7 @@ ParserWizard generated YACC file. Date: 07 December 2000 ****************************************************************************/ +#include "function.h" #include "lexer.h" #include "codegen.h" @@ -32,6 +33,10 @@ private: class mylexer *m_currentLexer; class CTreeNode *m_baseNode; + // Ugh! (pkg) + class CTreeNode *m_functionArgs; + int m_functionNumber; + } // constructor @@ -47,9 +52,10 @@ private: //} %union { - int variableIdx; - signed short value; - class CTreeNode *treenode; + int variableIdx; + signed short value; + int functionNumber; + class CTreeNode *treenode; } @@ -71,14 +77,18 @@ private: %token CLOSE_PAR %token BEGIN_CS %token END_CS -%token VARIABLE -%token VALUE +%token COMMA +%token VARIABLE +%token VALUE +%token FUNCTION + %type program statement_list statement %type assign_expression %type expression equal_expression notequal_expression %type variable %type value +%type function %% @@ -106,6 +116,7 @@ statement |IF OPEN_PAR expression CLOSE_PAR statement {$$=new CTreeNode(IF_STMT,$3,$5);} |IF OPEN_PAR expression CLOSE_PAR statement ELSE statement {$$=new CTreeNode(IFELSE_STMT,$3,$5,$7);} |BEGIN_CS statement_list END_CS {$$=new CTreeNode(STMT_LIST,$2);} + |function END_STMT {$$=new CTreeNode(STMT_LIST,$1,new CTreeNode(POP_STMT));} ; @@ -137,9 +148,16 @@ value :VALUE {$$=new CTreeNode(VALUE_EXPR,$1);} |VARIABLE {$$=new CTreeNode(VARIABLE_EXPR,$1);} // variable value |value PLUS value {$$=new CTreeNode(PLUS_EXPR,$1,$3);} + |function {$$=$1;} ; +function + :FUNCTION OPEN_PAR {if($1!=-1){m_functionNumber=$1;m_functionArgs=getFunctionArgs($1);}} + CLOSE_PAR {$$=new CTreeNode(STMT_LIST,m_functionArgs,new CTreeNode(FUNCTION_EXPR,m_functionNumber));} + ; + + %% diff --git a/Utils/Scripter/scripter.dsp b/Utils/Scripter/scripter.dsp index da5894317..cbdbfe3e5 100644 --- a/Utils/Scripter/scripter.dsp +++ b/Utils/Scripter/scripter.dsp @@ -132,6 +132,14 @@ SOURCE=.\codegen.h # End Source File # Begin Source File +SOURCE=.\function.cpp +# End Source File +# Begin Source File + +SOURCE=.\function.h +# End Source File +# Begin Source File + SOURCE=.\main.cpp # End Source File # Begin Source File diff --git a/data/Scripts/test.scr b/data/Scripts/test.scr index 6ba2803e4..62587eea4 100644 --- a/data/Scripts/test.scr +++ b/data/Scripts/test.scr @@ -1,37 +1,10 @@ -// Crappy test program -// Prints a number based upon another one ( eh? ) - -//#print something.. #include data/scripts/defs.scr - -// No switch statements here.. -if($tmp1==ONE) -{ - $tmp2=11; -} -else if($tmp1==TWO) -{ - $tmp2=22; -} -else if($tmp1==THREE) -{ - $tmp2=30+3; -} -else if($tmp1==FOUR) -{ - // Stop here! - stop; -} - -// Have a rest.. -pause; - -// Show result and stop -if($tmp2!=0) - print($tmp2); -else - print(5432); -stop; - +//$tmp1=11; +//$tmp2=22; +//$tmp3=_setCharacterExpression(1,2); +//$tmp3=_setCharacterExpression($tmp1,$tmp2); +print($tmp3); +$tmp3=_setText(123); +stop; \ No newline at end of file diff --git a/makefile.gaz b/makefile.gaz index 5e37edf82..90b233228 100644 --- a/makefile.gaz +++ b/makefile.gaz @@ -97,7 +97,8 @@ pad_src := pads paul_src := paul -script_src := script +script_src := script \ + function sound_src := sound \ spu \ diff --git a/source/script/function.cpp b/source/script/function.cpp index 27e3f4fa2..ff05abe99 100644 --- a/source/script/function.cpp +++ b/source/script/function.cpp @@ -39,7 +39,7 @@ typedef struct { - signed short (*m_func)(signed short *_args); + signed short (*m_func)(unsigned short *_args); int m_argCount; } FunctionDef; @@ -48,14 +48,20 @@ typedef struct Function Prototypes ------------------- */ +static signed short func_setCharacterExpression(unsigned short *_args); +static signed short func_setText(unsigned short *_args); + + /*---------------------------------------------------------------------- Vars ---- */ static FunctionDef s_functionDefs[]= { + { func_setCharacterExpression, 2 }, // character, expression + { func_setText, 1 }, // textId }; -static int s_numFunctionDefs=sizeof(s_functionDefs)/sizeof(FunctionDef); +static const int s_numFunctionDefs=sizeof(s_functionDefs)/sizeof(FunctionDef); /*---------------------------------------------------------------------- @@ -64,6 +70,42 @@ static int s_numFunctionDefs=sizeof(s_functionDefs)/sizeof(FunctionDef); Params: Returns: ---------------------------------------------------------------------- */ +signed short callFunction(int _functionNumber,int _argCount,unsigned short *_args) +{ + FunctionDef *fd; + + ASSERT(_functionNumberm_argCount); + return fd->m_func(_args); +} + + + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +static signed short func_setCharacterExpression(unsigned short *_args) +{ + return _args[0]; +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +static signed short func_setText(unsigned short *_args) +{ + return _args[0]; +} + /*=========================================================================== end */ diff --git a/source/script/function.h b/source/script/function.h index 700fb2375..e6c6bdc76 100644 --- a/source/script/function.h +++ b/source/script/function.h @@ -37,6 +37,9 @@ Functions --------- */ +signed short callFunction(int _functionNumber,int _argCount,unsigned short *_args); + + /*---------------------------------------------------------------------- */ #endif /* __SCRIPT_FUNCTION_H__ */ diff --git a/source/script/script.cpp b/source/script/script.cpp index 28291d0d2..f288493e2 100644 --- a/source/script/script.cpp +++ b/source/script/script.cpp @@ -18,6 +18,10 @@ #include "script\script.h" +#ifndef __SCRIPT_FUNCTION_H__ +#include "script\function.h" +#endif + #ifndef __SYSTEM_DBG_H__ #include "system\dbg.h" #endif @@ -59,6 +63,10 @@ signed short CScript::s_globalVars[NUM_GLOBAL_VARS]= }; +// Buffer for passing arguments to functions +unsigned short CScript::s_argBuffer[MAX_FUNCTION_ARGS]; + + /*---------------------------------------------------------------------- Function: Purpose: @@ -149,6 +157,7 @@ void CScript::executeNextInstruction() { unsigned short instruction; signed short val1,val2,val3; + int i; #ifdef FULL_CODE_OUTPUT PAUL_DBGMSG("pc:0x%04d sp:%03d",m_pc*2,m_sp); @@ -199,7 +208,14 @@ PAUL_DBGMSG("pc:0x%04d sp:%03d",m_pc*2,m_sp); push(val2); break; - case OP_JMP: // jump + case OP_POP: // value + val1=pop(); +#ifdef FULL_CODE_OUTPUT + PAUL_DBGMSG("POP %d",val1); +#endif + break; + + case OP_JMP: // jump val1=pop(); #ifdef FULL_CODE_OUTPUT PAUL_DBGMSG("JMP %d",val1); @@ -207,7 +223,7 @@ PAUL_DBGMSG("pc:0x%04d sp:%03d",m_pc*2,m_sp); jump(val1); break; - case OP_JMPF: // jump, value + case OP_JMPF: // jump, value val1=pop(); val2=pop(); #ifdef FULL_CODE_OUTPUT @@ -216,7 +232,7 @@ PAUL_DBGMSG("pc:0x%04d sp:%03d",m_pc*2,m_sp); if(val2==0)jump(val1); break; - case OP_JMPT: // jump, value + case OP_JMPT: // jump, value val1=pop(); val2=pop(); #ifdef FULL_CODE_OUTPUT @@ -225,7 +241,7 @@ PAUL_DBGMSG("pc:0x%04d sp:%03d",m_pc*2,m_sp); if(val2!=0)jump(val1); break; - case OP_IS_EQUAL_VALUE: // value, value pushes result ( 0 or 1 ) to stack + case OP_IS_EQUAL_VALUE: // value, value pushes result ( 0 or 1 ) to stack val1=pop(); val2=pop(); #ifdef FULL_CODE_OUTPUT @@ -234,7 +250,7 @@ PAUL_DBGMSG("pc:0x%04d sp:%03d",m_pc*2,m_sp); push(val1==val2); break; - case OP_IS_NOTEQUAL_VALUE: // value, value pushes result ( 0 or 1 ) to stack + case OP_IS_NOTEQUAL_VALUE: // value, value pushes result ( 0 or 1 ) to stack val1=pop(); val2=pop(); #ifdef FULL_CODE_OUTPUT @@ -243,7 +259,7 @@ PAUL_DBGMSG("pc:0x%04d sp:%03d",m_pc*2,m_sp); push(val1!=val2); break; - case OP_ASSIGN: // varidx, value + case OP_ASSIGN: // varidx, value val1=pop(); val2=pop(); #ifdef FULL_CODE_OUTPUT @@ -252,7 +268,7 @@ PAUL_DBGMSG("pc:0x%04d sp:%03d",m_pc*2,m_sp); setVar(val1,val2); break; - case OP_ADD: // value, value pushes result to stack + case OP_ADD: // value, value pushes result to stack val1=pop(); val2=pop(); #ifdef FULL_CODE_OUTPUT @@ -261,11 +277,29 @@ PAUL_DBGMSG("pc:0x%04d sp:%03d",m_pc*2,m_sp); push(val1+val2); break; - case OP_PRINT: // value + case OP_PRINT: // value val1=pop(); PAUL_DBGMSG("PRINT %d",val1); break; + case OP_CALL_FUNCTION: // functionnumber, argcount args pushes return value to stack + val1=readNextInstruction(); + val2=readNextInstruction(); +#ifdef FULL_CODE_OUTPUT + PAUL_DBGMSG("CALL_FUNCTION %d ( %d args )",val1,val2); +#endif + ASSERT(val2