InfixToPostfix.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright 2010 Juan Rada-Vilela
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. /*
  13. * File: InfixToPostfix.h
  14. * Author: jcrada
  15. *
  16. * Created on March 6, 2010, 1:14 AM
  17. */
  18. #ifndef _INFIXTOPOSTFIX_H
  19. #define _INFIXTOPOSTFIX_H
  20. #include <vector>
  21. #include <string>
  22. #include <map>
  23. #include "flScalar.h"
  24. namespace fl {
  25. class InfixToPostfix {
  26. private:
  27. std::vector<std::string> _operators;
  28. protected:
  29. virtual std::string preprocess(const std::string& infix) const;
  30. public:
  31. InfixToPostfix();
  32. virtual ~InfixToPostfix();
  33. virtual void addOperator(const std::string& op, int precedence = 0);
  34. virtual std::string removeOperator(int index);
  35. virtual std::string getOperator(int index) const;
  36. virtual int operatorPrecedence(const std::string& op) const;
  37. virtual int numberOfOperators() const;
  38. virtual bool isOperator(const std::string& op) const;
  39. virtual bool isUnaryOperator(const std::string op) const;
  40. virtual bool isOperand(const std::string& op) const;
  41. virtual bool isNumeric(const std::string& op) const;
  42. virtual void loadLogicalOperators();
  43. virtual void loadMathOperators();
  44. virtual std::string transform(const std::string& infix) const;
  45. virtual flScalar evaluate(const std::string postfix,
  46. const std::map<std::string, flScalar>* variables = NULL) const;
  47. virtual flScalar compute(const std::string& op, flScalar a, flScalar b) const;
  48. static void main(int args, char** argv);
  49. };
  50. }
  51. #endif /* _INFIXTOPOSTFIX_H */