@openreasoning/parser
v0.1.0
Published
Parser for various forms of logical statements
Downloads
7
Readme
parser.js
A parser to be used in logic programs.
This parses formulas within three styles (prefix, infix, and functional) returning a tree structure of the captured elements.
Installation
npm install @openreasoning/parser
Usage
import {prefixParser, infixParser, functionalParser, Node} from '@openreasoning/parser'
let parsed = prefixParser('(and a b)');
let parsed2 = infixParser('(a and b)');
let parsed3 = functionalParser('and(a, b)');
function isEqual(a: Node, b: Node): bool {
if (a.value !== b.value || a.children.length !== b.children.length) {
return false;
}
for (let i = 0; i < a.children.length; i++) {
if (!isEqual(a.children[i], b.children[i])) {
return false;
}
}
return true;
}
console.log(isEqual(parsed, parsed2)); // true
console.log(isEqual(parsed2, parsed3)); // true
License
This is uses the MIT License