1
0

IterationFormula.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef MANDEL_ITERATIONFORMULA_H
  2. #define MANDEL_ITERATIONFORMULA_H
  3. #include <variant>
  4. #include <memory>
  5. #include <string>
  6. #include <stdexcept>
  7. namespace mnd
  8. {
  9. struct IterationFormula;
  10. struct Constant;
  11. struct Variable;
  12. struct UnaryOperation;
  13. struct BinaryOperation;
  14. struct Addition;
  15. struct Multiplication;
  16. struct Division;
  17. struct Pow;
  18. using Expression = std::variant<
  19. Constant,
  20. Variable,
  21. UnaryOperation,
  22. Addition,
  23. Multiplication,
  24. Division,
  25. Pow
  26. >;
  27. struct ParseError : std::runtime_error
  28. {
  29. ParseError(const std::string& err) :
  30. std::runtime_error(err.c_str())
  31. {}
  32. };
  33. Expression parse(const std::string& formula);
  34. std::string toString(const mnd::Expression&);
  35. }
  36. struct mnd::IterationFormula
  37. {
  38. std::unique_ptr<Expression> expr;
  39. IterationFormula(Expression expr);
  40. void constantPropagation
  41. };
  42. struct mnd::Constant
  43. {
  44. double value;
  45. inline Constant(double value) :
  46. value{ value }
  47. {}
  48. };
  49. struct mnd::Variable
  50. {
  51. std::string name;
  52. };
  53. struct mnd::UnaryOperation
  54. {
  55. std::unique_ptr<Expression> operand;
  56. /*inline UnaryOperation(const UnaryOperation& other) :
  57. operand{ std::make_unique<Expression>(*other.operand) }
  58. {}*/
  59. };
  60. struct mnd::BinaryOperation
  61. {
  62. std::unique_ptr<Expression> left;
  63. std::unique_ptr<Expression> right;
  64. /*inline BinaryOperation(const BinaryOperation& other) :
  65. left{ std::make_unique<Expression>(*other.left) },
  66. right{ std::make_unique<Expression>(*other.right) }
  67. {}*/
  68. };
  69. struct mnd::Addition : mnd::BinaryOperation
  70. {
  71. bool subtraction = false;
  72. };
  73. struct mnd::Multiplication : mnd::BinaryOperation
  74. {
  75. };
  76. struct mnd::Division : mnd::BinaryOperation
  77. {
  78. };
  79. struct mnd::Pow : mnd::BinaryOperation
  80. {
  81. };
  82. namespace mnd
  83. {
  84. }
  85. #endif // MANDEL_ITERATIONFORMULA_H