我打算从 java 字节码生成解析树。典型的字节码如下,
public class org.scandroid.testing.InvokeCallArgTest extends org.scandroid.testing.SourceSink{
public org.scandroid.testing.InvokeCallArgTest();
Code:
0: aload_0
1: invokespecial #8; //Method org/scandroid/testing/SourceSink."<init>":()V
4: return
public static java.lang.String invokeCallArgSourceSpec();
Code:
0: iconst_1
1: newarray char
3: astore_0
4: aload_0
5: invokestatic #16; //Method org/scandroid/testing/SourceSink.load:([C)V
8: new #20; //class java/lang/String
11: dup
12: aload_0
13: invokespecial #22; //Method java/lang/String."<init>":([C)V
16: areturn
public static int invokeCallArgSourceSpecInt();
Code:
0: iconst_1
1: newarray char
3: astore_0
4: aload_0
5: invokestatic #16; //Method org/scandroid/testing/SourceSink.load:([C)V
8: aload_0
9: arraylength
10: ireturn
public static void invokeCallArgSinkSpecInt(int);
Code:
0: iload_0
1: invokestatic #30; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
4: invokestatic #36; //Method org/scandroid/testing/SourceSink.sink:(Ljava/lang/Object;)V
7: return
public static void invokeCallArgSinkSpecBiInt(int, int);
Code:
0: iload_0
1: iload_1
2: iadd
3: invokestatic #30; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
6: invokestatic #36; //Method org/scandroid/testing/SourceSink.sink:(Ljava/lang/Object;)V
9: return
}
我的目标是生成解析树或抽象语法树。我打算使用 flex 和 bison 组合。只是想知道这将是一个正确的方法吗?我应该从头开始还是有其他工具可用于处理从字节码创建 AST?