Code Monkey home page Code Monkey logo

bonsaiblog's People

Contributors

ohbonsai avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

bonsaiblog's Issues

temp

let Parser = require("jison").Parser;

let grammar = {
    "comment": "Boolean Parser",

    "lex": {
        "rules": [

            // OPERATORS
            ["\\=",                                    "return '='           "],
            ["\\!\\=",                                 "return '!='          "],
            ["\\>\\=",                                 "return '>='          "],
            ["\\>",                                    "return '>'           "],
            ["\\<\\=",                                 "return '<='          "],
            ["\\<",                                    "return '<'           "],
            ["[I,i][N,n]",                             "return 'IN'          "],
            ["[L,l][I,i][K,k][E,e]",                   "return 'LIKE'        "],

            // CONDITIONALS
            ["[A,a][N,n][D,d]",                        "return '&'           "],
            ["\\&",                                    "return '&'           "],
            ["[O,o][R,r]",                             "return '|'           "],
            ["\\|",                                    "return '|'           "],
            ["[N,n][O,o][T,t]",                        "return '!'           "],
            ["\\!",                                    "return '!'           "],

            ["\\s+",                                   "/* skip whitespace */"],
            ["^\"([^\\\\\"]*(?:\\\\.[^\\\\\"]*)*)\"",  "return 'DBLSTRING'   "],
            ["^'([^\\\\']*(?:\\\\.[^\\\\']*)*)'",      "return 'STRING'      "],
            ["[0-9]+(?:\\.[0-9]+)?\\b",                "return 'NUMBER'      "],
            ["^`?([a-z_][a-z0-9_]{0,})`?",             "return 'LITERAL'     "],

            ["\\(",                                    "return '('           "],
            ["\\)",                                    "return ')'           "],






            ["\\*",                     "return '*'"],
            ["\\/",                     "return '/'"],
            ["-",                       "return '-'"],
            ["\\+",                     "return '+'"],
            ["\\^",                     "return '^'"],
            ["!",                       "return '!'"],
            ["%",                       "return '%'"],
            ["\\(",                     "return '('"],
            ["\\)",                     "return ')'"],
            ["PI\\b",                   "return 'PI'"],
            ["E\\b",                    "return 'E'"],
            ["$",                       "return 'EOF'"]
        ]
    },

    "operators": [
        ["left", "+", "-", "*", "/", "="],

        ["left", "^"],
        ["right", "!"],
        ["right", "%"],
        ["left", "UMINUS"]
    ],

    "bnf": {
        "expressions": [["e EOF",   "return $1"]],

        "e" :[
            ["STRING", "$$ = yytext.slice(1, yytext.length-1)"],
            ["DBLSTRING", "$$ = yytext.slice(1, yytext.length-1)"],
            ["LITERAL", "$$ = yytext"],
            ["e = e",  "$$ = '{' + $1 + ':' + $3 + '}'"],
            ["e + e",  "$$ = $1+$3"],
            ["e - e",  "$$ = $1-$3"],
            ["e * e",  "$$ = $1*$3"],
            ["e / e",  "$$ = $1/$3"],
            ["e ^ e",  "$$ = Math.pow($1, $3)"],
            ["e !",    "$$ = (function(n) {if(n==0) return 1; return arguments.callee(n-1) * n})($1)"],
            ["e %",    "$$ = $1/100"],
            ["- e",    "$$ = -$2", {"prec": "UMINUS"}],
            ["( e )",  "$$ = $2"],
            ["NUMBER", "$$ = Number(yytext)"],
            ["E",      "$$ = Math.E"],
            ["PI",     "$$ = Math.PI"]
        ]
    }
};

let parser = new Parser(grammar);

console.log(parser.parse(
    `
(a=b)=c
`
));

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.