To download srcML, go to srcML.org and download the installer for your platform. For example, on Ubuntu (and this includes WSL in Windows):
- Download the debian package. Note: curl may not be installed
curl -L -O http://131.123.42.38/lmcrs/v1.0.0/srcml_1.0.0-1_ubuntu18.04.deb
- Install srcml
apt-get install ./srcml_1.0.0-1_ubuntu18.04.deb
- Verify install
srcml --version
with the output:
srcml 1.0.0
libsrcml 1.0.0
libarchive 3.4.0
- Directly create srcML for a statement:
srcml --text='\nstr = "Hello World!";\n' --language C++ --archive -o str.xml
To view the srcML:
cat str.xml
with the output (may have to scroll right):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<unit xmlns="http://www.srcML.org/srcML/src" revision="1.0.0">
<unit revision="1.0.0" language="C++" hash="ffa860933a5dca89d01a331e62b47431bb3ed325">
<expr_stmt><expr><name>str</name> <operator>=</operator> <literal type="string">"Hello World!"</literal></expr>;</expr_stmt>
</unit>
</unit>
About this example:
- Escaped newlines in the text, i.e.,
\n
, are converted to newlines in the srcML file. - The option
--archive
, necessary for a single input file or direct text, creates a srcML archive. The srcFacts program is designed to run on srcML archives - The option
--language
is required for direct text input so srcML knows the programming language of the code. srcML supports C++, C, Java, and C#
To run your program with a srcML file you created
./srcFacts < str.xml
To run your program directly from an example
srcml --text='\nstr = "Hello World!";\n' --language C++ --archive | ./srcFacts
- Create a srcML file from an individual source code file:
srcml srcFacts.cpp --archive -o srcFacts.cpp.xml
- Create srcML file for a project in a directory:
srcml . -o srcFacts.cpp.xml
- Convert srcML back to source code (for a single file)
srcml srcFacts.cpp.xml -o srcFacts2.cpp