Autolev Parser (using ANTLR v4)

In this post, I shall discuss my project: Autolev Parser (using ANTLR v4). This is the timeline I am proposing. Please suggest any changes if required.


Finalize this after discussing things with the mentors.

Phase 1:

Weeks 1 and 2 (May 15 – May 28): Refactor the grammar and the preprocessing steps. Finish parsing the mathematical entities of Autolev.  Start off with parsing the symbolic dynamics part of Autolev. (Pull request #1)

Weeks 3 and 4 (May 29 – Jun 11): Work on parsing the symbolic dynamics part of Autolev using sympy.physics.vector and sympy.physics.mechanics. (Pull request #2)


Phase 2:

Weeks 5 (Jun 12 – Jun 18): Work further on the symbolic dynamics part. Work on the more difficult parts of the parser ie translations which are quite indirect and require more code and tweaking as opposed to calling equivalent SymPy commands. (Pull request #3)

Weeks 6, 7 and 8 (Jun 19 – Jul 9): Work on parsing the solvers and visualization parts. Use sympy.solvers and numerical solvers from the SciPy stack to translate the algebraic, nonlinear and ODE solvers. Use pydy.codegen to solve the equations of motion numerically and use sympy.physics.units to manipulate the units before plugging the values in. Use matplotlib and pydy.viz to translate the plotting parts. (Pull request #4)


Phase 3:

Weeks 9, 10 and 11 (Jul 17 – Aug 6): Refactor and tie up all the things done earlier and work on writing lots of test cases and well documented examples. Run benchmarking tests and make sure the results obtained are correct. (Pull request #5)

Week 12: (Jul 10 – Jul 16) Implement the error handling and recovery mechanism discussed in the Design section.

Week 13 (Aug 6 – Aug 14): Wrap everything up. Refactor the code, tests and examples and do a cleanup. (Pull request #6)


Code Setup:

Now I shall discuss some of the technical details about how my code is setup. You can find the code on my Github here.

  1. The antlr_essentials directory contains the antlr jar file and some bat files. If you want to run antlr commands, first specify the classpath of this jar file in the commands prompt.
  2. The test files directory contains the example test files on which I run the code. The files example5.1-example5.9 are examples of the same names in the Autolev Tutorial.  I have also included whipple.txt which is the bicycle model Autolev code. The directory also contains png image files of the parse trees generated when the grammar is run on these test files.
  3. Autolev.g4 is the grammar file., and are files automatically generated by ANTLR. A listener is basically a tree walker which triggers events when it enters and exits a rule. One can use this mechanism by subclassing AutolevListener.
  4. The file contains the myListener class which simply subclasses AutolevListener. This is where I will be putting the majority of the parser code.
  5. The file initializes the parser, lexer and listener and is the file you would want to run. Running ‘python input.txt’ on the file input.txt which contains Autolev code would generate the parsed SymPy output in an output file of choice.
  6. The pydy_for_autolev_users.rst is a guide and I will keep updating it as I keep parsing more of the Autolev language.

I haven’t put much of an emphasis on code readability. Should this be an aspect to focus on? I am thinking the parsed output and the results are of primary concern. One reason I feel this way is because this isn’t core SymPy code and the project is niche and that the majority of code is based in ANTLR. Please tell me if you don’t think the same.


Status of the Project:

I have finished writing the grammar for the Autolev language. I am now partway through parsing the mathematical entities.

Parsing Mathematical Entities :
# Constants ✓
# Variables ✓
# Imaginary ✓
# MotionVariables ✓
# Specifieds ✓
# Expression reconstruction ✓
# Assignments ✓
# Math commands (deal with function calls) and expressions
# Reserved names and constants (T, Pi etc)
# Matrices

I have written code to parse the basic mathematical variable declarations such as constants, variables, specifieds etc.  I have also written code for expression reconstruction and assignment. I will now work all the math commands, reserved names and matrices. I will be handling vectors and dyadics in the physics part as sympy.physics.vector is more appropriate in the sense of Autolev and symbolic dynamics. Go over pydy_for_autolev_users.rst to get an idea of the different mathematical commands and physical entities. You can have a look at input1.txt and the parsed output in output1.txt in the test_files directory of autolev-parser on my Github.

I will get started with the symbolic dynamics part next once I am done with the mathematical entities.

Do you think I am headed in the right direction with the project? Please let me know what you think. Any feedback is much appreciated.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s