Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 1.25 KB

README.md

File metadata and controls

54 lines (37 loc) · 1.25 KB

Abstract syntax tree for logic expressions

Build an AST (JSON object) from a logic expression string

Input

    const logicExpression = 'a AND b OR c';

Processing

    const bracketTree = new BracketTree(logicExpression);
    const logicTree = new LogicTree(bracketTree.nodes, bracketTree.text).getAst();

Output

    console.log(logicTree);
    
    {
      name: 'node0',
      content: 'a AND b OR c',
      orParams: [{
        text: 'a AND b',
        andParams: [{ name: 'a' }, { name: 'b' }]
      }, {
        text: 'c',
        andParams: [{ name: 'c' }]
      }]
    }

Entity-relationship model

Logic tree relationship

Logical operators

First-order logic

Binary boolean expresssion tree

Binary boolean expression tree

https://en.wikipedia.org/wiki/Binary_expression_tree