Code Monkey home page Code Monkey logo

Comments (4)

jiggzson avatar jiggzson commented on August 18, 2024

At the moment no. I would like to point out that adding custom functions if quite easy. It's just a matter of extending the Math2 object in the core and then creating a link in the Parser object. For example let's say we wanted to add bitwise and operator functionality and we'll call the function "bitand"

//extend the Math2 object
Math2 = {
    ...
    bitand: function(a, b) {
        return a & b;
    }
}

//create a link in the Parser object. This accepts an array containing the mapped function 
//and the number of arguments it expects. Leave the first blank to use the default name
function Parser() {
    ...
    functions = this.function = {
        ...
        bitand: [ , 2] //2 because it expects 2 arguments
    }
}

//then just call it
nerdamer('bitand(5, 7)');

Would this solution suffice?

from nerdamer.

starfishmod avatar starfishmod commented on August 18, 2024

I guess I'm looking for the ability to do x & y and x<<7 without having to
make them functions :-)

On Aug 7, 2016 3:05 PM, "Martin Donk" [email protected] wrote:

At the moment no. I would like to point out that adding custom functions
if quite easy. It's just a matter of extending the Math2 object in the core
and then creating a link in the Parser object. For example let's say we
wanted to add bitwise and operator functionality and we'll call the
function "bitand"

//extend the Math2 object
Math2 = {
...
bitand: function(a, b) {
return a & b;
}
}
//create a link in the Parser object. This accepts an array containing the mapped function //and the number of arguments it expects. Leave the first blank to use the default namefunction Parser() {
...
functions = this.function = {
...
bitand: [ , 2] //2 because it expects 2 arguments
}
}
//then just call itnerdamer('bitand(5.7)');

Would this solution suffice?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#45 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAs6k9HELCAcC9oeQ2p0aVVa_aIpe3Ojks5qdWeugaJpZM4JebJM
.

from nerdamer.

jiggzson avatar jiggzson commented on August 18, 2024

This would require a little more effort since this would be a modification to the parser itself. I'm hoping to add the ability to add custom operators in future versions but that functionality isn't there at the moment.

from nerdamer.

jiggzson avatar jiggzson commented on August 18, 2024

I think this might actually solve your issue. A few minor modifications allows for support for additional operators. In your case this might help. Note that your compound operator limit is two characters. Anything above will have to be a function. Also it's up to you to define the handling of symbolic types.
This goes after loading nerdamer.

var core = nerdamer.getCore();
var _ = core.PARSER;
//see core source code for full explanation or parameters. In this case just know
//The first param is the operator character so the parser can recognize it
//The second is the name of the parser function that it maps to
//The third is the order 
//The third is if it's left associative. And the last is if it's a prefix operator
var Operator = core.Operator;
//create a blank operator so the operator knows it's an operator 
//because the parser only sees one character at a time
_.operators['<'] = new Operator('<');
//create the operator you want and we'll name it bitleft. It's up to you. Just make
//sure you call it the same as the function defined below
_.operators['<<'] = new Operator('<<', 'bitleft', 1, true, false);
//define the function
_.bitleft = function(a, b) {
    if(!a.isConstant() || !b.isConstant()) {
        //do something with symbolic types
    }
    return a << b;
};

from nerdamer.

Related Issues (20)

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.