const exp = new apgExp(grammar, '');
console.log();
console.log('Demonstrate true recursion - matching paired parentheses and more.');
console.log();
const str = 'find the matched parentheses (down 1(down 2(down 3(the middle)up 3)up 2)up 1)';
console.log('grammar:');
console.log(exp.source);
console.log();
console.log(` input: ${str}`);
const result = exp.exec(str);
if (result) {
txt = result.toText();
console.log(txt);
txt = exp.toText();
console.log(txt);
} else {
console.log(' result: null');
}
} catch (e) {
console.log(`EXCEPTION: ${e.message}`);
}
})();