Solving Riddles with Prolog and ES6 Generators (2014)

Solving Riddles with Prolog and ES6 Generators (2014)

== ‘)’) { throw new SyntaxError(‘Expected , or ) in term but got ‘ + current); } if (current === ‘,’) { next(); // eat , } } next(); // eat ) return new Conjunction(args); } var functor = parseAtom(); if { if (functor === ‘_’) { return new Variable(‘_’); } // variable X in the same scope should point to the same object var variable = scope[functor]; if (! == ‘)’) { throw new SyntaxError(‘Expected , or ) in term but got ‘ + current); } if (current === ‘,’) { next(); // eat , } } next(); // eat ) return new Term(functor, args); } function parseRule() { var head = parseTerm(); if (current === ‘.’) var body; if (args.length === 1) { // body is a regular Term body = args[0]; } else { // body is a conjunction of all terms body = new Conjunction(args); } return new Rule(head, body); } next(); // start the tokens iterator return { parseRules: function() { var rules = []; while (!

Source: curiosity-driven.org