11 #ifndef ONCE_FPARSER_H_
12 #define ONCE_FPARSER_H_
17 #ifdef FUNCTIONPARSER_SUPPORT_DEBUGGING
24 #pragma warning(disable : 4661)
27 namespace FPoptimizer_CodeTree {
template<
typename Value_t>
class CodeTree; }
29 template<
typename Value_t>
35 SYNTAX_ERROR=0, MISM_PARENTH, MISSING_PARENTH, EMPTY_PARENTH,
36 EXPECT_OPERATOR, OUT_OF_MEMORY, UNEXPECTED_ERROR, INVALID_VARS,
37 ILL_PARAMS_AMOUNT, PREMATURE_EOS, EXPECT_PARENTH_FUNC,
39 NO_FUNCTION_PARSED_YET,
43 typedef Value_t value_type;
46 int Parse(
const char* Function,
const std::string& Vars,
47 bool useDegrees =
false);
48 int Parse(
const std::string& Function,
const std::string& Vars,
49 bool useDegrees =
false);
51 void setDelimiterChar(
char);
53 const char* ErrorMsg()
const;
54 ParseErrorType GetParseErrorType()
const;
56 Value_t Eval(
const Value_t* Vars);
57 int EvalError()
const;
59 bool AddConstant(
const std::string& name, Value_t value);
60 bool AddUnit(
const std::string& name, Value_t value);
62 typedef Value_t (*FunctionPtr)(
const Value_t*);
64 bool AddFunction(
const std::string& name,
65 FunctionPtr,
unsigned paramsAmount);
70 template<
typename DerivedWrapper>
71 bool AddFunctionWrapper(
const std::string& name,
const DerivedWrapper&,
72 unsigned paramsAmount);
76 bool RemoveIdentifier(
const std::string& name);
81 int ParseAndDeduceVariables(
const std::string&
function,
82 int* amountOfVariablesFound = 0,
83 bool useDegrees =
false);
84 int ParseAndDeduceVariables(
const std::string&
function,
85 std::string& resultVarString,
86 int* amountOfVariablesFound = 0,
87 bool useDegrees =
false);
88 int ParseAndDeduceVariables(
const std::string&
function,
89 std::vector<std::string>& resultVars,
90 bool useDegrees =
false);
102 void ForceDeepCopy();
106 #ifdef FUNCTIONPARSER_SUPPORT_DEBUGGING
110 void InjectRawByteCode(
const unsigned* bytecode,
unsigned bytecodeAmount,
111 const Value_t* immed,
unsigned immedAmount,
114 void PrintByteCode(std::ostream& dest,
bool showExpression =
true)
const;
125 Data* getParserData();
144 bool NameExists(
const char*,
unsigned);
145 bool ParseVariables(
const std::string&);
146 int ParseFunction(
const char*,
bool);
147 const char* SetErrorType(ParseErrorType,
const char*);
149 void AddFunctionOpcode(
unsigned);
150 void AddImmedOpcode(Value_t v);
152 void CompilePowi(
long);
153 bool TryCompilePowi(Value_t);
155 const char* CompileIf(
const char*);
156 const char* CompileFunctionParams(
const char*,
unsigned);
157 const char* CompileElement(
const char*);
158 const char* CompilePossibleUnit(
const char*);
159 const char* CompilePow(
const char*);
160 const char* CompileUnaryMinus(
const char*);
161 const char* CompileMult(
const char*);
162 const char* CompileAddition(
const char*);
163 const char* CompileComparison(
const char*);
164 const char* CompileAnd(
const char*);
165 const char* CompileExpression(
const char*);
166 inline const char* CompileFunction(
const char*,
unsigned);
167 inline const char* CompileParenthesis(
const char*);
168 inline const char* CompileLiteral(
const char*);
169 template<
bool SetFlag>
170 inline void PushOpcodeParam(
unsigned);
171 template<
bool SetFlag>
172 inline void PutOpcodeParamAt(
unsigned,
unsigned offset);
173 const char* Compile(
const char*);
175 bool addFunctionWrapperPtr(
const std::string&,
FunctionWrapper*,
unsigned);
181 static std::pair<const char*, Value_t> ParseLiteral(
const char*);
182 static unsigned ParseIdentifier(
const char*);
197 template<
typename Value_t>
200 unsigned mReferenceCount;
209 virtual Value_t callFunction(
const Value_t*) = 0;
212 template<
typename Value_t>
213 template<
typename DerivedWrapper>
215 (
const std::string& name,
const DerivedWrapper& wrapper,
unsigned paramsAmount)
217 return addFunctionWrapperPtr
218 (name,
new DerivedWrapper(wrapper), paramsAmount);
Definition: fparser.hh:192
Definition: fparser.hh:193
Definition: fparser.hh:30
Definition: fparser.hh:186
Definition: fparser.hh:188
Definition: fparser.hh:27
Definition: fparser.hh:191
Definition: fparser.hh:187
Definition: fparser.hh:185
Definition: fparser.hh:198