-
Notifications
You must be signed in to change notification settings - Fork 0
/
singles.cpp
executable file
·71 lines (67 loc) · 1.49 KB
/
singles.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* singles.cpp
* By: Frank Jones
* January 24th 2017
* Description: Contains an implemenetation of the state machine for recognizing single character key words
*/
#include "singles.h"
#include "lexer.h"
/** BEGIN SINGLES **/
bool singles::input(char Character)
{
switch(Character)
{
case ',':
m_token->setType(COMMA);
break;
case '.':
m_token->setType(PERIOD);
break;
case '?':
m_token->setType(Q_MARK);
break;
case '(':
m_token->setType(LEFT_PAREN);
break;
case ')':
m_token->setType(RIGHT_PAREN);
break;
case ':':
m_token->setType(COLON);//this may change if we see a dash next...
m_token->addCharacter(Character);
nextState(new colonFound(m_contextManager, m_token));
delete this;
return true;
break;
case '*':
m_token->setType(MULTIPLY);
break;
case '+':
m_token->setType(ADD);
break;
case EOF:
m_token->setType(MY_EOF);
break;
default://not a valid input for this machine...
reject();//likely redundant - but just to be safe...
break;
}
if(m_token->Type() != UNDEFINED)
{
m_token->addCharacter(Character);
}
/*THIS MUST HAPPEN LAST!!!*/
delete this;
return false;
}
bool colonFound::input(char Character)
{
if(Character == '-')//we have a colon-dash, accept it
{
m_token->setType(COLON_DASH);
m_token->addCharacter(Character);
}
//either way we matched something, stop processing input either way...
delete this;
return false;
}