Looking for a standalone Java source code parser

Aaron Lewis the.warl0ck.1989 at gmail.com
Tue Oct 21 03:14:06 UTC 2014

Hi, list,

I took a look at ANTLR first, and I did this:

wget http://www.antlr.org/download/antlr-4.2-complete.jar
wget https://raw.githubusercontent.com/antlr/grammars-v4/master/java/Java.g4

Then I created a simple Java file:
import java.io.*;

public class Foo {
    public static void main (String[] args)


It compiles with javac, so I moved to ANTLR:
%> java -jar antlr-4.2-complete.jar Foo.java
error(50): /run/shm/antlr/Foo.java:1:0: syntax error: 'import' came as
a complete surprise to me
error(50): /run/shm/antlr/Foo.java:1:11: syntax error: mismatched
input '.' expecting SEMI

Hmm, I think the g4 file I downloaded is the official one, so I must
have done something wrong.
Anyone know how to correct that?

On Tue, Oct 21, 2014 at 5:43 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> There's an ANTLR grammar in the JLS, if this helps.
> On 10/20/2014 3:09 AM, Aaron Lewis wrote:
>> Hi,
>> I'm looking for a parser that parses Java source code, is there any
>> recommend ones?

Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print:   9F67 391B B770 8FF6 99DC  D92D 87F6 2602 1371 4D33

More information about the discuss mailing list