Skip to content

Commit 12007be

Browse files
committed
Moved passing of input to SyntaxParser from constructor to align with InfixProcessor and Solver
1 parent d3dcfbd commit 12007be

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

ArithmeticCalculator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#include "PostficCalculator.h"
55

66
double ArithmeticCalculator::Solve(char* equation) {
7-
SyntaxParser* parser = new SyntaxParser(equation);
7+
SyntaxParser* parser = new SyntaxParser();
88
PostfixConvertor* postfixConverter = new PostfixConvertor();
99
PostfixCalculator* postfixCalculator = new PostfixCalculator();
1010

11-
LinkedList<FormulaItem*>* formulaList = parser->ParseExpression();
11+
LinkedList<FormulaItem*>* formulaList = parser->ParseExpression(equation);
1212

1313
Stack<FormulaItem*>* postfixStack = postfixConverter->CreatePostfixStack(formulaList);
1414

SyntaxParser.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
using namespace std;
66

7-
SyntaxParser::SyntaxParser(string input) {
8-
_input = input;
7+
SyntaxParser::SyntaxParser() {
98
_parsedExpression = new LinkedList<FormulaItem*>();
109
_current = 0;
1110
}
@@ -122,7 +121,9 @@ void SyntaxParser::ParseNumber() {
122121
delete buffer;
123122
}
124123

125-
LinkedList<FormulaItem*>* SyntaxParser::ParseExpression() {
124+
LinkedList<FormulaItem*>* SyntaxParser::ParseExpression(string input) {
125+
_input = input;
126+
126127
while (true) {
127128
char c = GetNextChar();
128129

SyntaxParser.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SyntaxParser {
1717
void ParseText();
1818
void ParseNumber();
1919
public:
20-
SyntaxParser(string input);
20+
SyntaxParser();
2121
~SyntaxParser();
22-
LinkedList<FormulaItem*>* ParseExpression();
22+
LinkedList<FormulaItem*>* ParseExpression(string input);
2323
};

0 commit comments

Comments
 (0)