Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef AEXPRESSION_H
- #define AEXPRESSION_H
- #include "AScope.h"
- #include <vector>
- #include <string>
- #include <iostream>
- typedef enum AOperator {A_NO_OPERATOR, A_ADD, A_SUB, A_DIV, A_MUL, A_MOD, A_POW, A_AND, A_OR, A_EQS, A_NEQ, A_NOT, A_GRT, A_SML, A_GEQ, A_SEQ, A_IF, A_THN, A_ELS, A_EDF};
- typedef enum TokenType {OPERAND, OPERATOR, UNKNOWN};
- template < typename numeraltype > class AExpression
- {
- public:
- AExpression ();
- AExpression( std::string expression_string );
- AExpression( std::string expression_string, AScope<numeraltype> * ascope);
- AExpression( std::vector<AExpression> expression_values,
- std::vector<AOperator> expression_operators );
- ~AExpression();
- numeraltype evaluate();
- numeraltype evaluate(AScope<numeraltype> * scope);
- void init(std::string expression_string);
- void reset();
- void simplify();
- void pushOperator( AOperator oper );
- void pushOperand( AExpression expression );
- void handlePrecedenceOfOperators();
- void setScope( AScope<numeraltype> * scope );
- void setAsVar(int var_ptr_index);
- void setAsCond();
- void setAsFunc(int func_ptr_index, unsigned int param_count);
- numeraltype forceEvaluate();
- numeraltype getFinalValue();
- unsigned int _size = 0;
- private:
- inline void evalOperations();
- inline void evalVarsFuncsConds(AScope<numeraltype> * scope);
- bool isValidOperandCharacter( char c );
- bool isConstant();
- bool isMinus( char c );
- int getGroupIndex(AOperator oper);
- int wordInStringVector(std::vector<std::string> string_vector, std::string word, bool * fullword);
- int wordInVarsFuncs(std::string word, bool * fullword);
- std::string processScopeTokens(std::string expression_string);
- AScope<numeraltype> * _ascope;
- std::vector<AExpression> _value_stack;
- std::vector<AOperator> _operator_stack;
- numeraltype _final_value;
- bool _is_constant = false, _is_variable = false, _is_function = false, _is_conditional = false;
- int _func_param_count;
- int _scope_ptr_index;
- numeraltype _constant_value;
- std::string _expression_string;
- };
- #endif // AEXPRESSION_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement