Skip to main content

A simple parse tree utility package, with animated evaluations and configurable tree displays

Project description

Animated Parse Tree

Author Ethan Tan
Date 11/12/2021
Language Python (py)

Description

This package is meant to provide a high-level API for programmers to visualise parse trees. The eventual goal is to animate the tokenization (extracting symbols from a string), lexing (formatting the tokens), parsing (building the parse tree) and evaluation (reducing the parse tree).

Setup

It is extremely easy to integrate this package in your existing projects.

In the command line, run:

pip install animated_parse_tree

Sample Usage

Then in your Python source file / Jupyter Notebook, insert:

from animated_parse_tree import ParseTree

# Instantiate Parse Tree Object
t = ParseTree()

# Read a Mathematical String Expression (separated by singular whitespace characters)
t.read('1 + 2 * 3')

# Retrieve the Result
print('<<< Equation >>>')
print(t.expression, '=', t.evaluate(), end='\n\n')

# Display the Parse Tree
print('<<< Parse Tree >>>')
print(str(t))

The output in the terminal will look something like this:

<<< Equation >>>
1 + 2 * 3 = 7.0

<<< Parse Tree >>>
   +
 ↙     ↘
1.0    *
     ↙   ↘
    2.0 3.0

Declaring Custom Operands/Operators

Refer to bundles.py

See Also

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

animated-parse-tree-0.0.9.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

animated_parse_tree-0.0.9-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file animated-parse-tree-0.0.9.tar.gz.

File metadata

  • Download URL: animated-parse-tree-0.0.9.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for animated-parse-tree-0.0.9.tar.gz
Algorithm Hash digest
SHA256 9f12c5ff3e6d3dc3879a89503d57caab2cd60d700f44ddc13b126b180994b39d
MD5 8a4fbb106dd7345303e9c2e5a2f925cc
BLAKE2b-256 90a51c6991b74387815446362f33fd27b2709ff20b6e4545f704e7d23c0ba14e

See more details on using hashes here.

File details

Details for the file animated_parse_tree-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: animated_parse_tree-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for animated_parse_tree-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 b42e6d229d1d810177bd743ac601c078a5d8510dce450859506c031176557c19
MD5 b08a89fdd1e3fd530ea5c9a1856e151b
BLAKE2b-256 a608b93e9e00bb54f31aa9a6004761789bc0faaa55975a6f93f85e3c31eddb22

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page