[antlr-interest] Error computing the FIRST set???

Ulrich Frank Ulrich.Frank at dlr.de
Fri Feb 17 02:44:38 PST 2006


Hello, me again.

I have a problem with the computation of the first set of a rule. I hope 
you can help me although it is a little difficult to explain.
Well, first the lexer grammar:

...
tokens {
    CIT = "ComplexItemType";
    ATTR = "Attribute" ;
}

IDENT options {testLiterals=true;} : (DIGIT | CHAR | DOT)+ ;

....

Then the parser grammar:

{
    private String first = "";
}

query :   { first=$FIRST.toString(); } "from" query2 ;
query2 : { first=$FIRST.toString(); } CIT query3 ;
query3 : { first=$FIRST.toString(); } "select" query4 ;
query4 : { first=$FIRST.toString(); } (ATTR)? query5 ;
query5 : { first=$FIRST.toString(); } "where" query6 ;
....


So first includes in the different cases the following
FIRST(query) = {"from"}
FIRST(query2) = {"ComplexItemType"}
FIRST(query3) = {"select"}
FIRST(query4) = {"where"}   <-------------- ERROR ????? I'm missing 
"Attribute"
FIRST(query5) = {"where"}

There is something more to explain but I think it will get to much (I 
subclass the generatet lexer class and modify the nextToken() method)).
The main problem is the following: The difference in using the tokens 
(CIT and ATTR) is that in the second case the usage is optional. In the 
case of query2 the FIRST set was computed correct but in the optional 
case query4 "Attribute" is missing. Is there a bug or what did I wrong? 
Please help.


More information about the antlr-interest mailing list