>>868
Cで書こうと思って途中でめんどくさくなったんでJavaScriptで
書いたけど大体こんな感じじだろ。トリッキーなテクに頼らなくても
別段書きにくいor読みにくいことはないと思うが。

function tokenize(inStr) {
var i = 0; var c = null; var tkn;
function step() { c = (inStr.length <= i) ? null : inStr[i++]; }
function push() { tkn += c; step(); }
function skipWhiteSpace() { while (c == ' ' || c == '¥t' || c == '¥n') { step(); } }
function numberLiteral() { push(); while (c >= '0' && c <= '9') { push(); } }
function comment() {
push();
while (c) { if (c == '*') { push(); if (!c) { break; } if (c == '/') { push(); break; } }
push();
}
}
function identifier() { push(); while (c >= 'a' && c <= 'z') { push(); } }
function scan() {
tkn = ""; skipWhiteSpace();
if (!c) { return false; }
if (c >= '0' && c <= '9') { numberLiteral(); return true; }
if (c >= 'a' && c <= 'z') { identifier(); return true; }
if (c == '(' || c == ')' || c == ',' || c == '*' || c == '{' || c == '}' || c == ';') { push(); return true; }
if (c == '/') { push(); if (c == '*') { comment(); return true; } else { return true; }}
return false;
}
var result = ""; step(); while (scan()) { result += tkn + "¥n"; } return result;
}
alert(tokenize("int main(int, char**){/*comment*/ return 0;}"));