lexical analysis gives only one output?
- by Caffè
I tested this example(lexe.java), but it gave me only one output.
I gave this text as a reader:
public class LexeTest{
private int a = 14;
}
And the nextToken() function is :
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 the main method:
System.out.println(lexeObject.nextToken());
output is :
IDENT
Why? but the textfile contains multiple keywords? Anyone know what's the problem?