diff options
| Commit | b3a6a4936eca7f8809cf05b9324fc57e68fa9073 (patch) | |
|---|---|---|
| Author | 2022-06-14 08:23:45 +0300 | |
| Committer | 2022-06-14 08:23:45 +0300 | |
| Files | cea6591c728e95d46e5d8c91147ad313b764e676 /src | |
| FMI-OOP-P2_Tables-b3a6a4936eca7f8809cf05b9324fc57e68fa9073.tar FMI-OOP-P2_Tables-b3a6a4936eca7f8809cf05b9324fc57e68fa9073.tar.gz FMI-OOP-P2_Tables-b3a6a4936eca7f8809cf05b9324fc57e68fa9073.zip | ||
| Parent | 8e1122d386cc970ae18a7f03ef7890dbfb4b20da (diff) | |
Autocommit at 14.06.2022 @ 08:23
1 files changed, 8 insertions, 6 deletions
| -rw-r--r-- | src/Models/CellFormula.cpp | 14 |
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp index 931feff..e2919f3 100644 --- a/src/Models/CellFormula.cpp +++ b/src/Models/CellFormula.cpp @@ -71,7 +71,7 @@ String CellFormula::getValueForPrint() const { // Rough implementation of the grammar // -// S -> WDS | WD.DS | WRDCDS | WOS | W +// S -> WDWOS | WD.DWOS | WRDCDWOS | W // O -> + | - | * | / | ^ // D -> D0 | D1 | ... | D9 | 0 | 1 | ... | 9 // W -> W | epsilon @@ -96,26 +96,26 @@ void CellFormula::parseAndSetValue(const char* str) { rawFormula = String(str); Pair<int, int> loc; - char currOp; + char currOp = 0; while (*str != '\0') { List<char> buffer; W(str); if (*str == 'R') { D(str, buffer); - int row = atoi(buffer.raw_data()); + loc.left = atoi(buffer.raw_data()); if (*str != 'C') throw std::logic_error("Error: Invalid character!"); str++; buffer.clear(); D(str, buffer); - int col = atoi(buffer.raw_data()); + loc.right = atoi(buffer.raw_data()); W(str); O(str, currOp); + if (currOp == 0) throw std::logic_error("Error: Could not find operand!"); W(str); - loc = {row, col}; } - else { + else if (*str >= '0' && *str <= '9') { double val = atof(str); while ((*str >= '0' && *str <= '9') || *str == ' ' || *str == '.') str++; @@ -123,6 +123,8 @@ void CellFormula::parseAndSetValue(const char* str) { localCells.add(CellDouble(val)); loc = {-1, (int)(localCells.get_count() - 1)}; } + else + throw std::logic_error("Error: Invalid value!"); if (currOp == '^') currOp *= -1; else if ((currOp == '+' || currOp == '-') && formula.get_count() != 0) { |
