diff --git a/Utils/Scripter/function.cpp b/Utils/Scripter/function.cpp new file mode 100644 index 000000000..5a0073f9e --- /dev/null +++ b/Utils/Scripter/function.cpp @@ -0,0 +1,146 @@ +/*========================================================================= + + function.cpp + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2000 Climax Development Ltd + +===========================================================================*/ + + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "function.h" + +#ifndef _LEXER_H +#include "lexer.h" +#endif + +#ifndef _PARSER_H +#include "parser.h" +#endif + + +/* Std Lib + ------- */ + +#include +#include + + +/* Data + ---- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ +static FunctionDef s_functionNames[]= +{ + { 0, "print", 1, }, +}; +static int s_functionCount=sizeof(s_functionNames)/sizeof(FunctionDef); + +extern mylexer s_lexer; +extern myparser s_parser; + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +extern FunctionDef *lookupFunctionName(char *_name) +{ + int i; + FunctionDef *fp; + + fp=s_functionNames; + for(i=0;im_name,_name)==0) + { + return fp; + } + fp++; + } + + printf("Unknown function name _%s\n",_name); + s_lexer.error(); + return NULL; +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: Argument count for the requestion function + ---------------------------------------------------------------------- */ +extern int getFunctionArgCount(int _functionNumber) +{ + return s_functionNames[_functionNumber].m_argCount; +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: A treenode that contains all of the functions arguments + ---------------------------------------------------------------------- */ +extern CTreeNode *getFunctionArgs(int _argCount) +{ + int i; + int tokenType; + + if(_argCount) + { + CTreeNode *base; + +// base=new CTreeNode(STMT_LIST + for(i=0;i<_argCount;i++) + { + tokenType=s_parser.yygettoken(); + switch(tokenType) + { + case VARIABLE: + break; + case VALUE: + break; + default: + printf("UNEXPECTED TOKEN '%s' FOR ARGUMENT %d\n",s_lexer.yytext,i+1); + s_lexer.error(); + break; + } + } + + return new CTreeNode(EMPTY_STMT); + } + else + { + return new CTreeNode(EMPTY_STMT); + } +} + + +/*=========================================================================== + end */ diff --git a/Utils/Scripter/function.h b/Utils/Scripter/function.h new file mode 100644 index 000000000..915a2e6ef --- /dev/null +++ b/Utils/Scripter/function.h @@ -0,0 +1,65 @@ +/*========================================================================= + + function.h + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2000 Climax Development Ltd + +===========================================================================*/ + +#ifndef __FUNCTION_H__ +#define __FUNCTION_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#ifndef __CODEGEN_H__ +#include "codegen.h" +#endif + + +/* Std Lib + ------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +struct FunctionDef +{ + int m_functionNumber; + char *m_name; + int m_argCount; +}; + + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/*---------------------------------------------------------------------- + Functions + --------- */ + +extern FunctionDef *lookupFunctionName(char *_name); + +extern int getFunctionArgCount(int _functionNumber); + +extern CTreeNode *getFunctionArgs(int _argCount); + + +/*---------------------------------------------------------------------- */ + +#endif /* __FUNCTION_H__ */ + +/*=========================================================================== + end */