#include <vector>
#include <string>
-#include "lexeme_id.h"
#include "lexeme_impl.h"
+#include "lexeme_id.h"
+#include "data.h"
using namespace utakata::lexeme;
using namespace utakata::utf8_string;
+using namespace utakata::interpreter;
+
smart_ptr<ILexeme> utakata::lexeme::makeOpenParen()
{
- return smart_ptr<ILexeme>(new OpenParen());
+ smart_ptr<UTF8String> tmp(new UTF8String());
+ *tmp += "(";
+ return smart_ptr<ILexeme>(new PureLexeme(tmp, LexemeID::openParenthesis));
}
smart_ptr<ILexeme> utakata::lexeme::makeEOS()
{
- return smart_ptr<ILexeme>(new EOS());
+ return smart_ptr<ILexeme>(new PureLexeme(smart_ptr<UTF8String>(), LexemeID::eos));
}
smart_ptr<ILexeme> utakata::lexeme::makeCloseParen()
{
- return smart_ptr<ILexeme>(new CloseParen());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert(")")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::closeParenthesis));
}
smart_ptr<ILexeme> utakata::lexeme::makeBackQuote()
{
- return smart_ptr<ILexeme>(new BackQuote());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("`")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::backquote));
}
smart_ptr<ILexeme> utakata::lexeme::makeQuote()
{
- return smart_ptr<ILexeme>(new Quote());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("'")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::quote));
}
smart_ptr<ILexeme> utakata::lexeme::makeDot()
{
- return smart_ptr<ILexeme>(new Dot());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert(".")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::dot));
}
smart_ptr<ILexeme> utakata::lexeme::makeIdentifier(const utakata::utf8_string::UTF8String& str)
smart_ptr<ILexeme> utakata::lexeme::makeUnquoteSplicing(const utakata::utf8_string::UTF8String& str)
{
- return smart_ptr<ILexeme>(new UnquoteSplicing());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert(",@")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::unquoteSplicing));
}
smart_ptr<ILexeme> utakata::lexeme::makeUnquote()
{
- return smart_ptr<ILexeme>(new Unquote());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert(",")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::unsyntax));
}
smart_ptr<ILexeme> utakata::lexeme::makeByteVector()
{
- return smart_ptr<ILexeme>(new ByteVector());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("#vu(")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::byteVector));
}
smart_ptr<ILexeme> utakata::lexeme::makeVector()
{
- return smart_ptr<ILexeme>(new Vector());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("#(")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::vector));
}
smart_ptr<ILexeme> utakata::lexeme::makeSyntax()
{
- return smart_ptr<ILexeme>(new Syntax());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("#'")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::syntax));
}
smart_ptr<ILexeme> utakata::lexeme::makeQuasiSyntax()
{
- return smart_ptr<ILexeme>(new QuasiSyntax());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("#`")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::quasiSyntax));
}
smart_ptr<ILexeme> utakata::lexeme::makeUnsyntaxSplicing()
{
- return smart_ptr<ILexeme>(new UnsyntaxSplicing());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("#,@")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::unsyntaxSplicing));
}
smart_ptr<ILexeme> utakata::lexeme::makeUnsyntax()
{
- return smart_ptr<ILexeme>(new Unsyntax());
+ smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert(",#")));
+ return smart_ptr<ILexeme>(new PureLexeme(tmp,
+ LexemeID::unsyntax));
}
smart_ptr<ILexeme> utakata::lexeme::makeCharactor(const utakata::utf8_string::UTF8String& str)
return smart_ptr<ILexeme>(new Number(real, imagin, exact, radix));
}
-
-// 各lexemeの実装
-
-///////////////
-// OpenParen //
-///////////////
-
-const utakata::lexeme::LexemeID OpenParen::getID() const
-{
- return utakata::lexeme::LexemeID::openParenthesis;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> OpenParen::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string("(");
- return p;
-}
-
-/////////
-// EOF //
-/////////
-
-const utakata::lexeme::LexemeID EOS::getID() const
-{
- return utakata::lexeme::LexemeID::eos;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> EOS::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string("");
- return p;
-}
-
-
-////////////////
-// CloseParen //
-////////////////
-
-const utakata::lexeme::LexemeID CloseParen::getID() const
-{
- return utakata::lexeme::LexemeID::closeParenthesis;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> CloseParen::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string(")");
- return p;
-}
-
-///////////////
-// BackQuote //
-///////////////
-
-const utakata::lexeme::LexemeID BackQuote::getID() const
-{
- return utakata::lexeme::LexemeID::backquote;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> BackQuote::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string("`");
- return p;
-}
-
-///////////
-// Quote //
-///////////
-
-const utakata::lexeme::LexemeID Quote::getID() const
-{
- return utakata::lexeme::LexemeID::quote;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> Quote::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string("'");
- return p;
-}
-
-/////////
-// Dot //
-/////////
-
-const utakata::lexeme::LexemeID Dot::getID() const
-{
- return utakata::lexeme::LexemeID::dot;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> Dot::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string(".");
- return p;
-}
-
-/////////////////////
-// UnquoteSplicing //
-/////////////////////
-
-const utakata::lexeme::LexemeID UnquoteSplicing::getID() const
-{
- return utakata::lexeme::LexemeID::unquoteSplicing;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> UnquoteSplicing::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string(",@");
- return p;
-}
-
////////////////
-// ByteVector //
+// PureLexeme //
////////////////
+PureLexeme::PureLexeme(const smart_ptr<UTF8String>& str,
+ const LexemeID id) : str_(str), id_(id)
+{}
-const utakata::lexeme::LexemeID ByteVector::getID() const
-{
- return utakata::lexeme::LexemeID::byteVector;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> ByteVector::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string("#vu8(");
- return p;
-}
-
-////////////////
-// Vector //
-////////////////
-
-const utakata::lexeme::LexemeID Vector::getID() const
-{
- return utakata::lexeme::LexemeID::vector;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> Vector::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string("#vu8(");
- return p;
-}
-
-/////////////
-// Unquote //
-/////////////
-
-const utakata::lexeme::LexemeID Unquote::getID() const
-{
- return utakata::lexeme::LexemeID::unquote;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> Unquote::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string(",");
- return p;
-}
-
-////////////
-// Syntax //
-////////////
-
-const utakata::lexeme::LexemeID Syntax::getID() const
-{
- return utakata::lexeme::LexemeID::syntax;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> Syntax::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string("#'");
- return p;
-}
-
-/////////////////
-// QuasiSyntax //
-/////////////////
-
-const utakata::lexeme::LexemeID QuasiSyntax::getID() const
-{
- return utakata::lexeme::LexemeID::quasiSyntax;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> QuasiSyntax::toString() const
-{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string("#`");
- return p;
-}
-
-//////////////
-// Unsyntax //
-//////////////
-
-const utakata::lexeme::LexemeID Unsyntax::getID() const
-{
- return utakata::lexeme::LexemeID::unsyntax;
-}
-
-smart_ptr<utakata::utf8_string::UTF8String> Unsyntax::toString() const
+const LexemeID PureLexeme::getID() const
{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string("#,");
- return p;
+ return id_;
}
-//////////////////////
-// UnsyntaxSplicing //
-//////////////////////
-
-const utakata::lexeme::LexemeID UnsyntaxSplicing::getID() const
+smart_ptr<UTF8String> PureLexeme::toString() const
{
- return utakata::lexeme::LexemeID::unsyntaxSplicing;
+ return str_;
}
-smart_ptr<utakata::utf8_string::UTF8String> UnsyntaxSplicing::toString() const
+smart_ptr<utakata::interpreter::LiteralData> PureLexeme::getData() const
{
- smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
- *p += std::string("#,@");
- return p;
+ return smart_ptr<utakata::interpreter::LiteralData>();
}
////////////////
Identifier::Identifier(const utakata::utf8_string::UTF8String& str) :
str_(new utakata::utf8_string::UTF8String(str))
-{}
+{
+}
const utakata::lexeme::LexemeID Identifier::getID() const
{
return str_;
}
+smart_ptr<utakata::interpreter::LiteralData> Identifier::getData() const
+{
+ smart_ptr<utakata::interpreter::LiteralData> data(new utakata::interpreter::LiteralData);
+
+ data->string.add(new utakata::interpreter::StringData);
+ data->string->str.add(new utakata::utf8_string::UTF8String(*str_));
+ return data;
+}
+
/////////////
// String //
/////////////
String::String(const utakata::utf8_string::UTF8String& str) :
str_(new utakata::utf8_string::UTF8String(str))
-{}
+{
+}
const utakata::lexeme::LexemeID String::getID() const
{
- return utakata::lexeme::LexemeID::string;
+ return utakata::lexeme::LexemeID::identifier;
}
smart_ptr<utakata::utf8_string::UTF8String> String::toString() const
return str_;
}
+smart_ptr<utakata::interpreter::LiteralData> String::getData() const
+{
+ smart_ptr<utakata::interpreter::LiteralData> data(new utakata::interpreter::LiteralData);
+
+ data->string.add(new utakata::interpreter::StringData);
+ data->string->str.add(new utakata::utf8_string::UTF8String(*str_));
+ return data;
+}
+
////////////
// Number //
////////////
Number::Number(const UTF8String& real,
const UTF8String& imagin,
bool exact, int radix) :
- real_(new UTF8String(real)), imagin_(new UTF8String(imagin)),
- exact_(exact), radix_(radix)
+ data_(new LiteralData)
{
+ data_->number = utakata::interpreter::makeNumberData(real, imagin, exact, radix);
}
const utakata::lexeme::LexemeID Number::getID() const
smart_ptr<utakata::utf8_string::UTF8String> Number::toString() const
{
- return smart_ptr<UTF8String>(new UTF8String(*real_ + *imagin_));
+ return smart_ptr<UTF8String>(new UTF8String(*data_->number->real + *data_->number->imagin));
+}
+
+smart_ptr<utakata::interpreter::LiteralData> Number::getData() const
+{
+ return data_;
}
///////////////
///////////////
Charactor::Charactor(const UTF8String& ch) : ch_(new UTF8String(ch))
-{}
+{
+}
const utakata::lexeme::LexemeID Charactor::getID() const
{
return ch_;
}
+smart_ptr<utakata::interpreter::LiteralData> Charactor::getData() const
+{
+ smart_ptr<utakata::interpreter::LiteralData> data(new utakata::interpreter::LiteralData);
+
+ data->string.add(new utakata::interpreter::StringData);
+ data->string->str.add(new utakata::utf8_string::UTF8String(*ch_));
+ return data;
+}
+
+
/////////////
// Boolean //
/////////////
-Boolean::Boolean(const smart_ptr<UTF8Char>& ch) : str_(new UTF8String())
+Boolean::Boolean(const smart_ptr<UTF8Char>& ch) : bool_(new UTF8String())
{
- *str_ += *ch;
+ *bool_ += *ch;
}
const utakata::lexeme::LexemeID Boolean::getID() const
smart_ptr<utakata::utf8_string::UTF8String> Boolean::toString() const
{
- return str_;
+ return bool_;
+}
+
+smart_ptr<utakata::interpreter::LiteralData> Boolean::getData() const
+{
+ smart_ptr<utakata::interpreter::LiteralData> data(new utakata::interpreter::LiteralData);
+
+ data->string.add(new utakata::interpreter::StringData);
+ data->string->str.add(new utakata::utf8_string::UTF8String(*bool_));
+ return data;
}