-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrintCommand.cpp
52 lines (46 loc) · 1.22 KB
/
PrintCommand.cpp
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
//
// Created by franckito on 12/18/18.
//
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include "PrintCommand.h"
#include "Command.h"
#include "GlobalTables.h"
#include "ShuntingYard.h"
int PrintCommand::execute(vector<string> cmdTemp, int index){
ShuntingYard* sY = new ShuntingYard();
GlobalTables* gT = new GlobalTables();
int endLine = enterKey(cmdTemp, index);
string temp = vectorToString(cmdTemp, index + 1, index + endLine);
if(gT->keyExists(temp))
printMeth(to_string(symbolTable.at(temp)));
else if(temp.find("\"")== string::npos)
printMeth(to_string(sY->calculate(temp)));
else
printMeth(temp);
delete sY;
delete gT;
return endLine;
}
void PrintCommand::printMeth(string message) {
cout << message << endl;
}
string PrintCommand::vectorToString(vector<string> vector, int index, int end) {
string ret = vector.at(index);
int i = 1;
while(index + i < end){
ret += vector.at(index + i);
}
return ret;
}
int PrintCommand::enterKey(vector<string> vector, int index){
int i = 0;
while(vector.at(index + i) != "\n") {
i++;
}
return i;
}
PrintCommand::~PrintCommand() = default;