-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContext.cpp
52 lines (45 loc) · 1.07 KB
/
Context.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
#include <stdlib.h>
#include "Context.h"
#include "Symbol.h"
Context::Context (std::vector<std::string> * tokens)
: tokens_ (tokens), symbols_ (new std::stack<Symbol *> ())
{
this->begin_ = tokens_->begin ();
this->end_ = tokens_->end ();
}
Context::~Context (void)
{
delete this->symbols_;
delete this->tokens_;
}
std::stack<Symbol *> & Context::getSymbols (void) const
{
return *this->symbols_;
}
const std::string & Context::getToken (void) const
{
return *this->begin_;
}
void Context::nextToken (void)
{
++ this->begin_;
}
bool Context::hasNextToken (void) const
{
return this->begin_ != this->end_;
}
// checks for if the token has alpha and special characters
bool Context::is_numeric (const std::string & token) const
{
bool result = true;
// scans the input token checking to see if any of the characters are not numeric
for (std::string::const_iterator iter = token.begin (); iter != token.end (); ++ iter)
{
char character = *iter;
if (std::isalpha (character) || std::ispunct (character))
{
result = false;
}
}
return result;
}