f



List Java keywords from within Java?

How can I list Java keywords from within Java?

You know.. if, else, void, class..

I had a look over System and Class docs but
could see nothing helpful.  I want to highlight
the keywords in source, the lazy way.

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site




0
andrew64 (796)
1/2/2004 8:32:29 AM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

3 Replies
235 Views

Similar Articles

[PageSpeed] 22

"Andrew Thompson" wrote:

> How can I list Java keywords from within Java?
> 
> You know.. if, else, void, class..

You have to enumarate them yourself. AFAIK there is nothing in the 
public API which has a list of the keywords. Of course, the compiler 
must have a list, but that is compiler internal. 

You can get an official list out of the JLS.

<quote>
3.9 Keywords
The following character sequences, formed from ASCII letters, are 
reserved for use as keywords and cannot be used as identifiers (�3.8):

Keyword: one of
	abstract    default    if            private      this
	boolean     do         implements    protected    throw
	break       double     import        public       throws
	byte        else       instanceof    return       transient
	case        extends    int           short        try
	catch       final      interface     static       void
	char        finally    long          strictfp     volatile
	class       float      native        super        while
	const       for        new           switch
	continue    goto       package       synchronized

The keywords const and goto are reserved, even though they are not 
currently used. This may allow a Java compiler to produce better error 
messages if these C++ keywords incorrectly appear in programs. 

While true and false might appear to be keywords, they are technically 
Boolean literals (�3.10.3). Similarly, while null might appear to be a 
keyword, it is technically the null literal (�3.10.7). 
</quote>



0
speechless (234)
1/2/2004 8:43:23 AM
"Harald Hein" <speechless@gmx.de> wrote in message
news:Xns946462DC549FAhhtoken@194.97.5.11...
> "Andrew Thompson" wrote:
>
> > How can I list Java keywords from within Java?
.....
> Keyword: one of
> abstract    default    if            private      this.......

Thank you kindly, ..updates to my
code displayer soon.


0
andrew64 (796)
1/2/2004 4:10:45 PM
"Andrew Thompson" <andrew64@bigNOSPAMpond.com> wrote in message
news:9KgJb.74831$aT.20453@news-server.bigpond.net.au...
> "Harald Hein" <speechless@gmx.de> wrote in message
> news:Xns946462DC549FAhhtoken@194.97.5.11...
> > "Andrew Thompson" wrote:
...
> Thank you kindly, ..updates to my
> code displayer soon.

How soon is now?
http://www.physci.org/launcher.jsp   :)

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


0
andrew64 (796)
1/2/2004 4:49:32 PM
Reply: