-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cpp
44 lines (42 loc) · 1.25 KB
/
util.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
#include "util.h"
TypeChecker::TypeChecker()
{
}
const std::vector <std::string> TypeChecker::operators = {"+", "-", "*", "/", "=", "{", "}", "(", ")", "<", ">", "#", ";"};
const std::vector <std::string> TypeChecker::binaryOperators = {"+", "-", "*", "/"};
const std::vector <std::string> TypeChecker::dataTypes = {"int", "char", "double", "string"};
template <typename T>
bool TypeChecker::isPresentInVector(const std::vector <T> &array, const T &searchString)
{
for(int i = 0; i < (int)array.size(); i += 1)
{
if(array[i] == searchString)
{
return true;
}
}
return false;
}
bool TypeChecker::isStringAnOperator(const std::string &operatorString)
{
return isPresentInVector(operators, operatorString);
}
bool TypeChecker::isStringADataType(const std::string &dataTypeString)
{
return isPresentInVector(dataTypes, dataTypeString);
}
bool TypeChecker::isStringABinaryOperator(const std::string &binaryOperator)
{
return isPresentInVector(binaryOperators, binaryOperator);
}
bool TypeChecker::isStringANumber(const std::string &numberString)
{
for(int i = 0; i < (int)numberString.size(); i += 1)
{
if(!isdigit(numberString[i]))
{
return false;
}
}
return true;
}