From c0d29a127be54606344fce8de0ac62faa5be484e Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sat, 8 Jul 2023 22:21:52 -0500 Subject: [PATCH] feat: implement matrix indexing --- src/parser/LatexParser.g4 | 1 + src/parser/LatexParser.ts | 503 +++++++++++++++++-------------- src/parser/LatexParserVisitor.ts | 8 + src/parser/LatexToSympy.ts | 8 +- 4 files changed, 295 insertions(+), 225 deletions(-) diff --git a/src/parser/LatexParser.g4 b/src/parser/LatexParser.g4 index 8565f21b..9afb85fd 100644 --- a/src/parser/LatexParser.g4 +++ b/src/parser/LatexParser.g4 @@ -70,6 +70,7 @@ expr: id CARET_SINGLE_CHAR_ID_UNDERSCORE_SUBSCRIPT #exp | id CARET L_BRACE expr R_BRACE UNDERSCORE_SUBSCRIPT #exponent | expr (CARET_SINGLE_CHAR_ID | CARET_SINGLE_CHAR_NUMBER) #exponent | expr CARET L_BRACE expr R_BRACE #exponent + | expr UNDERSCORE L_BRACE expr COMMA expr R_BRACE #index | CMD_SQRT_INT #singleIntSqrt | CMD_SQRT L_BRACE expr R_BRACE #sqrt | BEGIN_MATRIX matrix_row (DOUBLE_BACKSLASH matrix_row)* END_MATRIX #matrix diff --git a/src/parser/LatexParser.ts b/src/parser/LatexParser.ts index 6277bcf4..df86325a 100644 --- a/src/parser/LatexParser.ts +++ b/src/parser/LatexParser.ts @@ -2194,7 +2194,7 @@ export default class LatexParser extends Parser { break; } this._ctx.stop = this._input.LT(-1); - this.state = 489; + this.state = 497; this._errHandler.sync(this); _alt = this._interp.adaptivePredict(this._input, 37, this._ctx); while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { @@ -2204,7 +2204,7 @@ export default class LatexParser extends Parser { } _prevctx = localctx; { - this.state = 487; + this.state = 495; this._errHandler.sync(this); switch ( this._interp.adaptivePredict(this._input, 36, this._ctx) ) { case 1: @@ -2254,8 +2254,8 @@ export default class LatexParser extends Parser { localctx = new ExponentContext(this, new ExprContext(this, _parentctx, _parentState)); this.pushNewRecursionContext(localctx, _startState, LatexParser.RULE_expr); this.state = 479; - if (!(this.precpred(this._ctx, 28))) { - throw this.createFailedPredicateException("this.precpred(this._ctx, 28)"); + if (!(this.precpred(this._ctx, 29))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 29)"); } this.state = 480; _la = this._input.LA(1); @@ -2273,8 +2273,8 @@ export default class LatexParser extends Parser { localctx = new ExponentContext(this, new ExprContext(this, _parentctx, _parentState)); this.pushNewRecursionContext(localctx, _startState, LatexParser.RULE_expr); this.state = 481; - if (!(this.precpred(this._ctx, 27))) { - throw this.createFailedPredicateException("this.precpred(this._ctx, 27)"); + if (!(this.precpred(this._ctx, 28))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 28)"); } this.state = 482; this.match(LatexParser.CARET); @@ -2286,10 +2286,32 @@ export default class LatexParser extends Parser { this.match(LatexParser.R_BRACE); } break; + case 6: + { + localctx = new IndexContext(this, new ExprContext(this, _parentctx, _parentState)); + this.pushNewRecursionContext(localctx, _startState, LatexParser.RULE_expr); + this.state = 487; + if (!(this.precpred(this._ctx, 27))) { + throw this.createFailedPredicateException("this.precpred(this._ctx, 27)"); + } + this.state = 488; + this.match(LatexParser.UNDERSCORE); + this.state = 489; + this.match(LatexParser.L_BRACE); + this.state = 490; + this.expr(0); + this.state = 491; + this.match(LatexParser.COMMA); + this.state = 492; + this.expr(0); + this.state = 493; + this.match(LatexParser.R_BRACE); + } + break; } } } - this.state = 491; + this.state = 499; this._errHandler.sync(this); _alt = this._interp.adaptivePredict(this._input, 37, this._ctx); } @@ -2317,7 +2339,7 @@ export default class LatexParser extends Parser { try { this.enterOuterAlt(localctx, 1); { - this.state = 492; + this.state = 500; _la = this._input.LA(1); if(!(_la===1 || _la===2)) { this._errHandler.recoverInline(this); @@ -2326,9 +2348,9 @@ export default class LatexParser extends Parser { this._errHandler.reportMatch(this); this.consume(); } - this.state = 493; + this.state = 501; this.u_expr(0); - this.state = 494; + this.state = 502; _la = this._input.LA(1); if(!(_la===69 || _la===70)) { this._errHandler.recoverInline(this); @@ -2361,7 +2383,7 @@ export default class LatexParser extends Parser { try { this.enterOuterAlt(localctx, 1); { - this.state = 496; + this.state = 504; _la = this._input.LA(1); if(!(_la===1 || _la===2)) { this._errHandler.recoverInline(this); @@ -2370,7 +2392,7 @@ export default class LatexParser extends Parser { this._errHandler.reportMatch(this); this.consume(); } - this.state = 497; + this.state = 505; localctx._numRows = this._input.LT(1); _la = this._input.LA(1); if(!(_la===83 || _la===84)) { @@ -2380,7 +2402,7 @@ export default class LatexParser extends Parser { this._errHandler.reportMatch(this); this.consume(); } - this.state = 498; + this.state = 506; _la = this._input.LA(1); if(!(_la===74 || _la===76)) { this._errHandler.recoverInline(this); @@ -2389,7 +2411,7 @@ export default class LatexParser extends Parser { this._errHandler.reportMatch(this); this.consume(); } - this.state = 499; + this.state = 507; localctx._numColumns = this._input.LT(1); _la = this._input.LA(1); if(!(_la===83 || _la===84)) { @@ -2399,7 +2421,7 @@ export default class LatexParser extends Parser { this._errHandler.reportMatch(this); this.consume(); } - this.state = 500; + this.state = 508; _la = this._input.LA(1); if(!(_la===69 || _la===70)) { this._errHandler.recoverInline(this); @@ -2430,17 +2452,17 @@ export default class LatexParser extends Parser { this.enterRule(localctx, 56, LatexParser.RULE_u_fraction); let _la: number; try { - this.state = 510; + this.state = 518; this._errHandler.sync(this); switch (this._input.LA(1)) { case 71: this.enterOuterAlt(localctx, 1); { - this.state = 502; + this.state = 510; this.match(LatexParser.U_CMD_FRAC); - this.state = 503; + this.state = 511; this.match(LatexParser.U_L_BRACE); - this.state = 504; + this.state = 512; _la = this._input.LA(1); if(!(_la===83 || _la===84)) { this._errHandler.recoverInline(this); @@ -2449,20 +2471,20 @@ export default class LatexParser extends Parser { this._errHandler.reportMatch(this); this.consume(); } - this.state = 505; + this.state = 513; this.match(LatexParser.U_R_BRACE); - this.state = 506; + this.state = 514; this.match(LatexParser.U_L_BRACE); - this.state = 507; + this.state = 515; this.match(LatexParser.U_NUMBER); - this.state = 508; + this.state = 516; this.match(LatexParser.U_R_BRACE); } break; case 72: this.enterOuterAlt(localctx, 2); { - this.state = 509; + this.state = 517; this.match(LatexParser.U_CMD_FRAC_INTS); } break; @@ -2503,7 +2525,7 @@ export default class LatexParser extends Parser { let _alt: number; this.enterOuterAlt(localctx, 1); { - this.state = 534; + this.state = 542; this._errHandler.sync(this); switch (this._input.LA(1)) { case 75: @@ -2512,13 +2534,13 @@ export default class LatexParser extends Parser { this._ctx = localctx; _prevctx = localctx; - this.state = 513; + this.state = 521; this.match(LatexParser.U_CMD_SQRT); - this.state = 514; + this.state = 522; this.match(LatexParser.U_L_BRACE); - this.state = 515; + this.state = 523; this.expr(0); - this.state = 516; + this.state = 524; this.match(LatexParser.U_R_BRACE); } break; @@ -2527,11 +2549,11 @@ export default class LatexParser extends Parser { localctx = new UnitDivideContext(this, localctx); this._ctx = localctx; _prevctx = localctx; - this.state = 518; + this.state = 526; this.match(LatexParser.U_CMD_FRAC); - this.state = 519; + this.state = 527; this.match(LatexParser.U_L_BRACE); - this.state = 522; + this.state = 530; this._errHandler.sync(this); switch (this._input.LA(1)) { case 71: @@ -2539,26 +2561,26 @@ export default class LatexParser extends Parser { case 78: case 79: { - this.state = 520; + this.state = 528; this.u_expr(0); } break; case 83: { - this.state = 521; + this.state = 529; this.match(LatexParser.U_ONE); } break; default: throw new NoViableAltException(this); } - this.state = 524; + this.state = 532; this.match(LatexParser.U_R_BRACE); - this.state = 525; + this.state = 533; this.match(LatexParser.U_L_BRACE); - this.state = 526; + this.state = 534; this.u_expr(0); - this.state = 527; + this.state = 535; this.match(LatexParser.U_R_BRACE); } break; @@ -2567,7 +2589,7 @@ export default class LatexParser extends Parser { localctx = new UnitNameContext(this, localctx); this._ctx = localctx; _prevctx = localctx; - this.state = 529; + this.state = 537; this.match(LatexParser.U_NAME); } break; @@ -2576,11 +2598,11 @@ export default class LatexParser extends Parser { localctx = new UnitSubExprContext(this, localctx); this._ctx = localctx; _prevctx = localctx; - this.state = 530; + this.state = 538; this.match(LatexParser.U_L_PAREN); - this.state = 531; + this.state = 539; this.u_expr(0); - this.state = 532; + this.state = 540; this.match(LatexParser.U_R_PAREN); } break; @@ -2588,7 +2610,7 @@ export default class LatexParser extends Parser { throw new NoViableAltException(this); } this._ctx.stop = this._input.LT(-1); - this.state = 558; + this.state = 566; this._errHandler.sync(this); _alt = this._interp.adaptivePredict(this._input, 42, this._ctx); while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { @@ -2598,20 +2620,20 @@ export default class LatexParser extends Parser { } _prevctx = localctx; { - this.state = 556; + this.state = 564; this._errHandler.sync(this); switch ( this._interp.adaptivePredict(this._input, 41, this._ctx) ) { case 1: { localctx = new UnitMultiplyContext(this, new U_exprContext(this, _parentctx, _parentState)); this.pushNewRecursionContext(localctx, _startState, LatexParser.RULE_u_expr); - this.state = 536; + this.state = 544; if (!(this.precpred(this._ctx, 4))) { throw this.createFailedPredicateException("this.precpred(this._ctx, 4)"); } - this.state = 537; + this.state = 545; this.match(LatexParser.U_CMD_CDOT); - this.state = 538; + this.state = 546; this.u_expr(5); } break; @@ -2619,13 +2641,13 @@ export default class LatexParser extends Parser { { localctx = new UnitExponentContext(this, new U_exprContext(this, _parentctx, _parentState)); this.pushNewRecursionContext(localctx, _startState, LatexParser.RULE_u_expr); - this.state = 539; + this.state = 547; if (!(this.precpred(this._ctx, 9))) { throw this.createFailedPredicateException("this.precpred(this._ctx, 9)"); } - this.state = 540; + this.state = 548; this.match(LatexParser.U_CARET); - this.state = 541; + this.state = 549; this.match(LatexParser.U_NUMBER); } break; @@ -2633,17 +2655,17 @@ export default class LatexParser extends Parser { { localctx = new UnitExponentContext(this, new U_exprContext(this, _parentctx, _parentState)); this.pushNewRecursionContext(localctx, _startState, LatexParser.RULE_u_expr); - this.state = 542; + this.state = 550; if (!(this.precpred(this._ctx, 8))) { throw this.createFailedPredicateException("this.precpred(this._ctx, 8)"); } - this.state = 543; + this.state = 551; this.match(LatexParser.U_CARET); - this.state = 544; + this.state = 552; this.match(LatexParser.U_L_BRACE); - this.state = 545; + this.state = 553; this.match(LatexParser.U_NUMBER); - this.state = 546; + this.state = 554; this.match(LatexParser.U_R_BRACE); } break; @@ -2651,13 +2673,13 @@ export default class LatexParser extends Parser { { localctx = new UnitFractionalExponentContext(this, new U_exprContext(this, _parentctx, _parentState)); this.pushNewRecursionContext(localctx, _startState, LatexParser.RULE_u_expr); - this.state = 547; + this.state = 555; if (!(this.precpred(this._ctx, 7))) { throw this.createFailedPredicateException("this.precpred(this._ctx, 7)"); } - this.state = 548; + this.state = 556; this.match(LatexParser.U_CARET); - this.state = 549; + this.state = 557; this.u_fraction(); } break; @@ -2665,24 +2687,24 @@ export default class LatexParser extends Parser { { localctx = new UnitFractionalExponentContext(this, new U_exprContext(this, _parentctx, _parentState)); this.pushNewRecursionContext(localctx, _startState, LatexParser.RULE_u_expr); - this.state = 550; + this.state = 558; if (!(this.precpred(this._ctx, 6))) { throw this.createFailedPredicateException("this.precpred(this._ctx, 6)"); } - this.state = 551; + this.state = 559; this.match(LatexParser.U_CARET); - this.state = 552; + this.state = 560; this.match(LatexParser.U_L_BRACE); - this.state = 553; + this.state = 561; this.u_fraction(); - this.state = 554; + this.state = 562; this.match(LatexParser.U_R_BRACE); } break; } } } - this.state = 560; + this.state = 568; this._errHandler.sync(this); _alt = this._interp.adaptivePredict(this._input, 42, this._ctx); } @@ -2721,29 +2743,31 @@ export default class LatexParser extends Parser { case 2: return this.precpred(this._ctx, 6); case 3: - return this.precpred(this._ctx, 28); + return this.precpred(this._ctx, 29); case 4: + return this.precpred(this._ctx, 28); + case 5: return this.precpred(this._ctx, 27); } return true; } private u_expr_sempred(localctx: U_exprContext, predIndex: number): boolean { switch (predIndex) { - case 5: - return this.precpred(this._ctx, 4); case 6: - return this.precpred(this._ctx, 9); + return this.precpred(this._ctx, 4); case 7: - return this.precpred(this._ctx, 8); + return this.precpred(this._ctx, 9); case 8: - return this.precpred(this._ctx, 7); + return this.precpred(this._ctx, 8); case 9: + return this.precpred(this._ctx, 7); + case 10: return this.precpred(this._ctx, 6); } return true; } - public static readonly _serializedATN: number[] = [4,1,89,562,2,0,7,0,2, + public static readonly _serializedATN: number[] = [4,1,89,570,2,0,7,0,2, 1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2, 10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17, 7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7, @@ -2779,157 +2803,160 @@ export default class LatexParser extends Parser { 8,25,1,25,1,25,1,25,1,25,1,25,1,25,3,25,451,8,25,1,25,1,25,1,25,1,25,5, 25,457,8,25,10,25,12,25,460,9,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,3,25, 469,8,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1, - 25,1,25,1,25,1,25,1,25,5,25,488,8,25,10,25,12,25,491,9,25,1,26,1,26,1,26, - 1,26,1,27,1,27,1,27,1,27,1,27,1,27,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1, - 28,3,28,511,8,28,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,3,29, - 523,8,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,3,29,535,8,29, - 1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1, - 29,1,29,1,29,1,29,1,29,1,29,5,29,557,8,29,10,29,12,29,560,9,29,1,29,2,82, - 89,2,50,58,30,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40, - 42,44,46,48,50,52,54,56,58,0,11,1,0,24,36,1,0,13,14,1,0,55,56,2,0,50,50, - 52,52,1,0,21,22,1,0,50,53,1,0,40,41,1,0,1,2,1,0,69,70,1,0,83,84,2,0,74, - 74,76,76,620,0,75,1,0,0,0,2,82,1,0,0,0,4,92,1,0,0,0,6,95,1,0,0,0,8,99,1, - 0,0,0,10,104,1,0,0,0,12,109,1,0,0,0,14,116,1,0,0,0,16,121,1,0,0,0,18,126, - 1,0,0,0,20,132,1,0,0,0,22,147,1,0,0,0,24,154,1,0,0,0,26,165,1,0,0,0,28, - 188,1,0,0,0,30,213,1,0,0,0,32,241,1,0,0,0,34,295,1,0,0,0,36,299,1,0,0,0, - 38,301,1,0,0,0,40,308,1,0,0,0,42,314,1,0,0,0,44,321,1,0,0,0,46,325,1,0, - 0,0,48,331,1,0,0,0,50,468,1,0,0,0,52,492,1,0,0,0,54,496,1,0,0,0,56,510, - 1,0,0,0,58,534,1,0,0,0,60,76,3,10,5,0,61,76,3,12,6,0,62,76,3,14,7,0,63, - 76,3,16,8,0,64,76,3,18,9,0,65,76,3,52,26,0,66,76,3,6,3,0,67,76,3,4,2,0, - 68,76,3,38,19,0,69,76,3,40,20,0,70,76,3,42,21,0,71,76,3,50,25,0,72,76,3, - 36,18,0,73,76,3,20,10,0,74,76,3,2,1,0,75,60,1,0,0,0,75,61,1,0,0,0,75,62, - 1,0,0,0,75,63,1,0,0,0,75,64,1,0,0,0,75,65,1,0,0,0,75,66,1,0,0,0,75,67,1, - 0,0,0,75,68,1,0,0,0,75,69,1,0,0,0,75,70,1,0,0,0,75,71,1,0,0,0,75,72,1,0, - 0,0,75,73,1,0,0,0,75,74,1,0,0,0,75,76,1,0,0,0,76,77,1,0,0,0,77,78,5,0,0, - 1,78,1,1,0,0,0,79,81,9,0,0,0,80,79,1,0,0,0,81,84,1,0,0,0,82,83,1,0,0,0, - 82,80,1,0,0,0,83,85,1,0,0,0,84,82,1,0,0,0,85,89,3,54,27,0,86,88,9,0,0,0, - 87,86,1,0,0,0,88,91,1,0,0,0,89,90,1,0,0,0,89,87,1,0,0,0,90,3,1,0,0,0,91, - 89,1,0,0,0,92,93,5,64,0,0,93,5,1,0,0,0,94,96,5,47,0,0,95,94,1,0,0,0,95, - 96,1,0,0,0,96,97,1,0,0,0,97,98,5,57,0,0,98,7,1,0,0,0,99,100,3,6,3,0,100, - 101,3,52,26,0,101,9,1,0,0,0,102,105,3,4,2,0,103,105,5,10,0,0,104,102,1, - 0,0,0,104,103,1,0,0,0,105,106,1,0,0,0,106,107,5,49,0,0,107,108,3,50,25, - 0,108,11,1,0,0,0,109,112,3,10,5,0,110,111,5,54,0,0,111,113,3,10,5,0,112, - 110,1,0,0,0,113,114,1,0,0,0,114,112,1,0,0,0,114,115,1,0,0,0,115,13,1,0, - 0,0,116,117,3,10,5,0,117,119,5,49,0,0,118,120,3,52,26,0,119,118,1,0,0,0, - 119,120,1,0,0,0,120,15,1,0,0,0,121,122,3,50,25,0,122,124,5,49,0,0,123,125, - 3,52,26,0,124,123,1,0,0,0,124,125,1,0,0,0,125,17,1,0,0,0,126,127,3,50,25, - 0,127,128,5,49,0,0,128,129,3,50,25,0,129,19,1,0,0,0,130,133,3,4,2,0,131, - 133,5,10,0,0,132,130,1,0,0,0,132,131,1,0,0,0,133,134,1,0,0,0,134,135,5, - 49,0,0,135,136,3,4,2,0,136,137,5,6,0,0,137,142,3,22,11,0,138,139,5,54,0, - 0,139,141,3,22,11,0,140,138,1,0,0,0,141,144,1,0,0,0,142,140,1,0,0,0,142, - 143,1,0,0,0,143,145,1,0,0,0,144,142,1,0,0,0,145,146,5,7,0,0,146,21,1,0, - 0,0,147,148,5,6,0,0,148,149,3,50,25,0,149,150,5,54,0,0,150,151,3,36,18, - 0,151,152,5,7,0,0,152,23,1,0,0,0,153,155,5,23,0,0,154,153,1,0,0,0,154,155, - 1,0,0,0,155,156,1,0,0,0,156,157,7,0,0,0,157,25,1,0,0,0,158,166,5,11,0,0, - 159,160,5,12,0,0,160,161,5,4,0,0,161,162,5,5,0,0,162,163,5,48,0,0,163,164, - 5,4,0,0,164,166,5,5,0,0,165,158,1,0,0,0,165,159,1,0,0,0,166,167,1,0,0,0, - 167,168,5,6,0,0,168,169,3,50,25,0,169,176,5,7,0,0,170,171,5,15,0,0,171, - 172,5,4,0,0,172,173,3,4,2,0,173,174,5,5,0,0,174,177,1,0,0,0,175,177,3,4, - 2,0,176,170,1,0,0,0,176,175,1,0,0,0,177,178,1,0,0,0,178,179,5,6,0,0,179, - 180,3,4,2,0,180,181,5,7,0,0,181,27,1,0,0,0,182,183,5,12,0,0,183,184,5,4, - 0,0,184,185,3,50,25,0,185,186,5,5,0,0,186,189,1,0,0,0,187,189,7,1,0,0,188, - 182,1,0,0,0,188,187,1,0,0,0,189,196,1,0,0,0,190,191,5,48,0,0,191,192,5, - 4,0,0,192,193,3,50,25,0,193,194,5,5,0,0,194,197,1,0,0,0,195,197,7,2,0,0, - 196,190,1,0,0,0,196,195,1,0,0,0,197,198,1,0,0,0,198,199,5,6,0,0,199,200, - 3,50,25,0,200,207,5,7,0,0,201,202,5,15,0,0,202,203,5,4,0,0,203,204,3,4, - 2,0,204,205,5,5,0,0,205,208,1,0,0,0,206,208,3,4,2,0,207,201,1,0,0,0,207, - 206,1,0,0,0,208,209,1,0,0,0,209,210,5,6,0,0,210,211,3,4,2,0,211,212,5,7, - 0,0,212,29,1,0,0,0,213,214,5,16,0,0,214,221,5,4,0,0,215,216,5,15,0,0,216, - 217,5,4,0,0,217,218,3,4,2,0,218,219,5,5,0,0,219,222,1,0,0,0,220,222,3,4, - 2,0,221,215,1,0,0,0,221,220,1,0,0,0,222,223,1,0,0,0,223,224,5,5,0,0,224, - 231,5,4,0,0,225,226,5,15,0,0,226,227,5,4,0,0,227,228,3,4,2,0,228,229,5, - 5,0,0,229,232,1,0,0,0,230,232,3,4,2,0,231,225,1,0,0,0,231,230,1,0,0,0,232, - 233,1,0,0,0,233,234,5,6,0,0,234,235,3,4,2,0,235,236,5,7,0,0,236,237,5,5, - 0,0,237,238,5,6,0,0,238,239,3,50,25,0,239,240,5,7,0,0,240,31,1,0,0,0,241, - 242,5,16,0,0,242,249,5,4,0,0,243,244,5,15,0,0,244,245,5,4,0,0,245,246,3, - 4,2,0,246,247,5,5,0,0,247,250,1,0,0,0,248,250,3,4,2,0,249,243,1,0,0,0,249, - 248,1,0,0,0,250,257,1,0,0,0,251,252,5,48,0,0,252,253,5,4,0,0,253,254,3, - 6,3,0,254,255,5,5,0,0,255,258,1,0,0,0,256,258,5,55,0,0,257,251,1,0,0,0, - 257,256,1,0,0,0,258,259,1,0,0,0,259,260,5,5,0,0,260,267,5,4,0,0,261,262, - 5,15,0,0,262,263,5,4,0,0,263,264,3,4,2,0,264,265,5,5,0,0,265,268,1,0,0, - 0,266,268,3,4,2,0,267,261,1,0,0,0,267,266,1,0,0,0,268,269,1,0,0,0,269,270, - 5,6,0,0,270,271,3,4,2,0,271,278,5,7,0,0,272,273,5,48,0,0,273,274,5,4,0, - 0,274,275,3,6,3,0,275,276,5,5,0,0,276,279,1,0,0,0,277,279,5,55,0,0,278, - 272,1,0,0,0,278,277,1,0,0,0,279,280,1,0,0,0,280,281,5,5,0,0,281,282,5,6, - 0,0,282,283,3,50,25,0,283,284,5,7,0,0,284,33,1,0,0,0,285,286,3,4,2,0,286, - 287,5,49,0,0,287,288,3,50,25,0,288,296,1,0,0,0,289,290,3,50,25,0,290,291, - 7,3,0,0,291,292,3,4,2,0,292,293,7,3,0,0,293,294,3,50,25,0,294,296,1,0,0, - 0,295,285,1,0,0,0,295,289,1,0,0,0,296,35,1,0,0,0,297,300,3,44,22,0,298, - 300,3,46,23,0,299,297,1,0,0,0,299,298,1,0,0,0,300,37,1,0,0,0,301,304,3, - 4,2,0,302,303,5,54,0,0,303,305,3,4,2,0,304,302,1,0,0,0,305,306,1,0,0,0, - 306,304,1,0,0,0,306,307,1,0,0,0,307,39,1,0,0,0,308,309,3,4,2,0,309,312, - 7,4,0,0,310,313,3,6,3,0,311,313,3,8,4,0,312,310,1,0,0,0,312,311,1,0,0,0, - 313,41,1,0,0,0,314,317,3,40,20,0,315,316,5,54,0,0,316,318,3,40,20,0,317, - 315,1,0,0,0,318,319,1,0,0,0,319,317,1,0,0,0,319,320,1,0,0,0,320,43,1,0, - 0,0,321,322,3,50,25,0,322,323,7,5,0,0,323,324,3,50,25,0,324,45,1,0,0,0, - 325,326,3,50,25,0,326,327,7,5,0,0,327,328,3,50,25,0,328,329,7,5,0,0,329, - 330,3,50,25,0,330,47,1,0,0,0,331,336,3,50,25,0,332,333,5,60,0,0,333,335, - 3,50,25,0,334,332,1,0,0,0,335,338,1,0,0,0,336,334,1,0,0,0,336,337,1,0,0, - 0,337,49,1,0,0,0,338,336,1,0,0,0,339,340,6,25,-1,0,340,341,3,4,2,0,341, - 342,5,63,0,0,342,469,1,0,0,0,343,344,3,4,2,0,344,345,7,2,0,0,345,346,5, - 62,0,0,346,469,1,0,0,0,347,348,3,4,2,0,348,349,5,48,0,0,349,350,5,4,0,0, - 350,351,3,50,25,0,351,352,5,5,0,0,352,353,5,62,0,0,353,469,1,0,0,0,354, - 469,5,20,0,0,355,356,5,19,0,0,356,357,5,4,0,0,357,358,3,50,25,0,358,359, - 5,5,0,0,359,469,1,0,0,0,360,361,5,58,0,0,361,366,3,48,24,0,362,363,5,61, - 0,0,363,365,3,48,24,0,364,362,1,0,0,0,365,368,1,0,0,0,366,364,1,0,0,0,366, - 367,1,0,0,0,367,369,1,0,0,0,368,366,1,0,0,0,369,370,5,59,0,0,370,469,1, - 0,0,0,371,372,3,24,12,0,372,373,5,6,0,0,373,374,3,50,25,0,374,375,5,7,0, - 0,375,469,1,0,0,0,376,469,3,26,13,0,377,469,3,28,14,0,378,469,3,30,15,0, - 379,469,3,32,16,0,380,382,5,23,0,0,381,380,1,0,0,0,381,382,1,0,0,0,382, - 383,1,0,0,0,383,384,5,37,0,0,384,385,5,6,0,0,385,386,3,50,25,0,386,387, - 5,7,0,0,387,469,1,0,0,0,388,390,5,23,0,0,389,388,1,0,0,0,389,390,1,0,0, - 0,390,391,1,0,0,0,391,392,5,38,0,0,392,393,5,6,0,0,393,394,3,50,25,0,394, - 395,5,7,0,0,395,469,1,0,0,0,396,397,5,39,0,0,397,398,5,4,0,0,398,399,3, - 50,25,0,399,400,5,5,0,0,400,401,5,6,0,0,401,402,3,50,25,0,402,403,5,7,0, - 0,403,469,1,0,0,0,404,405,7,6,0,0,405,406,5,6,0,0,406,407,3,50,25,0,407, - 408,5,7,0,0,408,469,1,0,0,0,409,410,5,8,0,0,410,411,3,50,25,0,411,412,5, - 8,0,0,412,469,1,0,0,0,413,469,3,8,4,0,414,469,3,6,3,0,415,416,5,47,0,0, - 416,469,3,50,25,11,417,418,5,16,0,0,418,419,5,4,0,0,419,420,3,50,25,0,420, - 421,5,5,0,0,421,422,5,4,0,0,422,423,3,50,25,0,423,424,5,5,0,0,424,469,1, - 0,0,0,425,469,5,17,0,0,426,469,3,4,2,0,427,428,3,4,2,0,428,429,5,6,0,0, - 429,434,3,34,17,0,430,431,5,54,0,0,431,433,3,34,17,0,432,430,1,0,0,0,433, - 436,1,0,0,0,434,432,1,0,0,0,434,435,1,0,0,0,435,437,1,0,0,0,436,434,1,0, - 0,0,437,442,5,7,0,0,438,439,5,64,0,0,439,440,3,6,3,0,440,441,5,64,0,0,441, - 443,1,0,0,0,442,438,1,0,0,0,442,443,1,0,0,0,443,469,1,0,0,0,444,445,5,15, - 0,0,445,446,5,4,0,0,446,447,3,4,2,0,447,448,5,5,0,0,448,451,1,0,0,0,449, - 451,3,4,2,0,450,444,1,0,0,0,450,449,1,0,0,0,451,452,1,0,0,0,452,453,5,6, - 0,0,453,458,3,50,25,0,454,455,5,54,0,0,455,457,3,50,25,0,456,454,1,0,0, - 0,457,460,1,0,0,0,458,456,1,0,0,0,458,459,1,0,0,0,459,461,1,0,0,0,460,458, - 1,0,0,0,461,462,5,7,0,0,462,469,1,0,0,0,463,469,5,10,0,0,464,465,5,6,0, - 0,465,466,3,50,25,0,466,467,5,7,0,0,467,469,1,0,0,0,468,339,1,0,0,0,468, - 343,1,0,0,0,468,347,1,0,0,0,468,354,1,0,0,0,468,355,1,0,0,0,468,360,1,0, - 0,0,468,371,1,0,0,0,468,376,1,0,0,0,468,377,1,0,0,0,468,378,1,0,0,0,468, - 379,1,0,0,0,468,381,1,0,0,0,468,389,1,0,0,0,468,396,1,0,0,0,468,404,1,0, - 0,0,468,409,1,0,0,0,468,413,1,0,0,0,468,414,1,0,0,0,468,415,1,0,0,0,468, - 417,1,0,0,0,468,425,1,0,0,0,468,426,1,0,0,0,468,427,1,0,0,0,468,450,1,0, - 0,0,468,463,1,0,0,0,468,464,1,0,0,0,469,489,1,0,0,0,470,471,10,10,0,0,471, - 472,5,18,0,0,472,488,3,50,25,11,473,474,10,7,0,0,474,475,5,46,0,0,475,488, - 3,50,25,8,476,477,10,6,0,0,477,478,5,47,0,0,478,488,3,50,25,7,479,480,10, - 28,0,0,480,488,7,2,0,0,481,482,10,27,0,0,482,483,5,48,0,0,483,484,5,4,0, - 0,484,485,3,50,25,0,485,486,5,5,0,0,486,488,1,0,0,0,487,470,1,0,0,0,487, - 473,1,0,0,0,487,476,1,0,0,0,487,479,1,0,0,0,487,481,1,0,0,0,488,491,1,0, - 0,0,489,487,1,0,0,0,489,490,1,0,0,0,490,51,1,0,0,0,491,489,1,0,0,0,492, - 493,7,7,0,0,493,494,3,58,29,0,494,495,7,8,0,0,495,53,1,0,0,0,496,497,7, - 7,0,0,497,498,7,9,0,0,498,499,7,10,0,0,499,500,7,9,0,0,500,501,7,8,0,0, - 501,55,1,0,0,0,502,503,5,71,0,0,503,504,5,81,0,0,504,505,7,9,0,0,505,506, - 5,82,0,0,506,507,5,81,0,0,507,508,5,84,0,0,508,511,5,82,0,0,509,511,5,72, - 0,0,510,502,1,0,0,0,510,509,1,0,0,0,511,57,1,0,0,0,512,513,6,29,-1,0,513, - 514,5,75,0,0,514,515,5,81,0,0,515,516,3,50,25,0,516,517,5,82,0,0,517,535, - 1,0,0,0,518,519,5,71,0,0,519,522,5,81,0,0,520,523,3,58,29,0,521,523,5,83, - 0,0,522,520,1,0,0,0,522,521,1,0,0,0,523,524,1,0,0,0,524,525,5,82,0,0,525, - 526,5,81,0,0,526,527,3,58,29,0,527,528,5,82,0,0,528,535,1,0,0,0,529,535, - 5,78,0,0,530,531,5,79,0,0,531,532,3,58,29,0,532,533,5,80,0,0,533,535,1, - 0,0,0,534,512,1,0,0,0,534,518,1,0,0,0,534,529,1,0,0,0,534,530,1,0,0,0,535, - 558,1,0,0,0,536,537,10,4,0,0,537,538,5,73,0,0,538,557,3,58,29,5,539,540, - 10,9,0,0,540,541,5,77,0,0,541,557,5,84,0,0,542,543,10,8,0,0,543,544,5,77, - 0,0,544,545,5,81,0,0,545,546,5,84,0,0,546,557,5,82,0,0,547,548,10,7,0,0, - 548,549,5,77,0,0,549,557,3,56,28,0,550,551,10,6,0,0,551,552,5,77,0,0,552, - 553,5,81,0,0,553,554,3,56,28,0,554,555,5,82,0,0,555,557,1,0,0,0,556,536, - 1,0,0,0,556,539,1,0,0,0,556,542,1,0,0,0,556,547,1,0,0,0,556,550,1,0,0,0, - 557,560,1,0,0,0,558,556,1,0,0,0,558,559,1,0,0,0,559,59,1,0,0,0,560,558, - 1,0,0,0,43,75,82,89,95,104,114,119,124,132,142,154,165,176,188,196,207, - 221,231,249,257,267,278,295,299,306,312,319,336,366,381,389,434,442,450, - 458,468,487,489,510,522,534,556,558]; + 25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,1,25,5,25,496, + 8,25,10,25,12,25,499,9,25,1,26,1,26,1,26,1,26,1,27,1,27,1,27,1,27,1,27, + 1,27,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1,28,3,28,519,8,28,1,29,1,29,1, + 29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,3,29,531,8,29,1,29,1,29,1,29,1,29, + 1,29,1,29,1,29,1,29,1,29,1,29,3,29,543,8,29,1,29,1,29,1,29,1,29,1,29,1, + 29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29, + 5,29,565,8,29,10,29,12,29,568,9,29,1,29,2,82,89,2,50,58,30,0,2,4,6,8,10, + 12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58, + 0,11,1,0,24,36,1,0,13,14,1,0,55,56,2,0,50,50,52,52,1,0,21,22,1,0,50,53, + 1,0,40,41,1,0,1,2,1,0,69,70,1,0,83,84,2,0,74,74,76,76,629,0,75,1,0,0,0, + 2,82,1,0,0,0,4,92,1,0,0,0,6,95,1,0,0,0,8,99,1,0,0,0,10,104,1,0,0,0,12,109, + 1,0,0,0,14,116,1,0,0,0,16,121,1,0,0,0,18,126,1,0,0,0,20,132,1,0,0,0,22, + 147,1,0,0,0,24,154,1,0,0,0,26,165,1,0,0,0,28,188,1,0,0,0,30,213,1,0,0,0, + 32,241,1,0,0,0,34,295,1,0,0,0,36,299,1,0,0,0,38,301,1,0,0,0,40,308,1,0, + 0,0,42,314,1,0,0,0,44,321,1,0,0,0,46,325,1,0,0,0,48,331,1,0,0,0,50,468, + 1,0,0,0,52,500,1,0,0,0,54,504,1,0,0,0,56,518,1,0,0,0,58,542,1,0,0,0,60, + 76,3,10,5,0,61,76,3,12,6,0,62,76,3,14,7,0,63,76,3,16,8,0,64,76,3,18,9,0, + 65,76,3,52,26,0,66,76,3,6,3,0,67,76,3,4,2,0,68,76,3,38,19,0,69,76,3,40, + 20,0,70,76,3,42,21,0,71,76,3,50,25,0,72,76,3,36,18,0,73,76,3,20,10,0,74, + 76,3,2,1,0,75,60,1,0,0,0,75,61,1,0,0,0,75,62,1,0,0,0,75,63,1,0,0,0,75,64, + 1,0,0,0,75,65,1,0,0,0,75,66,1,0,0,0,75,67,1,0,0,0,75,68,1,0,0,0,75,69,1, + 0,0,0,75,70,1,0,0,0,75,71,1,0,0,0,75,72,1,0,0,0,75,73,1,0,0,0,75,74,1,0, + 0,0,75,76,1,0,0,0,76,77,1,0,0,0,77,78,5,0,0,1,78,1,1,0,0,0,79,81,9,0,0, + 0,80,79,1,0,0,0,81,84,1,0,0,0,82,83,1,0,0,0,82,80,1,0,0,0,83,85,1,0,0,0, + 84,82,1,0,0,0,85,89,3,54,27,0,86,88,9,0,0,0,87,86,1,0,0,0,88,91,1,0,0,0, + 89,90,1,0,0,0,89,87,1,0,0,0,90,3,1,0,0,0,91,89,1,0,0,0,92,93,5,64,0,0,93, + 5,1,0,0,0,94,96,5,47,0,0,95,94,1,0,0,0,95,96,1,0,0,0,96,97,1,0,0,0,97,98, + 5,57,0,0,98,7,1,0,0,0,99,100,3,6,3,0,100,101,3,52,26,0,101,9,1,0,0,0,102, + 105,3,4,2,0,103,105,5,10,0,0,104,102,1,0,0,0,104,103,1,0,0,0,105,106,1, + 0,0,0,106,107,5,49,0,0,107,108,3,50,25,0,108,11,1,0,0,0,109,112,3,10,5, + 0,110,111,5,54,0,0,111,113,3,10,5,0,112,110,1,0,0,0,113,114,1,0,0,0,114, + 112,1,0,0,0,114,115,1,0,0,0,115,13,1,0,0,0,116,117,3,10,5,0,117,119,5,49, + 0,0,118,120,3,52,26,0,119,118,1,0,0,0,119,120,1,0,0,0,120,15,1,0,0,0,121, + 122,3,50,25,0,122,124,5,49,0,0,123,125,3,52,26,0,124,123,1,0,0,0,124,125, + 1,0,0,0,125,17,1,0,0,0,126,127,3,50,25,0,127,128,5,49,0,0,128,129,3,50, + 25,0,129,19,1,0,0,0,130,133,3,4,2,0,131,133,5,10,0,0,132,130,1,0,0,0,132, + 131,1,0,0,0,133,134,1,0,0,0,134,135,5,49,0,0,135,136,3,4,2,0,136,137,5, + 6,0,0,137,142,3,22,11,0,138,139,5,54,0,0,139,141,3,22,11,0,140,138,1,0, + 0,0,141,144,1,0,0,0,142,140,1,0,0,0,142,143,1,0,0,0,143,145,1,0,0,0,144, + 142,1,0,0,0,145,146,5,7,0,0,146,21,1,0,0,0,147,148,5,6,0,0,148,149,3,50, + 25,0,149,150,5,54,0,0,150,151,3,36,18,0,151,152,5,7,0,0,152,23,1,0,0,0, + 153,155,5,23,0,0,154,153,1,0,0,0,154,155,1,0,0,0,155,156,1,0,0,0,156,157, + 7,0,0,0,157,25,1,0,0,0,158,166,5,11,0,0,159,160,5,12,0,0,160,161,5,4,0, + 0,161,162,5,5,0,0,162,163,5,48,0,0,163,164,5,4,0,0,164,166,5,5,0,0,165, + 158,1,0,0,0,165,159,1,0,0,0,166,167,1,0,0,0,167,168,5,6,0,0,168,169,3,50, + 25,0,169,176,5,7,0,0,170,171,5,15,0,0,171,172,5,4,0,0,172,173,3,4,2,0,173, + 174,5,5,0,0,174,177,1,0,0,0,175,177,3,4,2,0,176,170,1,0,0,0,176,175,1,0, + 0,0,177,178,1,0,0,0,178,179,5,6,0,0,179,180,3,4,2,0,180,181,5,7,0,0,181, + 27,1,0,0,0,182,183,5,12,0,0,183,184,5,4,0,0,184,185,3,50,25,0,185,186,5, + 5,0,0,186,189,1,0,0,0,187,189,7,1,0,0,188,182,1,0,0,0,188,187,1,0,0,0,189, + 196,1,0,0,0,190,191,5,48,0,0,191,192,5,4,0,0,192,193,3,50,25,0,193,194, + 5,5,0,0,194,197,1,0,0,0,195,197,7,2,0,0,196,190,1,0,0,0,196,195,1,0,0,0, + 197,198,1,0,0,0,198,199,5,6,0,0,199,200,3,50,25,0,200,207,5,7,0,0,201,202, + 5,15,0,0,202,203,5,4,0,0,203,204,3,4,2,0,204,205,5,5,0,0,205,208,1,0,0, + 0,206,208,3,4,2,0,207,201,1,0,0,0,207,206,1,0,0,0,208,209,1,0,0,0,209,210, + 5,6,0,0,210,211,3,4,2,0,211,212,5,7,0,0,212,29,1,0,0,0,213,214,5,16,0,0, + 214,221,5,4,0,0,215,216,5,15,0,0,216,217,5,4,0,0,217,218,3,4,2,0,218,219, + 5,5,0,0,219,222,1,0,0,0,220,222,3,4,2,0,221,215,1,0,0,0,221,220,1,0,0,0, + 222,223,1,0,0,0,223,224,5,5,0,0,224,231,5,4,0,0,225,226,5,15,0,0,226,227, + 5,4,0,0,227,228,3,4,2,0,228,229,5,5,0,0,229,232,1,0,0,0,230,232,3,4,2,0, + 231,225,1,0,0,0,231,230,1,0,0,0,232,233,1,0,0,0,233,234,5,6,0,0,234,235, + 3,4,2,0,235,236,5,7,0,0,236,237,5,5,0,0,237,238,5,6,0,0,238,239,3,50,25, + 0,239,240,5,7,0,0,240,31,1,0,0,0,241,242,5,16,0,0,242,249,5,4,0,0,243,244, + 5,15,0,0,244,245,5,4,0,0,245,246,3,4,2,0,246,247,5,5,0,0,247,250,1,0,0, + 0,248,250,3,4,2,0,249,243,1,0,0,0,249,248,1,0,0,0,250,257,1,0,0,0,251,252, + 5,48,0,0,252,253,5,4,0,0,253,254,3,6,3,0,254,255,5,5,0,0,255,258,1,0,0, + 0,256,258,5,55,0,0,257,251,1,0,0,0,257,256,1,0,0,0,258,259,1,0,0,0,259, + 260,5,5,0,0,260,267,5,4,0,0,261,262,5,15,0,0,262,263,5,4,0,0,263,264,3, + 4,2,0,264,265,5,5,0,0,265,268,1,0,0,0,266,268,3,4,2,0,267,261,1,0,0,0,267, + 266,1,0,0,0,268,269,1,0,0,0,269,270,5,6,0,0,270,271,3,4,2,0,271,278,5,7, + 0,0,272,273,5,48,0,0,273,274,5,4,0,0,274,275,3,6,3,0,275,276,5,5,0,0,276, + 279,1,0,0,0,277,279,5,55,0,0,278,272,1,0,0,0,278,277,1,0,0,0,279,280,1, + 0,0,0,280,281,5,5,0,0,281,282,5,6,0,0,282,283,3,50,25,0,283,284,5,7,0,0, + 284,33,1,0,0,0,285,286,3,4,2,0,286,287,5,49,0,0,287,288,3,50,25,0,288,296, + 1,0,0,0,289,290,3,50,25,0,290,291,7,3,0,0,291,292,3,4,2,0,292,293,7,3,0, + 0,293,294,3,50,25,0,294,296,1,0,0,0,295,285,1,0,0,0,295,289,1,0,0,0,296, + 35,1,0,0,0,297,300,3,44,22,0,298,300,3,46,23,0,299,297,1,0,0,0,299,298, + 1,0,0,0,300,37,1,0,0,0,301,304,3,4,2,0,302,303,5,54,0,0,303,305,3,4,2,0, + 304,302,1,0,0,0,305,306,1,0,0,0,306,304,1,0,0,0,306,307,1,0,0,0,307,39, + 1,0,0,0,308,309,3,4,2,0,309,312,7,4,0,0,310,313,3,6,3,0,311,313,3,8,4,0, + 312,310,1,0,0,0,312,311,1,0,0,0,313,41,1,0,0,0,314,317,3,40,20,0,315,316, + 5,54,0,0,316,318,3,40,20,0,317,315,1,0,0,0,318,319,1,0,0,0,319,317,1,0, + 0,0,319,320,1,0,0,0,320,43,1,0,0,0,321,322,3,50,25,0,322,323,7,5,0,0,323, + 324,3,50,25,0,324,45,1,0,0,0,325,326,3,50,25,0,326,327,7,5,0,0,327,328, + 3,50,25,0,328,329,7,5,0,0,329,330,3,50,25,0,330,47,1,0,0,0,331,336,3,50, + 25,0,332,333,5,60,0,0,333,335,3,50,25,0,334,332,1,0,0,0,335,338,1,0,0,0, + 336,334,1,0,0,0,336,337,1,0,0,0,337,49,1,0,0,0,338,336,1,0,0,0,339,340, + 6,25,-1,0,340,341,3,4,2,0,341,342,5,63,0,0,342,469,1,0,0,0,343,344,3,4, + 2,0,344,345,7,2,0,0,345,346,5,62,0,0,346,469,1,0,0,0,347,348,3,4,2,0,348, + 349,5,48,0,0,349,350,5,4,0,0,350,351,3,50,25,0,351,352,5,5,0,0,352,353, + 5,62,0,0,353,469,1,0,0,0,354,469,5,20,0,0,355,356,5,19,0,0,356,357,5,4, + 0,0,357,358,3,50,25,0,358,359,5,5,0,0,359,469,1,0,0,0,360,361,5,58,0,0, + 361,366,3,48,24,0,362,363,5,61,0,0,363,365,3,48,24,0,364,362,1,0,0,0,365, + 368,1,0,0,0,366,364,1,0,0,0,366,367,1,0,0,0,367,369,1,0,0,0,368,366,1,0, + 0,0,369,370,5,59,0,0,370,469,1,0,0,0,371,372,3,24,12,0,372,373,5,6,0,0, + 373,374,3,50,25,0,374,375,5,7,0,0,375,469,1,0,0,0,376,469,3,26,13,0,377, + 469,3,28,14,0,378,469,3,30,15,0,379,469,3,32,16,0,380,382,5,23,0,0,381, + 380,1,0,0,0,381,382,1,0,0,0,382,383,1,0,0,0,383,384,5,37,0,0,384,385,5, + 6,0,0,385,386,3,50,25,0,386,387,5,7,0,0,387,469,1,0,0,0,388,390,5,23,0, + 0,389,388,1,0,0,0,389,390,1,0,0,0,390,391,1,0,0,0,391,392,5,38,0,0,392, + 393,5,6,0,0,393,394,3,50,25,0,394,395,5,7,0,0,395,469,1,0,0,0,396,397,5, + 39,0,0,397,398,5,4,0,0,398,399,3,50,25,0,399,400,5,5,0,0,400,401,5,6,0, + 0,401,402,3,50,25,0,402,403,5,7,0,0,403,469,1,0,0,0,404,405,7,6,0,0,405, + 406,5,6,0,0,406,407,3,50,25,0,407,408,5,7,0,0,408,469,1,0,0,0,409,410,5, + 8,0,0,410,411,3,50,25,0,411,412,5,8,0,0,412,469,1,0,0,0,413,469,3,8,4,0, + 414,469,3,6,3,0,415,416,5,47,0,0,416,469,3,50,25,11,417,418,5,16,0,0,418, + 419,5,4,0,0,419,420,3,50,25,0,420,421,5,5,0,0,421,422,5,4,0,0,422,423,3, + 50,25,0,423,424,5,5,0,0,424,469,1,0,0,0,425,469,5,17,0,0,426,469,3,4,2, + 0,427,428,3,4,2,0,428,429,5,6,0,0,429,434,3,34,17,0,430,431,5,54,0,0,431, + 433,3,34,17,0,432,430,1,0,0,0,433,436,1,0,0,0,434,432,1,0,0,0,434,435,1, + 0,0,0,435,437,1,0,0,0,436,434,1,0,0,0,437,442,5,7,0,0,438,439,5,64,0,0, + 439,440,3,6,3,0,440,441,5,64,0,0,441,443,1,0,0,0,442,438,1,0,0,0,442,443, + 1,0,0,0,443,469,1,0,0,0,444,445,5,15,0,0,445,446,5,4,0,0,446,447,3,4,2, + 0,447,448,5,5,0,0,448,451,1,0,0,0,449,451,3,4,2,0,450,444,1,0,0,0,450,449, + 1,0,0,0,451,452,1,0,0,0,452,453,5,6,0,0,453,458,3,50,25,0,454,455,5,54, + 0,0,455,457,3,50,25,0,456,454,1,0,0,0,457,460,1,0,0,0,458,456,1,0,0,0,458, + 459,1,0,0,0,459,461,1,0,0,0,460,458,1,0,0,0,461,462,5,7,0,0,462,469,1,0, + 0,0,463,469,5,10,0,0,464,465,5,6,0,0,465,466,3,50,25,0,466,467,5,7,0,0, + 467,469,1,0,0,0,468,339,1,0,0,0,468,343,1,0,0,0,468,347,1,0,0,0,468,354, + 1,0,0,0,468,355,1,0,0,0,468,360,1,0,0,0,468,371,1,0,0,0,468,376,1,0,0,0, + 468,377,1,0,0,0,468,378,1,0,0,0,468,379,1,0,0,0,468,381,1,0,0,0,468,389, + 1,0,0,0,468,396,1,0,0,0,468,404,1,0,0,0,468,409,1,0,0,0,468,413,1,0,0,0, + 468,414,1,0,0,0,468,415,1,0,0,0,468,417,1,0,0,0,468,425,1,0,0,0,468,426, + 1,0,0,0,468,427,1,0,0,0,468,450,1,0,0,0,468,463,1,0,0,0,468,464,1,0,0,0, + 469,497,1,0,0,0,470,471,10,10,0,0,471,472,5,18,0,0,472,496,3,50,25,11,473, + 474,10,7,0,0,474,475,5,46,0,0,475,496,3,50,25,8,476,477,10,6,0,0,477,478, + 5,47,0,0,478,496,3,50,25,7,479,480,10,29,0,0,480,496,7,2,0,0,481,482,10, + 28,0,0,482,483,5,48,0,0,483,484,5,4,0,0,484,485,3,50,25,0,485,486,5,5,0, + 0,486,496,1,0,0,0,487,488,10,27,0,0,488,489,5,9,0,0,489,490,5,4,0,0,490, + 491,3,50,25,0,491,492,5,54,0,0,492,493,3,50,25,0,493,494,5,5,0,0,494,496, + 1,0,0,0,495,470,1,0,0,0,495,473,1,0,0,0,495,476,1,0,0,0,495,479,1,0,0,0, + 495,481,1,0,0,0,495,487,1,0,0,0,496,499,1,0,0,0,497,495,1,0,0,0,497,498, + 1,0,0,0,498,51,1,0,0,0,499,497,1,0,0,0,500,501,7,7,0,0,501,502,3,58,29, + 0,502,503,7,8,0,0,503,53,1,0,0,0,504,505,7,7,0,0,505,506,7,9,0,0,506,507, + 7,10,0,0,507,508,7,9,0,0,508,509,7,8,0,0,509,55,1,0,0,0,510,511,5,71,0, + 0,511,512,5,81,0,0,512,513,7,9,0,0,513,514,5,82,0,0,514,515,5,81,0,0,515, + 516,5,84,0,0,516,519,5,82,0,0,517,519,5,72,0,0,518,510,1,0,0,0,518,517, + 1,0,0,0,519,57,1,0,0,0,520,521,6,29,-1,0,521,522,5,75,0,0,522,523,5,81, + 0,0,523,524,3,50,25,0,524,525,5,82,0,0,525,543,1,0,0,0,526,527,5,71,0,0, + 527,530,5,81,0,0,528,531,3,58,29,0,529,531,5,83,0,0,530,528,1,0,0,0,530, + 529,1,0,0,0,531,532,1,0,0,0,532,533,5,82,0,0,533,534,5,81,0,0,534,535,3, + 58,29,0,535,536,5,82,0,0,536,543,1,0,0,0,537,543,5,78,0,0,538,539,5,79, + 0,0,539,540,3,58,29,0,540,541,5,80,0,0,541,543,1,0,0,0,542,520,1,0,0,0, + 542,526,1,0,0,0,542,537,1,0,0,0,542,538,1,0,0,0,543,566,1,0,0,0,544,545, + 10,4,0,0,545,546,5,73,0,0,546,565,3,58,29,5,547,548,10,9,0,0,548,549,5, + 77,0,0,549,565,5,84,0,0,550,551,10,8,0,0,551,552,5,77,0,0,552,553,5,81, + 0,0,553,554,5,84,0,0,554,565,5,82,0,0,555,556,10,7,0,0,556,557,5,77,0,0, + 557,565,3,56,28,0,558,559,10,6,0,0,559,560,5,77,0,0,560,561,5,81,0,0,561, + 562,3,56,28,0,562,563,5,82,0,0,563,565,1,0,0,0,564,544,1,0,0,0,564,547, + 1,0,0,0,564,550,1,0,0,0,564,555,1,0,0,0,564,558,1,0,0,0,565,568,1,0,0,0, + 566,564,1,0,0,0,566,567,1,0,0,0,567,59,1,0,0,0,568,566,1,0,0,0,43,75,82, + 89,95,104,114,119,124,132,142,154,165,176,188,196,207,221,231,249,257,267, + 278,295,299,306,312,319,336,366,381,389,434,442,450,458,468,495,497,518, + 530,542,564,566]; private static __ATN: ATN; public static get _ATN(): ATN { @@ -4544,6 +4571,38 @@ export class SubtractContext extends ExprContext { } } } +export class IndexContext extends ExprContext { + constructor(parser: LatexParser, ctx: ExprContext) { + super(parser, ctx.parentCtx, ctx.invokingState); + super.copyFrom(ctx); + } + public expr_list(): ExprContext[] { + return this.getTypedRuleContexts(ExprContext) as ExprContext[]; + } + public expr(i: number): ExprContext { + return this.getTypedRuleContext(ExprContext, i) as ExprContext; + } + public UNDERSCORE(): TerminalNode { + return this.getToken(LatexParser.UNDERSCORE, 0); + } + public L_BRACE(): TerminalNode { + return this.getToken(LatexParser.L_BRACE, 0); + } + public COMMA(): TerminalNode { + return this.getToken(LatexParser.COMMA, 0); + } + public R_BRACE(): TerminalNode { + return this.getToken(LatexParser.R_BRACE, 0); + } + // @Override + public accept(visitor: LatexParserVisitor): Result { + if (visitor.visitIndex) { + return visitor.visitIndex(this); + } else { + return visitor.visitChildren(this); + } + } +} export class TrigContext extends ExprContext { constructor(parser: LatexParser, ctx: ExprContext) { super(parser, ctx.parentCtx, ctx.invokingState); diff --git a/src/parser/LatexParserVisitor.ts b/src/parser/LatexParserVisitor.ts index 0382cf9c..d5098031 100644 --- a/src/parser/LatexParserVisitor.ts +++ b/src/parser/LatexParserVisitor.ts @@ -50,6 +50,7 @@ import { BaseLogContext } from "./LatexParser"; import { AddContext } from "./LatexParser"; import { SingleIntSqrtContext } from "./LatexParser"; import { SubtractContext } from "./LatexParser"; +import { IndexContext } from "./LatexParser"; import { TrigContext } from "./LatexParser"; import { DivideIntsContext } from "./LatexParser"; import { NDerivativeContext } from "./LatexParser"; @@ -373,6 +374,13 @@ export default class LatexParserVisitor extends ParseTreeVisitor * @return the visitor result */ visitSubtract?: (ctx: SubtractContext) => Result; + /** + * Visit a parse tree produced by the `index` + * labeled alternative in `LatexParser.expr`. + * @param ctx the parse tree + * @return the visitor result + */ + visitIndex?: (ctx: IndexContext) => Result; /** * Visit a parse tree produced by the `trig` * labeled alternative in `LatexParser.expr`. diff --git a/src/parser/LatexToSympy.ts b/src/parser/LatexToSympy.ts index 406b1717..c1a2ca72 100644 --- a/src/parser/LatexToSympy.ts +++ b/src/parser/LatexToSympy.ts @@ -27,7 +27,7 @@ import type { U_blockContext, Condition_singleContext, Condition_chainContext, ConditionContext, Piecewise_argContext, Piecewise_assignContext, Insert_matrixContext, BaseLogSingleCharContext, DivideIntsContext, - Assign_listContext, Assign_plus_queryContext, SingleIntSqrtContext, MatrixContext + Assign_listContext, Assign_plus_queryContext, SingleIntSqrtContext, MatrixContext, IndexContext } from "./LatexParser"; @@ -729,6 +729,10 @@ export class LatexToSympy extends LatexParserVisitor { + return `(${this.visit(ctx.expr(0))})[${this.visit(ctx.expr(1))}-1,${this.visit(ctx.expr(2))}-1]`; + } + visitArgument = (ctx: ArgumentContext): (LocalSubstitution | LocalSubstitutionRange)[] => { const newSubs: (LocalSubstitution | LocalSubstitutionRange)[] = []; @@ -1181,8 +1185,6 @@ export class LatexToSympy extends LatexParserVisitor