Giter Club home page Giter Club logo

cl-prattler's Introduction

cl-prattler

This is a simple Pratt parser for mathematical expressions (easily extended to more complex expression types) based on this implementation of Pratt parsing - Simple Top-Down Parsing in Python.

This version generates an AST that can be plugged into a bigger AST scheme for parsing other kinds of entities besides expressions.

Build

CL-USER> (asdf:load-system "cl-prattler")

Run

CL-USER> (cl-prattler/main:main)

Sample Run

CL-USER> (cl-prattler/main:main)
1
#<(literal 1)>

CL-USER> (cl-prattler/main:main)
-99
#<(neg #<(literal 99)>)>

CL-USER> (cl-prattler/main:main)
+12
#<(pos #<(literal 12)>)>

CL-USER> (cl-prattler/main:main)
1 + +99
#<(add #<(literal 1)> #<(pos #<(literal 99)>)>)>

CL-USER> (cl-prattler/main:main)
11 + -99
#<(add #<(literal 11)> #<(neg #<(literal 99)>)>)>

CL-USER> (cl-prattler/main:main)
(1 + 2) * 3
#<(mul #<(add #<(literal 1)> #<(literal 2)>)> #<(literal 3)>)>

CL-USER> (cl-prattler/main:main)
1 + (2 * 3)
#<(add #<(literal 1)> #<(mul #<(literal 2)> #<(literal 3)>)>)>

CL-USER> (cl-prattler/main:main)
1 + 2 * 3
#<(add #<(literal 1)> #<(mul #<(literal 2)> #<(literal 3)>)>)>

CL-USER> (cl-prattler/main:main)
2 ^ 3 ^ 4
#<(pow #<(literal 2)> #<(pow #<(literal 3)> #<(literal 4)>)>)>

CL-USER> (cl-prattler/main:main)
12 + (2 - -12) + ((11 -2) *    3 + 12 / 2) ^ (11- 9)
#<(add #<(add #<(literal 12)> #<(sub #<(literal 2)> #<(neg #<(literal 12)>)>)>)> #<(pow #<(add #<(mul #<(sub #<(literal 11)> #<(literal 2)>)> #<(literal 3)>)> #<(div #<(literal 12)> #<(literal 2)>)>)> #<(sub #<(literal 11)> #<(literal 9)>)>)>)>

LICENCE

See LICENCE.

cl-prattler's People

Contributors

timmyjose avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.