How to convert source code to a xml based representation of the ast?

前端 未结 5 1460
囚心锁ツ
囚心锁ツ 2021-02-06 07:51

i wanna get a xml representation of the ast of java and c code. 3 months ago, i asked this question yet but the solutions weren\'t comfortable for me

  • srcml seems t
5条回答
  •  醉话见心
    2021-02-06 08:16

    srcml supports line number and column number. Here is an example using a java file called input.java (keep in mind srcml supports multiple languages, including C/C++) that contains the following:

    public class HelloWorld {
        public static void main(String[] args) {
            // Prints "Hello, World" to the terminal window.
            System.out.println("Hello, World");
        }
    }
    

    Then run srcml with the command to enable keeping track of this extra position information:

    srcml input.java --position
    

    It produces the following AST in an XML format with line number and column number embedded:

    
    public class HelloWorld {
        public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
        }
    }
    

    Reference: Documentation for srcml v0.9.5 (see srcml --help). I also use srcml frequently, including this feature to obtain position information.

提交回复
热议问题