我测试了这个例子(lex.java),但它只给了我一个输出。
我作为读者给出了这篇文章:
public class LexeTest{ private int a = 14; }
nextToken ()函数是:
public Category nextToken () {
if (inp.findWithinHorizon (tokenPat, 0) == null)
return Category.EOF;
else {
lastLexeme = inp.match ().group (0);
if (inp.match ().start (1) != -1)
return nextToken ();
else if (inp.match ().start (2) != -1)
return Category.IDENT;
else if (inp.match ().start (3) != -1)
return Category.NUMERAL;
Category result = tokenMap.get (lastLexeme);
if (result == null)
return Category.ERROR;
else
return result;
}
}
isdie主要方法:
System.out.println(lexeObject.nextToken());
输出是:
标识
为什么?但文本文件包含多个关键字?有谁知道是什么问题?