Usage: python yarspg_python_parser.py <path-to-yarspg-file> [-t|--tree]
where <path-to-yarspg-file> is the path to the .yarspg file you want to parse.
The optional -t or --tree argument prints the parse tree.
You can skip steps 2 and 3 if you downloaded the YARS-PG Python parser from the releases.
- Prepare the environment:
Install antlr4-python3-runtime
:
pip install -r requirements.txt
- Download the ANTRL4 Java binaries:
curl -O https://www.antlr.org/download/antlr-4.13.1-complete.jar
- Generate the Python target:
java -jar antlr-4.13.1-complete.jar -Dlanguage=Python3 -o /path/to/this/directory /path/to/grammar/YARSpg.g4
- Run the parser:
python yarspg_python_parser.py path/to/file.yarspg
Optionally, you can also print a parse tree:
python yarspg_python_parser.py path/to/file.yarspg --tree
python yarspg_python_parser.py path/to/file.yarspg -t
Python parser is much slower than the Java one because of the ANTLR's Python implementation. It is not recommended to use a Python parser for large files.
You may consider using the Java parser instead or try to build a C++ parser target and use it with Python (example: amykyta3/speedy-antlr-tool).