summaryrefslogtreecommitdiff
path: root/src/token.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/token.cpp')
-rw-r--r--src/token.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/token.cpp b/src/token.cpp
new file mode 100644
index 0000000..d7fbe88
--- /dev/null
+++ b/src/token.cpp
@@ -0,0 +1,70 @@
1#include "token.h"
2
3#include "number.h"
4#include <bu/formatter.h>
5#include <bu/string.h>
6
7Token::Token( Type eType ) :
8 eType( eType ),
9 sVal( 0 )
10{
11}
12
13Token::Token( Type eType, Bu::String *s ) :
14 eType( eType ),
15 sVal( s )
16{
17}
18
19Token::Token( Type eType, Number *n ) :
20 eType( eType ),
21 nVal( n )
22{
23}
24
25Token::Token( const Token &rSrc ) :
26 eType( rSrc.eType ),
27 sVal( rSrc.sVal )
28{
29 Token &rMod = const_cast<Token &>(rSrc);
30 rMod.sVal = 0;
31}
32
33Token::~Token()
34{
35 switch( eType )
36 {
37 case tNumber:
38 delete nVal;
39 break;
40
41 case tString:
42 case tCommand:
43 delete sVal;
44 break;
45
46 default:
47 break;
48 }
49}
50
51Bu::Formatter &operator<<( Bu::Formatter &f, Token::Type eType )
52{
53 switch( eType )
54 {
55 case Token::tNumber: return f << "num";
56 case Token::tString: return f << "str";
57 case Token::tCommand: return f << "cmd";
58 case Token::tPlus: return f << "+";
59 case Token::tMinus: return f << "-";
60 case Token::tDivide: return f << "/";
61 case Token::tMultiply: return f << "*";
62 case Token::tOpenParen: return f << "(";
63 case Token::tCloseParen: return f << ")";
64 case Token::tEndOfLine: return f << "eol";
65 case Token::tEndOfInput: return f << "eoi";
66
67 default: return f << "???";
68 }
69}
70