ひとまずコンセプトをコードに落とす

minipythonの手書きLexerの実装案

class reserved_word {
private:
    string word;
public:
    reserved_word(string word);
    bool check_char(char intput);
};

class word_checker {
private:
    list<reserved_word> words;
public:
    void add_word(string word);
    void check_char(char input);
    bool has_alive_candidate();
    string successed_word();
};

word_checker reserved_word_checker;

reserved_word_checker.add_word("if");
reserved_word_checker.add_word("then");
reserved_word_checker.add_word("else");

while(isspace(istream.peek()) == false){
    reserved_word_checker.check_char(istream.next_char());
}

if (reserved_word_checker.has_alive_candidate()){
    return reserved_word_checker.successed_word();
}

とりあえずこんなかんじでプロトタイプを作ってみる。

歯医者行く。