I am creating a program with ANTLR where I ask the user to enter some Java code and it splashes out the equivalent C # code. In my program, I ask the user to enter Java code and then parse it. So far, I assumed that they would introduce something that would be parsed as a valid compilation unit by itself, for example. sort of
package foo;
class A { ... }
class B { ... }
class C { ... }
However, this is not always the case. They can simply enter the code from within the class:
public void method1() {
...
}
public void method2() {
...
}
Or inside the method:
System.out.print("hello ");
System.out.println("world!");
Or even just an expression:
context.getSystemService(Context.ACTIVITY_SERVICE)
, parser.compilationUnit()
, , . , parser.expression()
parser.blockStatements()
. . , ?