Advertisement
Mr-A

AExpression.h

Oct 24th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. #ifndef AEXPRESSION_H
  2. #define AEXPRESSION_H
  3.  
  4. #include "AScope.h"
  5. #include <vector>
  6. #include <string>
  7. #include <iostream>
  8.  
  9. 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};
  10. typedef enum TokenType {OPERAND, OPERATOR, UNKNOWN};
  11.  
  12.  
  13. template < typename numeraltype > class AExpression
  14. {
  15. public:
  16.     AExpression ();
  17.     AExpression( std::string expression_string );
  18.     AExpression( std::string expression_string, AScope<numeraltype> * ascope);
  19.     AExpression( std::vector<AExpression> expression_values,
  20.                  std::vector<AOperator> expression_operators );
  21.     ~AExpression();
  22.  
  23.     numeraltype evaluate();
  24.     numeraltype evaluate(AScope<numeraltype> * scope);
  25.     void init(std::string expression_string);
  26.     void reset();
  27.     void simplify();
  28.     void pushOperator( AOperator oper );
  29.     void pushOperand( AExpression expression );
  30.     void handlePrecedenceOfOperators();
  31.     void setScope( AScope<numeraltype> * scope );
  32.     void setAsVar(int var_ptr_index);
  33.     void setAsCond();
  34.     void setAsFunc(int func_ptr_index, unsigned int param_count);
  35.     numeraltype forceEvaluate();
  36.     numeraltype getFinalValue();
  37.  
  38.     unsigned int _size = 0;
  39.  
  40. private:
  41.     inline void evalOperations();
  42.     inline void evalVarsFuncsConds(AScope<numeraltype> * scope);
  43.  
  44.     bool isValidOperandCharacter( char c );
  45.     bool isConstant();
  46.     bool isMinus( char c );
  47.     int getGroupIndex(AOperator oper);
  48.     int wordInStringVector(std::vector<std::string> string_vector, std::string word,  bool * fullword);
  49.     int wordInVarsFuncs(std::string word, bool * fullword);
  50.  
  51.     std::string processScopeTokens(std::string expression_string);
  52.  
  53.     AScope<numeraltype> * _ascope;
  54.     std::vector<AExpression> _value_stack;
  55.     std::vector<AOperator> _operator_stack;
  56.  
  57.     numeraltype _final_value;
  58.     bool _is_constant = false, _is_variable = false, _is_function = false, _is_conditional = false;
  59.     int _func_param_count;
  60.     int _scope_ptr_index;
  61.     numeraltype _constant_value;
  62.     std::string _expression_string;
  63. };
  64.  
  65. #endif // AEXPRESSION_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement