Wednesday, February 23, 2005

Keywords are not identifiers


In Java, keywords are not identifiers, but tokens (with the exception of languages such as PostScript, where keywords are lists of rules.)


Louden (1997:31) say that keywords are fixed strings of letters and that identifiers are user-defined strings. Obviously keywords are defined in the grammar, and can't be user-defined strings. Therefore, keywords can't be identifiers.

The Java Grammar explicitly say that identifiers are not keywords or boolean literals or the null literal:

Identifier =
IdentifierChars - (Keyword | BooleanLiteral | NullLiteral) ;

The Java Grammar also say that both identifiers and keywords are tokens:

Token =
Identifier | Keyword | Literal | Separator | Operator ;


No comments: