Coder Social home page Coder Social logo

au.js's Introduction

au.js

计算数学表达式,一个小型解释器的示例,支持变量和操作符扩展。

repl

在线REPL https://mwc.github.io/au.js/repl.html

support

内建支持操作符

  • + 加,优先级值10
  • - 减,优先级值10
  • * 乘,优先级值100
  • / 除,优先级值100
  • % 求模,优先级值100
  • ^ 幂,优先级值100

APIs

constructor

au(input, variables);
  • input: 表达式字符串
  • variables: 变量
base
au('22*3');     // result: 66
use variables
au('15 + $a + 4', {
    a: 6
});     // result: 25

au.operator(operator, priority, handler)

  • operator 待扩展的操作符
  • priority 优先级值
  • handler 计算函数

注意:所有操作符仅支持二元操作,例如扩展 & 符号:

au.operator('&', 100, function (o1, o2) {
    return o1 & o2;
});

au('12&4');     // result: 4

扩展已存在的操作符,将被覆盖之。

au.js's People

Contributors

mwc avatar

Stargazers

 avatar Francis avatar Steven Weng avatar

Watchers

 avatar James Cloos 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.