Sean Brennan, John McGinness, Zachary Sample, James Tompkins
Our project is a parser designed to parse Python3 syntax. It does not cover all parts of Python3's lexical analysis, just the parts required for the project that are in the python_test_code.py
test code provided (so no floats, etc).
The very first thing you will want to do is ensure you have Java installed on your machine.
Following the official ANTLR documentation, start by installing ANTLR on your machine. The latest version as of writing this documentation is 4.9.2
.
After installation, we can now run the ANTLR parsing tool! Grammar files have the extension *.g4
and to give a general idea of the syntax/form of a grammar file, we included the Hello.g4
grammar file provided in their documentation for testing. Just like it's stated in the "A First Example" portion of the documentation linked prior, you can run the ANTLR tool on a grammar file in the command line by typing antlr4 Grammer.g4
. This will generate the lexer, parser, etc files. We now need to compile these Java files. You can call the Java compiler from the command line like so: javac *.java
. Note that this will compile every .java
file present in the directory.
First, ensure you have Maven, and GraphViz installed.
To compile the project run make
, this will clean and build the project in maven. make test
will build and run the program with the test python code provided in the assignment.
To manually compile everything, run maven clean
, mvn package
to install the dependencies and build the project.
Run java -jar target/parser-VERSION.jar inFile.py outFile.dot outImage.png
to run the project. The version number is printed during the build process.
The optional first argument specifies a python file to parse. If a second argument is provided, the output will be printed to the given file. The file does not have to exist. A Third argument will specify the path to the output tree image.
If no arguments are provided you can pass code via stdin. End the input using ctrl+d
. The default output file if not specified is tree.dot
. The default image output is tree.png
.
- if/else blocks
- Line 98
- Variable definitions
- Line 134
- while & for loops
- Line 94 & 95
- Arithmetic operators (+, -, *, /, %, ^)
- Line 113 & 114
- Assignment operators (=, +=, -=, *=, /=, ^=, %=)
- Line 99
- Conditional statements (<, <=, >, >=, ==, !=, and, or, not)
- Line 115
- Support for comments
- Line 154
- Syntax error message
- Visualization of parse tree (Graphviz)
- Originally Sean was looking into using the TestRig/grun feature that's built into ANTLR, but we ended up opting for Graphviz instead with Zach leading its development.
After completing the "Getting Started" section, run make run
in the terminal in the root directory of the project. You will then be prompted to enter the input which can be terminated with ctrl-D
on Unix or ctrl-Z + Enter Key
on Windows.
Java ANTLR ANTLR GitHub Python3 Lexical Analysis Python3 Expressions Microsoft Regular Expressions