-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockParser.cpp
More file actions
67 lines (58 loc) · 2.41 KB
/
Copy pathBlockParser.cpp
File metadata and controls
67 lines (58 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// Created by roy on 12/22/18.
//
#include <iostream>
#include <chrono>
#include "BlockParser.h"
#include "IfCommand.h"
#include "WhileCommand.h"
/**
* Constructor of BlockParser, used for parsing blocks of strings.
* @param symbolTable symbol table for variables access.
* @param dataReaderServer data reader server for access to the bind map.
* @param dataSender data sender for sending data through commands.
*/
BlockParser::BlockParser(SymbolTable *symbolTable, DataReaderServer *dataReaderServer, DataSender* newDataSender) {
this->symbolTable = symbolTable;
this->dataReaderServer = dataReaderServer;
this->dataSender = newDataSender;
this->util.set(this->symbolTable, this->dataReaderServer);
}
/**
* This method parses the given strings vector and executes the matching commands
* by their order. The block will be of two types: If block or While block.
* @param stringVector vector of strings representing the commands and parameters.
*/
void BlockParser::parse(vector<string> stringVector) {
string condition, exp1String, exp2String;
vector<string> valueVector1, valueVector2;
string commandString = stringVector.at(0); // first string will represent the command (if/while).
Commands command = commandMap.getCommand(commandString);
// prepares the expressions and condition for the IfCommand / WhileCommand:
condition = stringVector.at(2); // condition of the if or while.
exp1String = stringVector.at(1);
exp2String = stringVector.at(3);
// erase the beginning of the vector.
stringVector.erase(stringVector.begin());
stringVector.erase(stringVector.begin());
stringVector.erase(stringVector.begin());
stringVector.erase(stringVector.begin());
// for each command option - execute the fitting operation:
switch (command) {
case If : {
IfCommand ifCommand(stringVector, exp1String, exp2String, condition,
this->symbolTable, this->dataReaderServer, this->dataSender);
ifCommand.execute();
break;
}
case While : {
WhileCommand whileCommand(stringVector, exp1String, exp2String, condition,
this->symbolTable, this->dataReaderServer, this->dataSender);
whileCommand.execute();
break;
}
// if the command was not valid.
default:
throw "Non valid command";
}
}