GithubHelp home page GithubHelp logo

bwiedermann / pratt-parser-blog-code Goto Github PK

View Code? Open in Web Editor NEW

This project forked from desmosinc/pratt-parser-blog-code

0.0 1.0 1.0 2.33 MB

The code to illustrate the pratt parser blog post for the desmos engineering blog.

License: MIT License

JavaScript 1.12% TypeScript 98.88%

pratt-parser-blog-code's Introduction

Maybe-Undefined or Definitely Type

This project started as an implementation of a lexer and Pratt parser for a simple language.

We turned this into the proof of concept for a Maybe-Undefined or Definitely (MUD) type to be added to Desmos' Computation Layer.

So, in addition to the lexer and Pratt parser, we added capabilities for functions, variables, conditional expressions, and many more types. We also added type checking, constant checking and evaluation, and MUD checking for the proof of concept.

Setup

Clone the repo, then run

npm install
node fuse.js

Then open http://localhost:4444/

Notes

If you wish to add negative numbers, make sure to use parentheses around the negative number, or it will not parse correctly.

The keywords WHEN and OTHERWISE can only be used inside conditional expression and will be parsed into Choose Nodes.

Functions will only parse if they are included in the list of built-in functions, which are as follows:

  • Sink(any type): the argument can be of any type but must either defined or error checked in a conditional expression
  • InputN(): represents a maybe-undefined source of input in number form
  • InputB(): represents a maybe-undefined source of input in boolean form
  • Inverse(number): computes the inverse a number as long as the argument is not 0
  • Sqrt(number): computes the square root of a number as long as the argument is not negative
  • IsDefined(any type): the argument can be of any type, returns a boolean

Variables must be lowercase.

Each call to InputN() or InputB() represents a new source of possibly undefined input.

pratt-parser-blog-code's People

Contributors

sarah-grade avatar lsanders99 avatar dlants avatar bwiedermann avatar

Watchers

James Cloos avatar

Forkers

harrismcc

pratt-parser-blog-code's Issues

Parse Error instead of Type Error

Parser throws an "unexpected end of tokens" error when presented with an incorrect 3 operand expression. This expression
1 + True + 2 should produce a type error instead.
Incorrect Parse Error

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.