- let intAdd = unaryOp('+', TokenType.I_ADD);
- let intSub = unaryOp('-', TokenType.I_SUB);
- let intMul = unaryOp('*', TokenType.I_MUL);
- let intDiv = unaryOp('/', TokenType.I_DIV);
- let lParen = unaryOp('(', TokenType.L_PAREN);
- let rParen = unaryOp(')', TokenType.R_PAREN);
- let lBracket = unaryOp('[', TokenType.L_BRACK);
- let rBracket = unaryOp(']', TokenType.R_BRACK);
- let lBrace = unaryOp('{', TokenType.L_BRACE);
- let rBrace = unaryOp('}', TokenType.R_BRACE);
- let comma = unaryOp(',', TokenType.COMMA);
- let dot = unaryOp('.', TokenType.DOT);
- let colon = unaryOp(':', TokenType.COLON);
- let semicolon = unaryOp(';', TokenType.SEMI_C);
- let at = unaryOp('@', TokenType.AT);
- let hash = unaryOp('#', TokenType.HASH);
- let set = unaryOp('=', TokenType.SET);
- let greaterthan = unaryOp('>', TokenType.GT);
- let lessthan = unaryOp('<', TokenType.LE);
- let term = (token_list, x) => {
- var ln = 1;
- var col = 0;
- var old_x = x;
- let term_list = [float, newline, space, integer, str, id,
- floatAdd, floatSub, floatMul, floatDiv,
- intAdd, intSub, intMul, intDiv,
- eq, ge, le, rightArrow,
- lParen, rParen, lBracket, rBracket, lBrace, rBrace,
- comma, dot, colon, semicolon, at, hash,
- set, greaterthan, lessthan];
- let term_aux = term_list.reduce((x, y) => orDo(x, y));
- var new_x = thenDo(old_x, term_aux);
- while (new_x._tag != "None") {
- if (new_x.value.matched_type != TokenType.NL) {
- col += new_x.value.matched.length;
- token_list.push({ text: new_x.value.matched,
- type: new_x.value.matched_type,
- ln: ln,
- col: col });
+ return ret;
+};
+let facAux2 = callees;
+let facAux = orDo(facAux1, facAux2);
+/** fac = single facAux | single
+ * Issue1 to be fixed.
+ */
+let fac1 = (x) => {
+ var ret = thenDo(thenDo(toSome(x), single), facAux);
+ if (ret._tag == "Some") {
+ console.log("777" + repr(tkTreeToSExp(ret.value.ast)));
+ ret.value.ast = [applyToken, ret.value.ast[ret.value.ast.length - 2],
+ ret.value.ast[ret.value.ast.length - 1]];
+ ret.value.ast;
+ rearrangeTree(ret.value.ast);
+ console.log("888" + repr(tkTreeToSExp(ret.value.ast)));
+ }
+ return ret;
+};
+let fac2 = single;
+let fac = orDo(fac1, fac2);
+/**
+ * rearrangeTree : for applyToken subtree from right-combination to
+ * left-combination
+ * @input x a ast
+ * @return another ast
+ */
+function rearrangeTree(x) {
+ if (x !== undefined) {
+ for (var i = 1; i < x.length; i++) {
+ rearrangeTree(x[i]);
+ }
+ console.log("@@" + repr(x[0]));
+ if (x[0] == applyToken) {
+ if (Array.isArray(x[2]) && x[2][0] == applyToken) {
+ let rl = rearrangeTree(x[2][1]);
+ let rr = rearrangeTree(x[2][2]);
+ let l = rearrangeTree(x[1]);
+ x[0] = applyToken;
+ x[1] = [applyToken, l, rl];
+ x[2] = rr;
+ console.log("@@==" + repr(x));
+ return x;