- ;
- 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 });
- }
- else {
- col = 0;
- ln += 1;
- token_list.push({ text: new_x.value.matched,
- type: new_x.value.matched_type,
- ln: ln,
- col: col });
- }
- old_x = toSome({ matched: "",
- remained: new_x.value.remained });
- new_x = thenDo(old_x, term_aux);
+ return a;
+};
+/**
+ * TODO: 12(13)(14) only parsed with only 12(13)
+ */
+/** single1 = tInt | "(" expr ")"*/
+let single1 = circumfix((x) => thenDo(thenDo(thenDo(tk.toSome(x), tLParen), expr), tRParen), "fac1");
+let single2 = tInt;
+let single = orDo(single1, single2);
+/** func = single | single "(" single ")"
+ * i.e.
+ *
+ * func = single | func_aux ( int )
+ *
+*/
+/** fac = single ["(" single ")"]? | single */
+let fac1Appliee = circumfix((x) => thenDo(thenDo(thenDo(tk.toSome(x), tLParen), tInt), tRParen), "fac1");
+let fac1 = (x) => {
+ let raw = thenDo(thenDo(toSome(x), single), OnceOrMoreDo(fac1Appliee));
+ if (raw._tag == "Some") {
+ var result = raw.value.ast[0];
+ let applyToken = { text: '%apply', ln: 0, col: 0 };
+ for (var i = 1; i < raw.value.ast.length; i++) {
+ result = [applyToken, result, raw.value.ast[i]];