lexical analysis gives only one output?
Posted
by
Caffè
on Stack Overflow
See other posts from Stack Overflow
or by Caffè
Published on 2013-11-07T09:18:12Z
Indexed on
2013/11/07
9:54 UTC
Read the original article
Hit count: 299
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?
© Stack Overflow or respective owner