diff --git a/yab2cpp.h b/yab2cpp.h index 5dc01a4..d482d0f 100644 --- a/yab2cpp.h +++ b/yab2cpp.h @@ -40,7 +40,12 @@ enum COMPILE_ERRORS { E_BAD_ALLOC, E_STACK_UNDERFLOW, E_INTERNAL, - E_DUPLICATE_SYMBOL + E_DUPLICATE_SYMBOL, + E_END_FUNCTION, + E_GOSUB_CANNOT_RETURN_VALUE, + E_SUBROUTINE_NOT_FOUND, + E_TOO_MANY_PARAMETERS, + E_UNASSIGNABLE_TYPE }; extern enum COMPILE_ERRORS errorLevel; @@ -56,11 +61,14 @@ const char *COMPILE_ERROR_NAMES[]={ "failed allocation", "stack underflow", "internal compiler error", - "duplicated label" + "duplicated label", + "previous subroutine didn't end", + "value returned from gosub call", + "undefined subroutine name", + "too many parameters in function call", + "value cannot be assigned" }; -extern enum COMPILEERRORS errorLevel; - /* flags used internally by the compiler (must be powers of 2) */ #define COMPILE 1 @@ -70,7 +78,8 @@ extern enum COMPILEERRORS errorLevel; /* list of all variable and constant types */ enum TYPES { - T_NONE=0, + T_UNKNOWN=0, + T_NONE, T_STRING, T_INT, T_FLOAT, @@ -80,6 +89,7 @@ enum TYPES T_INTCALL_ARRAY, T_FLOATCALL_ARRAY, T_STRINGCALL_ARRAY, + T_VOIDCALL } /* list of all kinds of other code structures */ enum CODES @@ -97,11 +107,17 @@ enum CODES T_ASSIGNMENT, T_LABEL, T_PARAMLIST, - T_DATAITEM + T_DATAITEM, + T_STRINGFUNC, + T_FLOATFUNC, + T_INTFUNC, + T_VOIDFUNC, + T_UNKNOWNFUNC }; /* These correspond to the types of enum TYPES. */ const string TYPENAMES[]={ + "unknown", "none", "string constant", "integer constant", @@ -111,7 +127,9 @@ const string TYPENAMES[]={ "floating point variable", "string array or function", "integer array or function", - "floating point array or function" + "floating point array or function", + "string array or function", + "function" }; const string CODETYPES[]={ @@ -127,7 +145,12 @@ const string CODETYPES[]={ "assignment", "label", "parameter list or array index", - "data item" + "data item", + "function returning string", + "function returning floating point", + "function returning integer", + "function returning nothing", + "function" }; typedef union @@ -165,25 +188,30 @@ enum OPERATORS O_OR, O_AND, O_STRING_CONCAT, + O_INT_TO_FLOAT, O_TERM }; +/* global prototype */ +void error(enum COMPILE_ERRORS err); + /* internal states used by the parser */ class operands { enum TYPES type; unsigned int id; static unsigned int nextID; - static unordered_map globals; - static unordered_map strConst; + static unordered_map globals; + static unordered_map strConst; public: enum TYPES getType() const {return type;} unsigned int getID() const {return id;} + static operands *findGlobal(string &s); static void dumpVars(ostream &out); - static unsigned int getOrCreateStr(ostream &k, string &s); - static operands *createConst(ostream &k, string &s, enum TYPES t); - static operands *getOrCreateGlobal(ostream &heap, string &s, enum TYPES t); + static unsigned int getOrCreateStr(string &s); + static operands *createConst(string &s, enum TYPES t); + static operands *getOrCreateGlobal(string &s, enum TYPES t); enum TYPES getSimpleVarType(); void generateBox(ostream &scope); @@ -223,19 +251,17 @@ public: op=x; oper=O_TERM; } + /*TODO: Recycle temporary variables when not in debug mode*/ virtual ~expression(); }; /* parent class of all code types */ class codeType { - unsigned int id; enum CODES type; - static unsigned int nextID; static list nesting; public: enum CODES getType() const {return this->type;} - unsigned int getID() const {return this->id;} static codeType *getCurrent(); @@ -258,7 +284,7 @@ public: unsigned int getID() const {return id;} void generateJumpTo(); - void generateOnNSkip(ostream &k, list