CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
CPP = gcc -E
-CPPFLAGS =
+CPPFLAGS = -Wall
CXX = g++
CXXDEPMODE = depmode=gcc3
CXXFLAGS = -g -O2
// 何か一つの非終端記号、終端記号を読みだすたびにそれを返す。
// まずは何はなくとも1文字読みだす。
- utf8_string::CUTF8Char ch(stream->read());
- if (utf8_string::is_eof(ch))
- {
- // eofを示す値を返す。
- return smart_ptr<lexer::CLexeme>();
+ // EOF以外の値の場合には、通常の字句解析を行っていく。
+ utf8_string::CUTF8String str();
+ bool first = true;
+ while (!stream->isEOF()) {
+
+ // 意味のある文字のみで構成していく。
+
+ utf8_string::CUTF8Char ch(stream->read());
+
+
+ // 最初の一文字で、大体決定されるため、firstをチェックして
+ // いく。
+ if (first)
+ {
+ first = false;
+
+ // ()[]`',.は構文解析の重要な要素となるため、このまま返す。
+ if (ch.toUTF16Code() == '(' || ch.toUTF16Code() == '[')
+ {
+ return makeStartParen();
+ }
+
+ if (ch.toUTF16Code() == ')' || ch.toUTF16Code() == ']')
+ {
+ return makeEndParen();
+ }
+
+ if (ch.toUTF16Code() == '`')
+ {
+ return makeBackQuote();
+ }
+
+ if (ch.toUTF16Code() == '\'')
+ {
+ return makeQuote();
+ }
+
+ if (ch.toUTF16Code() == '.')
+ {
+ return makeDot();
+ }
+
+ if (ch.toUTF16Code() == ',')
+ {
+ return makeComma();
+ }
+ }
+ else
+ {
+ // 読出した文字がデリミタであるかどうか。
+ if (isDelimiter(ch))
+ {
+ // デリミタ文字である場合、このデリミタ文字に来るまでの間に
+ // 保存した文字列から、実際のデータを作成する。
+
+ }
+ }
}
}
namespace utakata {
namespace lexer {
-
+
+ class CLexeme;
class CLexer
{
/**
// つまりは全体をpimplにしておき、データはそれらから取得するようにするということ。
// それぞれを取得するためのインターフェースはこれから作成される。
public:
- ILexeme();
- virtual ~ILexeme(){}
+ CLexeme();
+ virtual ~CLexeme(){}
// 終端記号、非終端記号のIDを取得する。
int getID() const;
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
CPP = gcc -E
-CPPFLAGS =
+CPPFLAGS = -Wall
CXX = g++
CXXDEPMODE = depmode=gcc3
CXXFLAGS = -g -O2
str3.insert(str3.end(), str2.begin(), str2.end());
asserter->check(str3.toStr(), "あsいうえsssお");
+ // 互いに加算できる。
+ utakata::utf8_string::CUTF8String str4 = str + str2;
+ asserter->check(str4.toStr(), "ssおssおあいうえs");
+
return asserter->isOk();
}
#include <iostream>
#include <sstream>
#include <string>
+#include <algorithm>
+
#include <functional>
asserter->check(stream.peek()[0], 'T');
asserter->check(stream.read()[0], 'T');
+ // ここの時点ではまだeofではない。
+ asserter->check(stream.isEOF(), false);
+
// 複数文字の読み出しのチェック
const std::vector<unsigned char> f = stream.read(2);
std::string t("", f.size());
identity_local());
asserter->check(t, "F8");
+
+ // この時点でeofがtrueとなる
+ asserter->check(stream.isEOF(), true);
+ asserter->check(stream.read()[0], 0xff);
return asserter->isOk();
}
#include <sstream>
#include <assert.h>
-
#include "InputStream.h"
#include "utf8.h"
#include "smart_ptr.h"
using namespace std;;
using namespace utakata::utf8;
-CUTF8InputStream::CUTF8InputStream() : strm_()
+CUTF8InputStream::CUTF8InputStream() : EOF_(0xff), strm_()
{
}
-CUTF8InputStream::CUTF8InputStream(const smart_ptr<std::istream>& strm) : strm_(strm)
+CUTF8InputStream::CUTF8InputStream(const smart_ptr<std::istream>& strm) : EOF_(0xff), strm_(strm)
{
}
}
}
- return std::vector<unsigned char>(0xff);
+ return std::vector<unsigned char>(EOF_);
}
std::vector<unsigned char> CUTF8InputStream::read(int num)
// 指定された文字分だけ読みだしてくる。
// 途中で終了した場合、その文字の分だけunsigned charが減少すること
// になっている。
- std::vector<unsigned char> rtn;
- for (int i = 0; i < num; ++i)
+ // numが0の場合、必ず空のvectorが返される。
+
+ if (num == 0)
+ {
+ return std::vector<unsigned char>();
+ }
+
+ // eofの場合なら、この時点でeofが返るので、それで問題はない。
+ std::vector<unsigned char> rtn = this->read();
+ for (int i = 1; i < num && !strm_->eof(); ++i)
{
+ // 個数に到達するか、もしくはeofとなるまでは追加しつづける。
std::vector<unsigned char> tmp = this->read();
- if (tmp.size() > 0)
- {
- rtn.insert(rtn.end(), tmp.begin(), tmp.end());
- }
- else
- {
- // サイズより大きくなってしまうような場合には、そのまま抜けることにする。
- break;
- }
+ rtn.insert(rtn.end(), tmp.begin(), tmp.end());
}
+
return rtn;
}
return tmp;
}
+bool utakata::utf8::CUTF8InputStream::isEOF() const
+{
+ if (strm_->good())
+ {
+ return strm_->eof() ? true : false;
+ }
+ else
+ {
+ return false;
+ }
+}
//================================================================================
入力ストリームから、UTF-8のデータを指定した文字だけ読みだして
返す。
*/
+
+ const unsigned char EOF_;
+
public:
// 入力に利用するストリームは最初に渡される。
std::vector<unsigned char> peek();
-
+ // ファイルの終端に到達しているかどうかを返す。
+ // trueを返す場合、readの結果は常にEOF文字を返す。
+ bool isEOF() const;
+
private:
smart_ptr<std::istream> strm_;
#include <vector>
#include <string>
#include <functional>
+#include <algorithm>
+
#include "utf8.h"
#include "utf8_string.h"
return ch.getBytes()[0] == 0xff ? true : false;
}
+CUTF8String utakata::utf8_string::operator+(const CUTF8String& lh, const CUTF8String& rh)
+{
+ // 双方をコピーして加算して返す。凄い負荷が高い。
+ CUTF8String str(lh);
+ str += rh;
+ return str;
+}
+
//================================================================================
utakata::utf8_string::CUTF8String::CUTF8String() : chars_()
// 実体に代入する。代入が行われなかった場合、元のデータ
// は保存される。
void assign(const std::vector<unsigned char>& bytes);
+ void assign(const std::vector<CUTF8Char>& chars);
void assign(const CUTF8String& str);
// iteratorを取得する。
std::vector<CUTF8Char> chars_;
};
+ CUTF8String operator+(const CUTF8String& lh, const CUTF8String& rh);
+
// substringの実装を行う。
// [begin, end)までの文字を文字列として返す。
// endが渡されないか、0が渡された場合、beginから末尾までが返される。