-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrintCommand.cpp
More file actions
32 lines (29 loc) · 1.04 KB
/
PrintCommand.cpp
File metadata and controls
32 lines (29 loc) · 1.04 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
#include <regex>
#include <iostream>
#include "PrintCommand.h"
#include "DataVars.h"
#include "DataCommands.h"
#include "ExpressionUtils.h"
using namespace std;
PrintCommand::PrintCommand(DataCommands* dataCommands, DataVars* dataVars) {
this->dataCommands = dataCommands;
this->dataVars = dataVars;
}
void PrintCommand::doCommand() {
// get the index from dataCommands
unsigned long index = this->dataCommands->getIndex();
// Set the appropriate regular expression
string toPrint=this->dataCommands->getSeparated().at(index + 1);
regex quote("\".*\"");
// Returns true if the nameInSimulator matches the regular expression of quotes and returns false if not
if(regex_match(toPrint, quote)){
cout<<toPrint.substr(1, toPrint.size() - 2)<<endl;
}
else{ //print Expression
ExpressionUtils expressionUtils;
cout<<expressionUtils.calculateInfixStr(toPrint,dataVars->getSymbolTable())<<endl;
}
index += 2;
// set the new index of dataCommands
this->dataCommands->setIndex(index);
}