예제 #1
0
파일: token.cpp 프로젝트: levelplane/circa
Name
TokenStream::consumeName(int match)
{
    Name value = name_from_string(nextStr().c_str());
    consume(match);
    return value;
}
예제 #2
0
파일: token.cpp 프로젝트: levelplane/circa
std::string
TokenStream::consumeStr(int match)
{
    std::string out = nextStr();
    consume(match);
    return out;
}
예제 #3
0
 string countAndSay(int n) {
   if(n<=0) return "";
   string re="1";
   for(int i=1;i<n;i++){
     re=nextStr(re);
   }
   return re;
 }
예제 #4
0
void TokenStream::dump()
{
    int lookbehind = 5;
    int lookahead = 15;
    for (int i=-lookbehind; i < lookahead; i++) {
        int index = position() + i;
        if (index < 0) continue;
        if (index >= length()) continue;

        std::cout << "[" << i << "] " << get_token_text(next(i).match)
            << " '" << nextStr(i) << "'" << std::endl;
    }
}
예제 #5
0
 void getNext(string s, unordered_set<string> &dict, unordered_set<string> &isVisited, unordered_set<string> &nextStrs) {
     for(int i = 0; i < s.length(); ++i) {
         string nextStr(s);
         for(char c = 'a'; c <= 'z'; ++c) {
             if(c != nextStr[i]) {
                 swap(c, nextStr[i]);
                 if(dict.count(nextStr) && !isVisited.count(nextStr)) {
                     nextStrs.insert(nextStr);
                     isVisited.insert(nextStr);
                 }
                 swap(c, nextStr[i]);
             } 
         }
     }
 }
예제 #6
0
파일: token.cpp 프로젝트: levelplane/circa
void
TokenStream::consume(int match)
{
    if (finished())
        throw std::runtime_error(std::string("Unexpected EOF while looking for ")
                                 + get_token_text(match));

    if ((match != -1) && next().match != match) {
        std::stringstream msg;
        msg << "Unexpected token (expected " << get_token_text(match)
            << ", found " << get_token_text(next().match)
            << " '" << nextStr() << "')";
        throw std::runtime_error(msg.str());
    }

    _position++;
}