How to analyze Java source files with Clojure

后端 未结 2 1898
遇见更好的自我
遇见更好的自我 2021-01-18 21:16

I\'m trying to analyze Java source files with Clojure but I couldn\'t find a way to do that.

First, I thought using Eclipse AST plugin(by copying necessary JAR\'s to

2条回答
  •  灰色年华
    2021-01-18 21:44

    ... and it doesn't compile with latest ANTLR ...

    I could not reproduce that.

    Using ANTLR v3.2, I got some warnings, but no errors. Using both ANTLR v3.3 and v3.4 (latest version), I have no problems generating a parser.

    You didn't mention how you're (trying) to generate a lexer/parser, but here's how it works for me:

    java -cp antlr-3.4.jar org.antlr.Tool Java.g
    

    EDIT 1

    Here's my output when running the commands:

    ls
    wget http://www.antlr.org/download/antlr-3.4-complete.jar
    wget http://openjdk.java.net/projects/compiler-grammar/antlrworks/Java.g
    java -cp antlr-3.4-complete.jar org.antlr.Tool Java.g
    ls
    

    enter image description here

    As you can see, the .java files of the lexer and parser are properly created.

    EDIT 2

    Instead of generating a parser yourself (from a grammar), you could use an existing parser like this one (Java 1.5 only AFAIK) and call it from your Clojure code.

提交回复
热议问题