factor: (_) => {
var self = this;
var openParen = Parser.symbol(List.fromString("("));
var closeParen = Parser.symbol(List.fromString(")"));
return Parser.alt(Parser.flatMap(openParen)((_) => {
return Parser.flatMap(self.expr())((e) => {
return Parser.flatMap(closeParen)((_) => {
return Parser.pure(e);
})
});
}))(
Parser.flatMap(Parser.numeric())((numeric) => {
return Parser.pure(I.Exp.num(numeric));
})
)
},
evaluate: (inputString) => {
var parseResult = Parser.parse(Dentaku.expr())(List.fromString(inputString));
var env = Env.empty;
return parseResult.match({
empty: (_) => {
return "Invalid input";
},
cons: (head, tail) => {
return head.match({
cons: (ast, remainingInput) => {
return remainingInput.match({
empty: (_) => {
return I.evaluate(ast,env);
},
cons: (head, tail) => {
return PP.print(tail);