IterationFormula.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef MANDEL_ITERATIONFORMULA_H
  2. #define MANDEL_ITERATIONFORMULA_H
  3. #include <variant>
  4. #include <memory>
  5. #include <string>
  6. namespace mnd
  7. {
  8. struct IterationFormula;
  9. struct Constant;
  10. struct Variable;
  11. struct UnaryOperation;
  12. struct BinaryOperation;
  13. struct Addition;
  14. struct Multiplication;
  15. struct Division;
  16. struct Pow;
  17. using Expression = std::variant<
  18. Constant,
  19. Variable,
  20. UnaryOperation,
  21. Addition,
  22. Multiplication,
  23. Division,
  24. Pow
  25. >;
  26. std::unique_ptr<Expression> parse(const std::string& formula);
  27. }
  28. struct mnd::IterationFormula
  29. {
  30. std::unique_ptr<Expression> expr;
  31. };
  32. struct mnd::Constant
  33. {
  34. double value;
  35. inline Constant(double value) :
  36. value{ value }
  37. {}
  38. };
  39. struct mnd::Variable
  40. {
  41. std::string name;
  42. };
  43. struct mnd::UnaryOperation
  44. {
  45. std::unique_ptr<Expression> operand;
  46. };
  47. struct mnd::BinaryOperation
  48. {
  49. std::unique_ptr<Expression> left;
  50. std::unique_ptr<Expression> right;
  51. };
  52. struct mnd::Addition : mnd::BinaryOperation
  53. {
  54. bool subtraction = false;
  55. };
  56. struct mnd::Multiplication : mnd::BinaryOperation
  57. {
  58. };
  59. struct mnd::Division : mnd::BinaryOperation
  60. {
  61. };
  62. struct mnd::Pow : mnd::BinaryOperation
  63. {
  64. };
  65. #endif // MANDEL_ITERATIONFORMULA_H