[antlr-interest] ANTLR-based Java grammar for javac compiler

Sam Harwell sharwell at pixelminegames.com
Mon Nov 10 23:28:38 PST 2008


I was able to use the Java.g grammar to create a syntax highlighter in a
skeleton Visual Studio language service in about 45 minutes today. It
was very easy to use from the clean work on it! :)

The lexer goes from 19000+ to just over 11000 lines, and codegen time is
cut in half or better if you do the following:

The last alt in each of IdentifierStart and IdentifierPart prevent those
rules from evaluating as sets. Change the IDENTIFIER rule to this:

IDENTIFIER
	:	(IdentifierStart | IdentifierStart2) (IdentifierPart |
IdentifierPart2)*
	;

And move the last lines of IdentifierStart and IdentifierPart to the new
fragment rules IdentifierStart2 and IdentifierPart2 (they should no
longer be alts in IdentifierStart and IdentifierPart):

fragment
IdentifierStart2
	:	('\ud800'..'\udbff') ('\udc00'..'\udfff')
	;

fragment
IdentifierPart2
	:	('\ud800'..'\udbff') ('\udc00'..'\udfff')
	;

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Terence Parr
Sent: Monday, November 10, 2008 2:45 PM
To: antlr-interest Interest
Subject: [antlr-interest] ANTLR-based Java grammar for javac compiler

http://openjdk.java.net/projects/compiler-grammar/

Direct link to the grammar:

http://openjdk.java.net/projects/compiler-grammar/antlrworks/Java.g

USF MSCS student Yang Jiang built this as an intern for Sun.

Terence

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-addr
ess



More information about the antlr-interest mailing list