Go to the
documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #pragma once
00015
00016 #include "maxheap.h"
00017 #include "export.h"
00018 #include "strclass.h"
00019 #include "Point3.h"
00020 #include "TabTypes.h"
00021
00024 #define SCALAR_EXPR 1 //!< A single floating point value.
00025
00027 #define VECTOR_EXPR 3 //!< An array of floating point values.
00028
00029
00033 #define SCALAR_VAR SCALAR_EXPR //!< A single floating point value.
00034
00038 #define VECTOR_VAR VECTOR_EXPR //!< A Point3 value when passed to the eval() method.
00039
00040
00041 class Expr;
00042
00043 typedef int (*ExprFunc)(Expr *e, float f);
00044
00045 class DllExport Inst: public MaxHeapOperators {
00046 public:
00047 ExprFunc func;
00048 float sVal;
00049 };
00050
00051 class ExprVar : public MaxHeapOperators {
00052 public:
00053 MSTR name;
00054 int type;
00055 int regNum;
00056 };
00057
00058
00059 typedef Tab<Inst> InstTab;
00060 typedef Tab<ExprVar> ExprVarTab;
00061
00332 class Expr: public MaxHeapOperators {
00333 public:
00336 Expr() { sValStk = vValStk = instStk = nextScalar = nextVector = 0; }
00338 ~Expr() { deleteAllVars(); }
00339
00348 DllExport int load(MCHAR *s);
00366 DllExport int eval(float *ans, int sRegCt, float *sRegs, int vRegCt=0, Point3 *vRegs=NULL);
00368 int getExprType(void) { return exprType; }
00371 MCHAR * getExprStr(void) { return origStr; }
00375 MCHAR * getProgressStr(void){ return progressStr; }
00385 DllExport int defVar(int type, MCHAR *name);
00393 DllExport int getVarCount(int type);
00401 DllExport MCHAR * getVarName(int type, int i);
00427 DllExport int getVarRegNum(int type, int i);
00431 DllExport BOOL deleteAllVars();
00442 DllExport BOOL deleteVar(MCHAR *name);
00443
00444
00445 void setExprType(int type) { exprType = type; }
00446 void pushInst(ExprFunc fn, float f)
00447 { if(instStk >= inst.Count()) inst.SetCount(instStk+30);
00448 inst[instStk].func = fn; inst[instStk++].sVal = f; }
00449 void pushSVal(float f) { if(sValStk>=sVal.Count())sVal.SetCount(sValStk+10);sVal[sValStk++]=f; }
00450 float popSVal() { return sVal[--sValStk]; }
00451 void pushVVal(Point3 &v) { if(vValStk>=vVal.Count())vVal.SetCount(vValStk+10);vVal[vValStk++]=v; }
00452 Point3 & popVVal() { return vVal[--vValStk]; }
00453 int getSRegCt(void) { return sRegCt; }
00454 float getSReg(int index) { return sRegPtr[index]; }
00455 int getVRegCt(void) { return vRegCt; }
00456 Point3 & getVReg(int index) { return vRegPtr[index]; }
00457
00458 ExprVarTab vars;
00459 private:
00460 MCHAR * exprPtr;
00461 MCHAR * exprStr;
00462 MSTR origStr;
00463 MSTR progressStr;
00464 int sRegCt;
00465 float *sRegPtr;
00466 int vRegCt;
00467 Point3 *vRegPtr;
00468 int exprType;
00469
00470 int sValStk;
00471 floatTab sVal;
00472 int vValStk;
00473 Point3Tab vVal;
00474 int instStk;
00475 InstTab inst;
00476
00477 int nextScalar;
00478 int nextVector;
00479
00480 friend int yylex();
00481 friend int yyerror(char *);
00482 };
00483
00486 #define EXPR_NORMAL 0 //!< No problems, expression evaluated successfully.
00487 #define EXPR_INST_OVERFLOW -1 //!< Instruction stack overflow during parsing.
00488 #define EXPR_UNKNOWN_TOKEN -2 //!< Unknown function, const, or reg during parsing.
00489 #define EXPR_TOO_MANY_VARS -3 //!< Value stack overflow.
00490 #define EXPR_TOO_MANY_REGS -4 //!< Register array overflow, or reg number too big.
00491 #define EXPR_CANT_EVAL -5 //!< Function can't be evaluated with given arguments.
00492 #define EXPR_CANT_PARSE -6 //!< Expression can't be parsed syntactically.
00493
00494