Coder Social home page Coder Social logo

expr2graph's Introduction

Expr2Graph

A Converter from Expression to Graph(dot)

test

Compile

  1. build using Stack

    stack build
  2. run with Stack

    stack run
  3. test with Stack

    stack test

Usage

An expression in each line, whose syntax is as below.

Syntax

We use syntax based on (Actually the same as by now) this CodeWars Kata which meas we Parse an function defined as below.

function   ::= '[' arg-list ']' expression

arg-list   ::= /* nothing */
                 | variable arg-list

expression ::= term
                 | expression '+' term
                 | expression '-' term

term       ::= factor
                 | term '*' factor
                 | term '/' factor

factor     ::= number
                 | variable
                 | '(' expression ')'

For example these functions below are OK

[ a b ] a*a + b*b
[ first second ] (first + second) / 2
[a b c]a*a+b*b+(a+b)*(a+c)/2

Output

NOTICE: This program DOES NOT generate any image format such as svg or jpeg but the content of an dot file, which can convert to an image file using Graphviz.

So you can use command like this to generate an image

echo "[a b] (a+b)/2" | stack run | dot -Tsvg > graph.svg

BTW this result is as below

output

Elements

Symbol Meaning
Circle Operator such as +,-,*,/
Box An Immediately number(only Integers for now)
Box3D The Index(beginning with 0) of an Argument

Known Bugs

  • When combining sub-trees, there are still some duplicate errors in graph ([a b] a*a + a*b + a*b + b*b as below)

    bug1

TODO-List

  • More operator such as ^
  • Some new feature like let...in...
  • Named function
  • Recursion support

expr2graph's People

Contributors

leoalex0 avatar

Watchers

 avatar  avatar

Forkers

shaoyy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.