...
artifact | transformation | artifact |
|---|---|---|
source (Hellohello.groovy) | GroovyLexer | antlr tokens |
antlr tokens | GroovyRecognizer | antlr ast |
antlr ast | AntlrParserPlugin | groovy ast |
groovy ast | AsmClassGenerator | bytecode (Hellohello.class) |
Note1 groovy.g is used to generate GroovyLexer and GroovyRecognizer
Note2 GroovyRecognizer is sometimes easier to understand in its syntax diagram form
Note3 AntlrParserPlugin source available.
Example
For these examples let's assume the file Hellohello.groovy contains
| Code Block |
|---|
class Hello {
static void main(args) {
println "hello world"
}
}
|
...
To view the antlr tokens that the source code has been broken into you need to do the following in groovy-core subdirectory
| Code Block |
|---|
java -cp
target/install/embeddable/groovy-all-1.6-beta-2.jar
org.codehaus.groovy.antlr.LexerFrame
|
...
To view the antlr AST that the recognized tokens have built
| Code Block |
|---|
java -cp
target/install/embeddable/groovy-all-1.6-beta-2.jar
org.codehaus.groovy.antlr.Main
-showtree Hello.groovy
|
...
To view the Groovy AST that is one step closer to the generated bytecode you can generate Hellohello.groovy.xml using these unix commands.
This can be generated by changing the groovy.ast system property. By doing this we can diff the generated Groovy AST artifacts for debugging and migration purposes.
| Code Block |
|---|
$ export JAVA_OPTS="-Dgroovy.ast=xml"
$ groovyc Hello.groovy
Written AST to Hello.groovy.xml
|
...
One interesting bytecode viewer is jclasslib which renders Hellohello.class in this manner...

Decompiling bytecode back to Java
If, however, you are bamboozled by bytecode... The easiest to grok mechanism for reading the compiled code is to use a tool like JAD to decompile the Hellohello.class into a readable Hellohello.java
