-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expr: Expression resution hierary prepared
- Loading branch information
Petr Laštovička
committed
May 11, 2022
1 parent
000f950
commit 7d50517
Showing
17 changed files
with
463 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,39 @@ | ||
# VimXel | ||
|
||
## Shrnutí | ||
### Vykreslování | ||
- nadřída drawer poskytující společné rozhraní pro vyhreslování jednotlivých částí UI | ||
|
||
### Vim ovládání | ||
- různé dekodéry vtupu z klávesnice podle druhu vstupu | ||
## Návrh polymorfismu | ||
|
||
### Buňky | ||
- různé druhy buňek - prázdný, textová a s výrazem | ||
různé druhy buňek | ||
- prázdná | ||
- textová/číselná | ||
- s výrazem | ||
|
||
### Výrazy | ||
Výraz bude převeden na binární strom, který bude postupně vyhodnocován. | ||
Každý node stromu může být | ||
- binární operátor | ||
- +, -, *, / | ||
- concat | ||
- unární operátor | ||
- +, - | ||
- sin, cos | ||
- agregační fce | ||
- avg, sum | ||
- literály | ||
- jednobuňkový | ||
- odkaz na buňku | ||
- číslo (int, double) | ||
- text | ||
- vícebuňkové | ||
- oblast | ||
|
||
### A další drobnosti | ||
- term | ||
- operátor | ||
*** | ||
- binární operátora nebo funkce | ||
- +, -, *, / | ||
- pow, sqrt, ... | ||
- unární operátor nebo funkce | ||
- +, - | ||
- sin, arcsin, ... | ||
- e, ln, ... | ||
- funkce n proměnných | ||
- avg, sum, ... | ||
- concat | ||
*** Dělení na operátory na číslech, textech a oblastích zde pro jednoduchost vynechám. | ||
Takovéto dělení mi umožní kontrolovat vstupy na 1 místě a v nodech provádět | ||
pouze výpočty, nekontrolovat typ vstupů. | ||
|
||
Term může být | ||
- číslo (floating) | ||
- text | ||
- oblast termů | ||
|
||
### A další | ||
- různé druhy chyb | ||
|
||
|
||
|
||
|
||
## Návrh polymorfismu | ||
|
||
Polymorfismus (dále jen pl) plánuji použít na mnoha místech, například pro | ||
různé druhy buněk, kde se mi bude hodit pro vyhodnocování obsahu buňky a její | ||
textová upravitelné podoby jinak pro buňky literálové a jinak pro výrazy. Jako | ||
v běžných tabulkových procesorech bude v tabulce zobrazena hodnota a mimo | ||
tabulku bude možnost výraz/literál upravit. A pro každý z nich platí jiná | ||
pravidla. | ||
|
||
Nadále plánuji pl. využívat při vyhodnocování výrazů. Nadefinuji si základní | ||
node a pak jeho specializace jako unární operátor, binární operátor, (funkce), | ||
agregační funkce, mezivýpočet, literál, hodnota buňky a hodnota oblasti buňek. | ||
Každý podvýraz bude muset implementovat společnou metodu getValue(). Binární a | ||
unární operace budou mít speciální společné konstruktory s odkazy na potomky. | ||
Celá struktura bude uložena ve stromu. Jako ochranu před cykly se již při | ||
stavbě stromu bude muset použít DFS algoritmus. Dále u literálů a hodnot buňek | ||
bude nutno rozliš mezi jejich typy - zda jsou kompatibilní s operací, | ||
sin("Ahoj") je co? Výsledkem všech operací bude buďto chyba propagovaná přes | ||
throw, nebo vypočítaná hodnota, na které bude muset být přetěžovaná metoda | ||
toString() pro vytvoření textu do tabulky a na uložení. | ||
|
||
Dále Vim má mnoho módů, každý z nich má vlastní parser a vlastní chování, rozhrají ovšem shodné | ||
- různé dekodéry vtupu z klávesnice podle Vim módu | ||
- nadřída drawer poskytující společné rozhraní pro vyhreslování jednotlivých částí UI | ||
- různé payloady tokenů při parsování výrazu buňky |
38 changes: 38 additions & 0 deletions
38
Semestralni_prace/src/cz/lastaapps/vimxel/expr/nodes/agregateFunNodes.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef H_AGREGATE_NODE | ||
#define H_AGREGATE_NODE | ||
#include <memory> | ||
#include "node.hpp" | ||
#include "terms.hpp" | ||
#include "multiOperatorNodes.hpp" | ||
|
||
using namespace std; | ||
namespace cz::lastaapps::vimxel::expr { | ||
using ST = shared_ptr<Term>; | ||
|
||
// sum | ||
struct SumNode : public MultiOpNumOrAreaNode { | ||
using MultiOpNumOrAreaNode::MultiOpNumOrAreaNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// max | ||
struct MaxNode : public MultiOpNumOrAreaNode { | ||
using MultiOpNumOrAreaNode::MultiOpNumOrAreaNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// min | ||
struct MinNode : public MultiOpNumOrAreaNode { | ||
using MultiOpNumOrAreaNode::MultiOpNumOrAreaNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// avg | ||
struct AvgNode : public MultiOpNumOrAreaNode { | ||
using MultiOpNumOrAreaNode::MultiOpNumOrAreaNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
} | ||
|
||
#endif |
29 changes: 29 additions & 0 deletions
29
Semestralni_prace/src/cz/lastaapps/vimxel/expr/nodes/binOperatorNodes.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef H_BIM_OP_NODE | ||
#define H_BIM_OP_NODE | ||
#include <memory> | ||
#include <string> | ||
#include "node.hpp" | ||
#include "operatorNode.hpp" | ||
#include "terms.hpp" | ||
|
||
using namespace std; | ||
namespace cz::lastaapps::vimxel::expr { | ||
using ST = shared_ptr<Term>; | ||
|
||
class BinOpNode : public OperatorNode { | ||
protected: | ||
ST mLeft, mRight; | ||
public: | ||
BinOpNode(Node * left, Node * right); | ||
}; | ||
|
||
struct BinOpNumNode : public BinOpNode { | ||
BinOpNumNode(Node * left, Node * right); | ||
}; | ||
|
||
struct BinOpTextNode : public BinOpNode { | ||
BinOpTextNode(Node * left, Node * right); | ||
}; | ||
} | ||
|
||
#endif |
63 changes: 63 additions & 0 deletions
63
Semestralni_prace/src/cz/lastaapps/vimxel/expr/nodes/goniometryNodes.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef H_GONIOMETRY_NODE | ||
#define H_GONIOMETRY_NODE | ||
#include <memory> | ||
#include "node.hpp" | ||
#include "terms.hpp" | ||
#include "binOperatorNodes.hpp" | ||
#include "unOperatorNodes.hpp" | ||
|
||
using namespace std; | ||
namespace cz::lastaapps::vimxel::expr { | ||
using ST = shared_ptr<Term>; | ||
|
||
// sin | ||
struct SinNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// cos | ||
struct CosNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// tan | ||
struct TanNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// cot | ||
struct CotNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// arcsin | ||
struct ArcsinNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// arccos | ||
struct ArccosNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// arctan | ||
struct ArctanNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// arccot | ||
struct ArccotNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
} | ||
|
||
#endif |
57 changes: 57 additions & 0 deletions
57
Semestralni_prace/src/cz/lastaapps/vimxel/expr/nodes/mathFunNodes.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef H_MATH_FUN_NODE | ||
#define H_MATH_FUN_NODE | ||
#include <memory> | ||
#include "node.hpp" | ||
#include "terms.hpp" | ||
#include "binOperatorNodes.hpp" | ||
#include "unOperatorNodes.hpp" | ||
|
||
using namespace std; | ||
namespace cz::lastaapps::vimxel::expr { | ||
using ST = shared_ptr<Term>; | ||
|
||
// pow | ||
struct PowNode : public BinOpNumNode { | ||
using BinOpNumNode::BinOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// sqrt | ||
struct SqrtNode : public BinOpNumNode { | ||
using BinOpNumNode::BinOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// abs | ||
struct AbsNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// e | ||
struct ENode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// ln | ||
struct LnNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// log2 | ||
struct Log2Node : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// log10 | ||
struct Log10Node : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
} | ||
|
||
#endif |
46 changes: 46 additions & 0 deletions
46
Semestralni_prace/src/cz/lastaapps/vimxel/expr/nodes/mathOperatorNodes.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef H_BIM_MATH_OP_NODE | ||
#define H_BIM_MATH_OP_NODE | ||
#include <memory> | ||
#include "node.hpp" | ||
#include "terms.hpp" | ||
#include "unOperatorNodes.hpp" | ||
#include "binOperatorNodes.hpp" | ||
|
||
using namespace std; | ||
namespace cz::lastaapps::vimxel::expr { | ||
using ST = shared_ptr<Term>; | ||
|
||
struct BinPlusNode : public BinOpNumNode { | ||
using BinOpNumNode::BinOpNumNode; | ||
ST getValue() override; | ||
string getName() const override; | ||
}; | ||
struct BinMinusNode : public BinOpNumNode { | ||
using BinOpNumNode::BinOpNumNode; | ||
ST getValue() override; | ||
string getName() const override; | ||
}; | ||
struct BinTimesNode : public BinOpNumNode { | ||
using BinOpNumNode::BinOpNumNode; | ||
ST getValue() override; | ||
string getName() const override; | ||
}; | ||
struct BinDivideNode : public BinOpNumNode { | ||
using BinOpNumNode::BinOpNumNode; | ||
ST getValue() override; | ||
string getName() const override; | ||
}; | ||
|
||
struct UnPlusNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
ST getValue() override; | ||
string getName() const override; | ||
}; | ||
struct UnMinusNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
ST getValue() override; | ||
string getName() const override; | ||
}; | ||
} | ||
|
||
#endif |
39 changes: 39 additions & 0 deletions
39
Semestralni_prace/src/cz/lastaapps/vimxel/expr/nodes/mathProcessNodes.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef H_MATH_PROCESS_NODE | ||
#define H_MATH_PROCESS_NODE | ||
#include <memory> | ||
#include "node.hpp" | ||
#include "terms.hpp" | ||
#include "binOperatorNodes.hpp" | ||
#include "unOperatorNodes.hpp" | ||
|
||
using namespace std; | ||
namespace cz::lastaapps::vimxel::expr { | ||
using ST = shared_ptr<Term>; | ||
|
||
// round | ||
struct RoundNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// ceil | ||
struct CeilNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// floor | ||
struct FloorNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
// tail | ||
struct TailNode : public UnOpNumNode { | ||
using UnOpNumNode::UnOpNumNode; | ||
string getName() const override; | ||
ST getValue() override; | ||
}; | ||
} | ||
|
||
#endif |
Oops, something went wrong.