rljacobson / FoxySheep

Compiler Technologies for Mathematica/Wolfram Language.
BSD 2-Clause "Simplified" License
36 stars 3 forks source link

July 15, 2020

I am grateful to Rocky Bernstein for breathing new life into FoxySheep in the form of a Python package. FoxySheep continues to evolve with Rocky's help at its new home on GitHub. This repository, the original, has suffered a little bit rot, but it feels right to leave it here as it is in case someone is interested in the Java target or has a use for it in its current state, prior to its evolution under a more focused vision.

Sincerely,

Robert Jacobson


What is FoxySheep?

FoxySheep is a collection of compiler technologies for Wolfram Language*. In particular, FoxySheep...

If you are here looking for a Wolfram Language parser for your project, jump down to Similar Projects.

*In this document, Wolfram Language refers to the programming language used in Mathematica (and some other Wolfram Research products), and Mathematica refers to the computer algebra system (or its kernel) produced by Wolfram the company. FoxySheep and its author(s) are not affiliated with Wolfram.

Motivation and Goals

For the Wolfram Language parser, I wanted something that is both fully functional and easy for students to understand, use in their own projects, modify, and contribute to. ANTLR4 is the perfect choice to achieve these goals. ANTLR4 produces parsers for Java, C#, Python 2&3, JavaScript, Go, C++, and Swift. The FoxySheep ANTLR4 grammars are language agnostic while the FullForm emitter comes in both Java and Python flavors. It would be easy to add support for another language.

For the Wolfram Language to Python translator, the goal is to be useful. My standard for usefulness is, it is sufficiently functional and easy to use that people, students especially, would want to use it to write simple programs in a Jupyter or Sage notebook.

Finally, for FoxySheep as a whole, my goal is that the project is helpful for students who are learning about compiler construction or Wolfram Language and helpful for me to learn how to teach those topics.

Possible Uses for FoxySheep

You can use it to...

FoxySheep doesn't...

But nothing is stopping you from using FoxySheep in your own project to do the above!

Building

This section is incomplete.

You will need ANTLR4 installed and available in your path. To check this, check that you can run antlr4 in a terminal.

Python target

You will need the ANTLR4 Python runtime somewhere in your site-packages. To check this, run python -c "import antlr4" in a terminal and make sure you don't get an ImportError.

To generate the Python target:

cd python_target
make

Project Status

FoxySheep is in heavy development.

The FoxySheep parser has complete coverage of non-box-related language features, and sketchy untested coverage of box-related features. While it is a goal of the project, FoxySheep does not always have identical behavior to Mathematica for the language constructs that it implements.

The FoxySheep translator is not yet functional.

Phase 1 - The Parser

The table below summarizes the status of planned features of Phase 1.

Feature Status Comments
Parses major language constructs complete
Parses box-related constructs started Low priority.
Java target complete Target language dependent components of the parser written in java.
Python target complete Target language dependent components of the parser written in python.
FullForm emitter (java) complete
FullForm emitter (python) complete
Develop test suite not started
Translator to another HIL started This is Phase 2 of development. See doc/TranslateToPythonNotes.md

Phase 2

The table below summarizes the status of planned features of Phase 2. See Notes on Wolfram Language to Python Translation and the Translator Roadmap for the most up-to-date status information.

Feature Status Comments
Skeleton of AST node types and construction started
Passes: Create Scopes and Verify Argument Patterns not started
Identify math expressions. not started
Transformations: Flatten, Thread Listables, Unwrap Iterated Functions not started
Passes: Convert [For | Do | NestWhile | FixedPoint | etc.] to While not started
Pass: Check Types not started
Python Emitter not started
AST-based FullForm Emitter not started

Contributing

See CONTRIBUTING.md.

Similar Projects

Here's what the open source Wolfram Language parser landscape looks like:

Authors and License

Author(s): Robert Jacobson

License: BSD license. See the file LICENSE.txt for details.