Skip to content

Latest commit

 

History

History

python

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

YARS-PG Python parser

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.

Usage

You can skip steps 2 and 3 if you downloaded the YARS-PG Python parser from the releases.

  1. Prepare the environment:

Install antlr4-python3-runtime:

pip install -r requirements.txt
  1. Download the ANTRL4 Java binaries:
curl -O https://www.antlr.org/download/antlr-4.13.1-complete.jar
  1. Generate the Python target:
java -jar antlr-4.13.1-complete.jar -Dlanguage=Python3 -o /path/to/this/directory /path/to/grammar/YARSpg.g4
  1. 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

Notes

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).