diff options
Autocommit at 14.06.2022 @ 08:08
2 files changed, 15 insertions, 6 deletions
| -rw-r--r-- | src/Models/CellFormula.cpp | 19 | ||||
| -rw-r--r-- | src/Models/Table.cpp | 2 |
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp index 4e7449c..4b2c0f8 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 | WRDRDS | WOS | W +// S -> WDS | WD.DS | WRDCDS | WOS | W // O -> + | - | * | / | ^ // D -> D0 | D1 | ... | D9 | 0 | 1 | ... | 9 // W -> W | epsilon @@ -87,6 +87,11 @@ void D(const char*& str, List<char>& buffer) { buffer.add(*(str++)); } +void O(const char*& str, List<char>& buffer) { + if (*str == '+' || *str == '-' || *str == '*' || *str == '/' || *str == '^') + buffer.add(*(str++)); +} + void CellFormula::parseAndSetValue(const char* str) { rawFormula = String(str); @@ -94,11 +99,15 @@ void CellFormula::parseAndSetValue(const char* str) { char currOp; while (*str != '\0') { - str++; - while (*str == ' ') str++; + List<char> buffer; + W(str); if (*str == 'R') { - int row = atoi(++str); - while (*str != 'C') str++; + D(str, buffer); + int row = atoi(buffer.raw_data()); + if (*str != 'C') throw std::logic_error("Error: Invalid character!"); + str++; + buffer.clear(); + D(str, buffer); int col = atoi(++str); while (*str != ' ' && *str != '\0') str++; while (*str == ' ') str++; diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index d1b2cc0..0fb01b6 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -12,7 +12,7 @@ // Rough implementation of the grammar // -// S -> W"=A"W | W"A"W | WPDW | WPD.DW +// S -> W"=A"S | W"A"S | WPDS | WPD.DS | epsilon // A -> Aa | Ab | ... | AZ | A0 | A1 | ... | A* | ... | a | b | ... | epsilon // D -> D0 | D1 | ... | D9 | 0 | 1 | ... | 9 // P -> + | - | epsilon |
