-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.cpp
More file actions
executable file
·87 lines (79 loc) · 1.66 KB
/
strings.cpp
File metadata and controls
executable file
·87 lines (79 loc) · 1.66 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* strings.cpp
* Benjamin Ferid Issa
* February 8th 2017
*
* Based on files provided by Dr. Frank Jones, Computer Science Department, Brigham Young University
*/
#include "strings.h"
bool strings::input(char Character)
{
bool stillValid = false;
if(Character == '\'')
{
stillValid = true;
m_token->addCharacter(Character);
nextState(new inString(m_contextManager, m_token));
}
else
{
reject();
}
/*THIS MUST HAPPEN LAST!!!*/
delete this;
return stillValid;
}
bool inString::input(char Character)
{
bool stillValid = false;
if(Character != '\'' && Character != EOF)
{
if (Character == '\n'){
m_contextManager->increaseLineCount();
}
stillValid = true;
m_token->addCharacter(Character);
return stillValid;//don't destroy this object, we are still in this state
}
else if(Character == '\'')
{
stillValid = true;
m_token->addCharacter(Character);
nextState(new oneQuote(m_contextManager, m_token));
}
else if (Character == EOF)
{
m_token->setType(UNDEFINED);
delete this;
return stillValid;
}
else{
m_token->setType(UNDEFINED);
}
/*THIS MUST HAPPEN LAST!!!*/
delete this;
return stillValid;
}
bool oneQuote::input(char Character)
{
bool stillValid = false;
if(Character == '\'')
{
stillValid = true;
m_token->addCharacter(Character);
nextState(new inString(m_contextManager, m_token));
}
else if (Character == EOF){
m_token->setType(UNDEFINED);
delete this;
return stillValid;
}
else {
m_token->setType(STRING);
delete this;
return stillValid;
}
/*THIS MUST HAPPEN LAST!!!*/
delete this;
return stillValid;
}