From 2909f50d008920568f0e50da760b266388ccc124 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 22 Apr 2013 13:05:22 -0600 Subject: There is now a parser & calculator interface. --- src/token.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/token.cpp (limited to 'src/token.cpp') 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 @@ +#include "token.h" + +#include "number.h" +#include +#include + +Token::Token( Type eType ) : + eType( eType ), + sVal( 0 ) +{ +} + +Token::Token( Type eType, Bu::String *s ) : + eType( eType ), + sVal( s ) +{ +} + +Token::Token( Type eType, Number *n ) : + eType( eType ), + nVal( n ) +{ +} + +Token::Token( const Token &rSrc ) : + eType( rSrc.eType ), + sVal( rSrc.sVal ) +{ + Token &rMod = const_cast(rSrc); + rMod.sVal = 0; +} + +Token::~Token() +{ + switch( eType ) + { + case tNumber: + delete nVal; + break; + + case tString: + case tCommand: + delete sVal; + break; + + default: + break; + } +} + +Bu::Formatter &operator<<( Bu::Formatter &f, Token::Type eType ) +{ + switch( eType ) + { + case Token::tNumber: return f << "num"; + case Token::tString: return f << "str"; + case Token::tCommand: return f << "cmd"; + case Token::tPlus: return f << "+"; + case Token::tMinus: return f << "-"; + case Token::tDivide: return f << "/"; + case Token::tMultiply: return f << "*"; + case Token::tOpenParen: return f << "("; + case Token::tCloseParen: return f << ")"; + case Token::tEndOfLine: return f << "eol"; + case Token::tEndOfInput: return f << "eoi"; + + default: return f << "???"; + } +} + -- cgit v1.2.3