From a437d3977316bdd1d859e3fdd462548c79d1fbec Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 14 Apr 2014 23:11:10 -0700 Subject: [PATCH] Add rule precedence construct Still need to add some way of expressing left and right associativity --- examples/grammars/arithmetic.cc | 39 +- examples/parsers/arithmetic.c | 1741 ++++------------- include/tree_sitter/compiler.h | 1 + include/tree_sitter/parser.h | 2 +- .../build_tables/conflict_manager_spec.cc | 126 +- .../build_tables/rule_transitions_spec.cc | 14 + spec/runtime/languages/arithmetic/errors.txt | 4 +- spec/runtime/languages/arithmetic/main.txt | 12 +- spec/runtime/node_position_spec.cc | 2 +- src/compiler/build_tables/build_tables.cc | 30 +- src/compiler/build_tables/conflict_manager.cc | 104 +- src/compiler/build_tables/get_metadata.cc | 3 +- src/compiler/build_tables/item.cc | 12 +- src/compiler/build_tables/item.h | 3 +- src/compiler/build_tables/rule_transitions.cc | 5 +- src/compiler/generate_code/c_code.cc | 5 +- src/compiler/generate_code/helpers.cc | 49 - src/compiler/generate_code/helpers.h | 16 - src/compiler/parse_table.cc | 20 +- src/compiler/parse_table.h | 8 +- src/compiler/rules/rules.cc | 9 + src/compiler/util/string_helpers.cc | 43 + src/compiler/util/string_helpers.h | 6 + 23 files changed, 750 insertions(+), 1504 deletions(-) delete mode 100644 src/compiler/generate_code/helpers.cc delete mode 100644 src/compiler/generate_code/helpers.h diff --git a/examples/grammars/arithmetic.cc b/examples/grammars/arithmetic.cc index e0ce49c8..205aad97 100644 --- a/examples/grammars/arithmetic.cc +++ b/examples/grammars/arithmetic.cc @@ -5,39 +5,34 @@ namespace tree_sitter_examples { using namespace tree_sitter::rules; using std::string; - static rule_ptr infix_op(string op, string rule_name) { - return choice({ - seq({ - sym(rule_name), - str(op), - sym(rule_name) }), - sym(rule_name) }); + static rule_ptr infix_op(string op, int precedence) { + return prec(precedence, seq({ + sym("expression"), + str(op), + sym("expression") })); } extern const Grammar arithmetic({ { "expression", choice({ sym("sum"), - sym("difference") }) }, - { "_operand1", choice({ + sym("difference"), sym("product"), - sym("quotient") }) }, - { "_operand2", choice({ - sym("exponent") }) }, - { "_operand3", choice({ + sym("quotient"), + sym("exponent"), + sym("group"), sym("number"), - sym("variable"), - sym("grouping") }) }, - { "grouping", seq({ + sym("variable") }) }, + + { "sum", infix_op("+", 1) }, + { "difference", infix_op("-", 1) }, + { "product", infix_op("*", 2) }, + { "quotient", infix_op("/", 2) }, + { "exponent", infix_op("^", 3) }, + { "group", seq({ str("("), err(sym("expression")), str(")") }) }, - { "sum", infix_op("+", "_operand1") }, - { "difference", infix_op("-", "_operand1") }, - { "product", infix_op("*", "_operand2") }, - { "quotient", infix_op("/", "_operand2") }, - { "exponent", infix_op("^", "_operand3") }, - { "number", pattern("\\d+") }, { "variable", pattern("\\a[\\w_]*") }, }); diff --git a/examples/parsers/arithmetic.c b/examples/parsers/arithmetic.c index 1e389e6b..c51b5c2f 100644 --- a/examples/parsers/arithmetic.c +++ b/examples/parsers/arithmetic.c @@ -1,58 +1,49 @@ #include "tree_sitter/parser.h" -#define STATE_COUNT 134 -#define SYMBOL_COUNT 21 +#define STATE_COUNT 32 +#define SYMBOL_COUNT 18 enum { - ts_sym__operand1 = 2, - ts_sym__operand2 = 3, - ts_sym__operand3 = 4, - ts_sym_difference = 5, - ts_sym_exponent = 6, - ts_sym_expression = 7, - ts_sym_grouping = 8, - ts_sym_number = 9, - ts_sym_product = 10, - ts_sym_quotient = 11, - ts_sym_sum = 12, - ts_sym_variable = 13, - ts_aux_sym_token1 = 14, - ts_aux_sym_token2 = 15, - ts_aux_sym_token3 = 16, - ts_aux_sym_token4 = 17, - ts_aux_sym_token5 = 18, - ts_aux_sym_token6 = 19, - ts_aux_sym_token7 = 20, + ts_sym_difference = 2, + ts_sym_exponent = 3, + ts_sym_expression = 4, + ts_sym_group = 5, + ts_sym_number = 6, + ts_sym_product = 7, + ts_sym_quotient = 8, + ts_sym_sum = 9, + ts_sym_variable = 10, + ts_aux_sym_token1 = 11, + ts_aux_sym_token2 = 12, + ts_aux_sym_token3 = 13, + ts_aux_sym_token4 = 14, + ts_aux_sym_token5 = 15, + ts_aux_sym_token6 = 16, + ts_aux_sym_token7 = 17, }; SYMBOL_NAMES = { - [ts_sym__operand1] = "_operand1", - [ts_sym__operand2] = "_operand2", - [ts_sym__operand3] = "_operand3", [ts_sym_difference] = "difference", [ts_sym_exponent] = "exponent", [ts_sym_expression] = "expression", - [ts_sym_grouping] = "grouping", + [ts_sym_group] = "group", [ts_sym_number] = "number", [ts_sym_product] = "product", [ts_sym_quotient] = "quotient", [ts_sym_sum] = "sum", [ts_sym_variable] = "variable", - [ts_aux_sym_token1] = "'('", - [ts_aux_sym_token2] = "')'", - [ts_aux_sym_token3] = "'+'", - [ts_aux_sym_token4] = "'-'", - [ts_aux_sym_token5] = "'*'", - [ts_aux_sym_token6] = "'/'", - [ts_aux_sym_token7] = "'^'", + [ts_aux_sym_token1] = "'+'", + [ts_aux_sym_token2] = "'-'", + [ts_aux_sym_token3] = "'*'", + [ts_aux_sym_token4] = "'/'", + [ts_aux_sym_token5] = "'^'", + [ts_aux_sym_token6] = "'('", + [ts_aux_sym_token7] = "')'", [ts_builtin_sym_end] = "EOF", [ts_builtin_sym_error] = "ERROR", }; HIDDEN_SYMBOLS = { - [ts_sym__operand1] = 1, - [ts_sym__operand2] = 1, - [ts_sym__operand3] = 1, [ts_aux_sym_token1] = 1, [ts_aux_sym_token2] = 1, [ts_aux_sym_token3] = 1, @@ -69,43 +60,33 @@ LEX_FN() { START_TOKEN(); if (lookahead == '\0') ADVANCE(1); - if ((lookahead == '\t') || - (lookahead == '\n') || + if (('\t' <= lookahead && lookahead <= '\n') || (lookahead == '\r') || (lookahead == ' ')) ADVANCE(0); + if (lookahead == '*') + ADVANCE(2); + if (lookahead == '+') + ADVANCE(3); + if (lookahead == '-') + ADVANCE(4); + if (lookahead == '/') + ADVANCE(5); + if (lookahead == '^') + ADVANCE(6); LEX_ERROR(); case 1: ACCEPT_TOKEN(ts_builtin_sym_end); case 2: - START_TOKEN(); - if ((lookahead == '\t') || - (lookahead == '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(2); - if (lookahead == ')') - ADVANCE(3); - LEX_ERROR(); - case 3: - ACCEPT_TOKEN(ts_aux_sym_token2); - case 4: - START_TOKEN(); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(4); - if (lookahead == ')') - ADVANCE(3); - if (lookahead == '+') - ADVANCE(5); - if (lookahead == '-') - ADVANCE(6); - LEX_ERROR(); - case 5: ACCEPT_TOKEN(ts_aux_sym_token3); - case 6: + case 3: + ACCEPT_TOKEN(ts_aux_sym_token1); + case 4: + ACCEPT_TOKEN(ts_aux_sym_token2); + case 5: ACCEPT_TOKEN(ts_aux_sym_token4); + case 6: + ACCEPT_TOKEN(ts_aux_sym_token5); case 7: START_TOKEN(); if (('\t' <= lookahead && lookahead <= '\n') || @@ -113,252 +94,84 @@ LEX_FN() { (lookahead == ' ')) ADVANCE(7); if (lookahead == ')') - ADVANCE(3); - if (lookahead == '*') ADVANCE(8); + if (lookahead == '*') + ADVANCE(2); if (lookahead == '+') - ADVANCE(5); + ADVANCE(3); if (lookahead == '-') - ADVANCE(6); + ADVANCE(4); if (lookahead == '/') - ADVANCE(9); + ADVANCE(5); + if (lookahead == '^') + ADVANCE(6); LEX_ERROR(); case 8: - ACCEPT_TOKEN(ts_aux_sym_token5); + ACCEPT_TOKEN(ts_aux_sym_token7); case 9: - ACCEPT_TOKEN(ts_aux_sym_token6); + START_TOKEN(); + if ((lookahead == '\t') || + (lookahead == '\n') || + (lookahead == '\r') || + (lookahead == ' ')) + ADVANCE(9); + if (lookahead == ')') + ADVANCE(8); + LEX_ERROR(); case 10: START_TOKEN(); if (('\t' <= lookahead && lookahead <= '\n') || (lookahead == '\r') || (lookahead == ' ')) ADVANCE(10); - if (lookahead == ')') - ADVANCE(3); - if (lookahead == '*') - ADVANCE(8); - if (lookahead == '+') - ADVANCE(5); - if (lookahead == '-') - ADVANCE(6); - if (lookahead == '/') - ADVANCE(9); - if (lookahead == '^') - ADVANCE(11); - LEX_ERROR(); - case 11: - ACCEPT_TOKEN(ts_aux_sym_token7); - case 12: - START_TOKEN(); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(12); if (lookahead == '(') - ADVANCE(13); + ADVANCE(11); if ('0' <= lookahead && lookahead <= '9') - ADVANCE(14); + ADVANCE(12); if (('A' <= lookahead && lookahead <= 'Z') || ('a' <= lookahead && lookahead <= 'z')) - ADVANCE(15); + ADVANCE(13); LEX_ERROR(); - case 13: - ACCEPT_TOKEN(ts_aux_sym_token1); - case 14: + case 11: + ACCEPT_TOKEN(ts_aux_sym_token6); + case 12: if ('0' <= lookahead && lookahead <= '9') - ADVANCE(14); + ADVANCE(12); ACCEPT_TOKEN(ts_sym_number); - case 15: + case 13: if (('0' <= lookahead && lookahead <= '9') || ('A' <= lookahead && lookahead <= 'Z') || (lookahead == '_') || ('a' <= lookahead && lookahead <= 'z')) - ADVANCE(15); - ACCEPT_TOKEN(ts_sym_variable); - case 16: - START_TOKEN(); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(16); - if (lookahead == ')') - ADVANCE(3); - if (lookahead == '+') - ADVANCE(5); - if (lookahead == '-') - ADVANCE(6); - if (lookahead == '^') - ADVANCE(11); - LEX_ERROR(); - case 17: - START_TOKEN(); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(17); - if (lookahead == ')') - ADVANCE(3); - if (lookahead == '^') - ADVANCE(11); - LEX_ERROR(); - case 18: - START_TOKEN(); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(18); - if (lookahead == ')') - ADVANCE(3); - if (lookahead == '*') - ADVANCE(8); - if (lookahead == '/') - ADVANCE(9); - LEX_ERROR(); - case 19: - START_TOKEN(); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(19); - if (lookahead == ')') - ADVANCE(3); - if (lookahead == '*') - ADVANCE(8); - if (lookahead == '/') - ADVANCE(9); - if (lookahead == '^') - ADVANCE(11); - LEX_ERROR(); - case 20: - START_TOKEN(); - if (lookahead == '\0') - ADVANCE(1); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(20); - if (lookahead == '^') - ADVANCE(11); - LEX_ERROR(); - case 21: - START_TOKEN(); - if (lookahead == '\0') - ADVANCE(1); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(21); - if (lookahead == '*') - ADVANCE(8); - if (lookahead == '/') - ADVANCE(9); - LEX_ERROR(); - case 22: - START_TOKEN(); - if (lookahead == '\0') - ADVANCE(1); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(22); - if (lookahead == '*') - ADVANCE(8); - if (lookahead == '/') - ADVANCE(9); - if (lookahead == '^') - ADVANCE(11); - LEX_ERROR(); - case 23: - START_TOKEN(); - if (lookahead == '\0') - ADVANCE(1); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(23); - if (lookahead == '+') - ADVANCE(5); - if (lookahead == '-') - ADVANCE(6); - LEX_ERROR(); - case 24: - START_TOKEN(); - if (lookahead == '\0') - ADVANCE(1); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(24); - if (lookahead == '+') - ADVANCE(5); - if (lookahead == '-') - ADVANCE(6); - if (lookahead == '^') - ADVANCE(11); - LEX_ERROR(); - case 25: - START_TOKEN(); - if (lookahead == '\0') - ADVANCE(1); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(25); - if (lookahead == '*') - ADVANCE(8); - if (lookahead == '+') - ADVANCE(5); - if (lookahead == '-') - ADVANCE(6); - if (lookahead == '/') - ADVANCE(9); - LEX_ERROR(); - case 26: - START_TOKEN(); - if (lookahead == '\0') - ADVANCE(1); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(26); - if (lookahead == '*') - ADVANCE(8); - if (lookahead == '+') - ADVANCE(5); - if (lookahead == '-') - ADVANCE(6); - if (lookahead == '/') - ADVANCE(9); - if (lookahead == '^') - ADVANCE(11); - LEX_ERROR(); - case 27: - START_TOKEN(); - if (lookahead == '\0') - ADVANCE(1); - if (('\t' <= lookahead && lookahead <= '\n') || - (lookahead == '\r') || - (lookahead == ' ')) - ADVANCE(27); - if (lookahead == '(') ADVANCE(13); - if (lookahead == ')') - ADVANCE(3); - if (lookahead == '*') - ADVANCE(8); - if (lookahead == '+') - ADVANCE(5); - if (lookahead == '-') - ADVANCE(6); - if (lookahead == '/') - ADVANCE(9); - if ('0' <= lookahead && lookahead <= '9') + ACCEPT_TOKEN(ts_sym_variable); + case 14: + START_TOKEN(); + if (lookahead == '\0') + ADVANCE(1); + if (('\t' <= lookahead && lookahead <= '\n') || + (lookahead == '\r') || + (lookahead == ' ')) ADVANCE(14); + if (lookahead == '(') + ADVANCE(11); + if (lookahead == ')') + ADVANCE(8); + if (lookahead == '*') + ADVANCE(2); + if (lookahead == '+') + ADVANCE(3); + if (lookahead == '-') + ADVANCE(4); + if (lookahead == '/') + ADVANCE(5); + if ('0' <= lookahead && lookahead <= '9') + ADVANCE(12); if (('A' <= lookahead && lookahead <= 'Z') || ('a' <= lookahead && lookahead <= 'z')) - ADVANCE(15); + ADVANCE(13); if (lookahead == '^') - ADVANCE(11); + ADVANCE(6); LEX_ERROR(); case ts_lex_state_error: START_TOKEN(); @@ -367,26 +180,26 @@ LEX_FN() { if (('\t' <= lookahead && lookahead <= '\n') || (lookahead == '\r') || (lookahead == ' ')) - ADVANCE(27); - if (lookahead == '(') - ADVANCE(13); - if (lookahead == ')') - ADVANCE(3); - if (lookahead == '*') - ADVANCE(8); - if (lookahead == '+') - ADVANCE(5); - if (lookahead == '-') - ADVANCE(6); - if (lookahead == '/') - ADVANCE(9); - if ('0' <= lookahead && lookahead <= '9') ADVANCE(14); + if (lookahead == '(') + ADVANCE(11); + if (lookahead == ')') + ADVANCE(8); + if (lookahead == '*') + ADVANCE(2); + if (lookahead == '+') + ADVANCE(3); + if (lookahead == '-') + ADVANCE(4); + if (lookahead == '/') + ADVANCE(5); + if ('0' <= lookahead && lookahead <= '9') + ADVANCE(12); if (('A' <= lookahead && lookahead <= 'Z') || ('a' <= lookahead && lookahead <= 'z')) - ADVANCE(15); + ADVANCE(13); if (lookahead == '^') - ADVANCE(11); + ADVANCE(6); LEX_ERROR(); default: LEX_PANIC(); @@ -394,140 +207,38 @@ LEX_FN() { } LEX_STATES = { - [0] = 12, - [1] = 23, - [2] = 12, - [3] = 0, - [4] = 21, - [5] = 12, + [0] = 10, + [1] = 0, + [2] = 0, + [3] = 10, + [4] = 0, + [5] = 10, [6] = 0, - [7] = 20, - [8] = 12, - [9] = 0, + [7] = 10, + [8] = 0, + [9] = 10, [10] = 0, - [11] = 12, - [12] = 4, - [13] = 12, - [14] = 2, - [15] = 18, - [16] = 12, - [17] = 2, - [18] = 17, - [19] = 12, - [20] = 2, - [21] = 2, - [22] = 12, + [11] = 10, + [12] = 0, + [13] = 10, + [14] = 7, + [15] = 7, + [16] = 10, + [17] = 7, + [18] = 10, + [19] = 7, + [20] = 10, + [21] = 7, + [22] = 10, [23] = 7, - [24] = 12, - [25] = 4, - [26] = 16, - [27] = 12, - [28] = 4, - [29] = 4, - [30] = 12, - [31] = 10, - [32] = 12, - [33] = 7, - [34] = 7, - [35] = 12, - [36] = 2, - [37] = 7, - [38] = 2, - [39] = 7, - [40] = 10, - [41] = 4, - [42] = 12, - [43] = 2, - [44] = 10, - [45] = 2, - [46] = 4, - [47] = 4, - [48] = 16, - [49] = 12, - [50] = 2, - [51] = 16, - [52] = 12, - [53] = 4, - [54] = 2, - [55] = 2, - [56] = 2, - [57] = 17, - [58] = 12, - [59] = 2, - [60] = 17, - [61] = 12, - [62] = 2, - [63] = 19, - [64] = 12, - [65] = 18, - [66] = 18, - [67] = 12, - [68] = 2, - [69] = 18, - [70] = 18, - [71] = 19, - [72] = 2, - [73] = 12, - [74] = 2, - [75] = 19, - [76] = 12, - [77] = 2, - [78] = 2, - [79] = 0, - [80] = 0, - [81] = 20, - [82] = 12, - [83] = 2, - [84] = 20, - [85] = 12, - [86] = 0, - [87] = 22, - [88] = 12, - [89] = 21, - [90] = 21, - [91] = 12, - [92] = 2, - [93] = 21, - [94] = 21, - [95] = 22, - [96] = 0, - [97] = 12, - [98] = 2, - [99] = 22, - [100] = 12, - [101] = 0, - [102] = 25, - [103] = 12, - [104] = 23, - [105] = 24, - [106] = 12, - [107] = 23, - [108] = 23, - [109] = 12, - [110] = 2, - [111] = 23, - [112] = 23, - [113] = 24, - [114] = 12, - [115] = 2, - [116] = 24, - [117] = 12, - [118] = 23, - [119] = 26, - [120] = 12, - [121] = 25, - [122] = 25, - [123] = 12, - [124] = 2, - [125] = 25, - [126] = 0, - [127] = 25, - [128] = 0, - [129] = 26, - [130] = 23, - [131] = 12, - [132] = 2, - [133] = 26, + [24] = 10, + [25] = 7, + [26] = 10, + [27] = 7, + [28] = 7, + [29] = 9, + [30] = 0, + [31] = 9, }; #pragma GCC diagnostic push @@ -535,906 +246,304 @@ LEX_STATES = { PARSE_TABLE = { [0] = { - [ts_sym__operand1] = SHIFT(1), - [ts_sym__operand2] = SHIFT(102), - [ts_sym__operand3] = SHIFT(119), - [ts_sym_difference] = SHIFT(126), - [ts_sym_exponent] = SHIFT(127), - [ts_sym_expression] = SHIFT(128), - [ts_sym_grouping] = SHIFT(129), - [ts_sym_number] = SHIFT(129), - [ts_sym_product] = SHIFT(130), - [ts_sym_quotient] = SHIFT(130), - [ts_sym_sum] = SHIFT(126), - [ts_sym_variable] = SHIFT(129), - [ts_aux_sym_token1] = SHIFT(131), + [ts_sym_difference] = SHIFT(1), + [ts_sym_exponent] = SHIFT(1), + [ts_sym_expression] = SHIFT(2), + [ts_sym_group] = SHIFT(1), + [ts_sym_number] = SHIFT(1), + [ts_sym_product] = SHIFT(1), + [ts_sym_quotient] = SHIFT(1), + [ts_sym_sum] = SHIFT(1), + [ts_sym_variable] = SHIFT(1), + [ts_aux_sym_token6] = SHIFT(13), }, [1] = { - [ts_aux_sym_token3] = SHIFT(2), - [ts_aux_sym_token4] = SHIFT(100), - [ts_builtin_sym_end] = REDUCE(ts_sym_sum, 1), - }, - [2] = { - [ts_sym__operand1] = SHIFT(3), - [ts_sym__operand2] = SHIFT(4), - [ts_sym__operand3] = SHIFT(87), - [ts_sym_exponent] = SHIFT(94), - [ts_sym_grouping] = SHIFT(95), - [ts_sym_number] = SHIFT(95), - [ts_sym_product] = SHIFT(96), - [ts_sym_quotient] = SHIFT(96), - [ts_sym_variable] = SHIFT(95), - [ts_aux_sym_token1] = SHIFT(97), - }, - [3] = { - [ts_builtin_sym_end] = REDUCE(ts_sym_sum, 3), - }, - [4] = { - [ts_aux_sym_token5] = SHIFT(5), - [ts_aux_sym_token6] = SHIFT(85), - [ts_builtin_sym_end] = REDUCE(ts_sym_quotient, 1), - }, - [5] = { - [ts_sym__operand2] = SHIFT(6), - [ts_sym__operand3] = SHIFT(7), - [ts_sym_exponent] = SHIFT(80), - [ts_sym_grouping] = SHIFT(81), - [ts_sym_number] = SHIFT(81), - [ts_sym_variable] = SHIFT(81), - [ts_aux_sym_token1] = SHIFT(82), - }, - [6] = { - [ts_builtin_sym_end] = REDUCE(ts_sym_product, 3), - }, - [7] = { - [ts_aux_sym_token7] = SHIFT(8), - [ts_builtin_sym_end] = REDUCE(ts_sym_exponent, 1), - }, - [8] = { - [ts_sym__operand3] = SHIFT(9), - [ts_sym_grouping] = SHIFT(10), - [ts_sym_number] = SHIFT(10), - [ts_sym_variable] = SHIFT(10), - [ts_aux_sym_token1] = SHIFT(11), - }, - [9] = { - [ts_builtin_sym_end] = REDUCE(ts_sym_exponent, 3), - }, - [10] = { - [ts_builtin_sym_end] = REDUCE(ts_sym__operand3, 1), - }, - [11] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(78), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(78), - }, - [12] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_sum, 1), - [ts_aux_sym_token3] = SHIFT(13), - [ts_aux_sym_token4] = SHIFT(76), - }, - [13] = { - [ts_sym__operand1] = SHIFT(14), - [ts_sym__operand2] = SHIFT(15), - [ts_sym__operand3] = SHIFT(63), - [ts_sym_exponent] = SHIFT(70), - [ts_sym_grouping] = SHIFT(71), - [ts_sym_number] = SHIFT(71), - [ts_sym_product] = SHIFT(72), - [ts_sym_quotient] = SHIFT(72), - [ts_sym_variable] = SHIFT(71), - [ts_aux_sym_token1] = SHIFT(73), - }, - [14] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_sum, 3), - }, - [15] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_product, 1), - [ts_aux_sym_token5] = SHIFT(16), - [ts_aux_sym_token6] = SHIFT(61), - }, - [16] = { - [ts_sym__operand2] = SHIFT(17), - [ts_sym__operand3] = SHIFT(18), - [ts_sym_exponent] = SHIFT(56), - [ts_sym_grouping] = SHIFT(57), - [ts_sym_number] = SHIFT(57), - [ts_sym_variable] = SHIFT(57), - [ts_aux_sym_token1] = SHIFT(58), - }, - [17] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_product, 3), - }, - [18] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token7] = SHIFT(19), - }, - [19] = { - [ts_sym__operand3] = SHIFT(20), - [ts_sym_grouping] = SHIFT(21), - [ts_sym_number] = SHIFT(21), - [ts_sym_variable] = SHIFT(21), - [ts_aux_sym_token1] = SHIFT(22), - }, - [20] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_exponent, 3), - }, - [21] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand3, 1), - }, - [22] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(54), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(54), - }, - [23] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_product, 1), - [ts_aux_sym_token3] = REDUCE(ts_sym_quotient, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym_quotient, 1), - [ts_aux_sym_token5] = SHIFT(24), - [ts_aux_sym_token6] = SHIFT(52), - }, - [24] = { - [ts_sym__operand2] = SHIFT(25), - [ts_sym__operand3] = SHIFT(26), - [ts_sym_exponent] = SHIFT(47), - [ts_sym_grouping] = SHIFT(48), - [ts_sym_number] = SHIFT(48), - [ts_sym_variable] = SHIFT(48), - [ts_aux_sym_token1] = SHIFT(49), - }, - [25] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_product, 3), - [ts_aux_sym_token3] = REDUCE(ts_sym_product, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_product, 3), - }, - [26] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token3] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token7] = SHIFT(27), - }, - [27] = { - [ts_sym__operand3] = SHIFT(28), - [ts_sym_grouping] = SHIFT(29), - [ts_sym_number] = SHIFT(29), - [ts_sym_variable] = SHIFT(29), - [ts_aux_sym_token1] = SHIFT(30), - }, - [28] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token3] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_exponent, 3), - }, - [29] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token3] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand3, 1), - }, - [30] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(45), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(45), - }, - [31] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token3] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token7] = SHIFT(32), - }, - [32] = { - [ts_sym__operand3] = SHIFT(33), - [ts_sym_grouping] = SHIFT(34), - [ts_sym_number] = SHIFT(34), - [ts_sym_variable] = SHIFT(34), - [ts_aux_sym_token1] = SHIFT(35), - }, - [33] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token3] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token5] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_exponent, 3), - }, - [34] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token3] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand3, 1), - }, - [35] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(38), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(38), - }, - [36] = { + [ts_aux_sym_token1] = REDUCE(ts_sym_expression, 1), [ts_aux_sym_token2] = REDUCE(ts_sym_expression, 1), - }, - [37] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token3] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand2, 1), - }, - [38] = { - [ts_aux_sym_token2] = SHIFT(39), - }, - [39] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token3] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token5] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_grouping, 3), - }, - [40] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token3] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token7] = REDUCE(ts_sym__operand3, 1), - }, - [41] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand1, 1), - [ts_aux_sym_token3] = REDUCE(ts_sym__operand1, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand1, 1), - }, - [42] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(43), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(43), - }, - [43] = { - [ts_aux_sym_token2] = SHIFT(44), - }, - [44] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token3] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token5] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token7] = REDUCE(ts_sym_grouping, 3), - }, - [45] = { - [ts_aux_sym_token2] = SHIFT(46), - }, - [46] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token3] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_grouping, 3), - }, - [47] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token3] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand2, 1), - }, - [48] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token3] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token7] = REDUCE(ts_sym__operand3, 1), - }, - [49] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(50), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(50), - }, - [50] = { - [ts_aux_sym_token2] = SHIFT(51), - }, - [51] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token3] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token7] = REDUCE(ts_sym_grouping, 3), - }, - [52] = { - [ts_sym__operand2] = SHIFT(53), - [ts_sym__operand3] = SHIFT(26), - [ts_sym_exponent] = SHIFT(47), - [ts_sym_grouping] = SHIFT(48), - [ts_sym_number] = SHIFT(48), - [ts_sym_variable] = SHIFT(48), - [ts_aux_sym_token1] = SHIFT(49), - }, - [53] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_quotient, 3), - [ts_aux_sym_token3] = REDUCE(ts_sym_quotient, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_quotient, 3), - }, - [54] = { - [ts_aux_sym_token2] = SHIFT(55), - }, - [55] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_grouping, 3), - }, - [56] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand2, 1), - }, - [57] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token7] = REDUCE(ts_sym__operand3, 1), - }, - [58] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(59), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(59), - }, - [59] = { - [ts_aux_sym_token2] = SHIFT(60), - }, - [60] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token7] = REDUCE(ts_sym_grouping, 3), - }, - [61] = { - [ts_sym__operand2] = SHIFT(62), - [ts_sym__operand3] = SHIFT(18), - [ts_sym_exponent] = SHIFT(56), - [ts_sym_grouping] = SHIFT(57), - [ts_sym_number] = SHIFT(57), - [ts_sym_variable] = SHIFT(57), - [ts_aux_sym_token1] = SHIFT(58), - }, - [62] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_quotient, 3), - }, - [63] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token7] = SHIFT(64), - }, - [64] = { - [ts_sym__operand3] = SHIFT(65), - [ts_sym_grouping] = SHIFT(66), - [ts_sym_number] = SHIFT(66), - [ts_sym_variable] = SHIFT(66), - [ts_aux_sym_token1] = SHIFT(67), - }, - [65] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token5] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_exponent, 3), - }, - [66] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand3, 1), - }, - [67] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(68), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(68), - }, - [68] = { - [ts_aux_sym_token2] = SHIFT(69), - }, - [69] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token5] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_grouping, 3), - }, - [70] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand2, 1), - }, - [71] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token7] = REDUCE(ts_sym__operand3, 1), - }, - [72] = { - [ts_aux_sym_token2] = REDUCE(ts_sym__operand1, 1), - }, - [73] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(74), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(74), - }, - [74] = { - [ts_aux_sym_token2] = SHIFT(75), - }, - [75] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token5] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token7] = REDUCE(ts_sym_grouping, 3), - }, - [76] = { - [ts_sym__operand1] = SHIFT(77), - [ts_sym__operand2] = SHIFT(15), - [ts_sym__operand3] = SHIFT(63), - [ts_sym_exponent] = SHIFT(70), - [ts_sym_grouping] = SHIFT(71), - [ts_sym_number] = SHIFT(71), - [ts_sym_product] = SHIFT(72), - [ts_sym_quotient] = SHIFT(72), - [ts_sym_variable] = SHIFT(71), - [ts_aux_sym_token1] = SHIFT(73), - }, - [77] = { - [ts_aux_sym_token2] = REDUCE(ts_sym_difference, 3), - }, - [78] = { - [ts_aux_sym_token2] = SHIFT(79), - }, - [79] = { - [ts_builtin_sym_end] = REDUCE(ts_sym_grouping, 3), - }, - [80] = { - [ts_builtin_sym_end] = REDUCE(ts_sym__operand2, 1), - }, - [81] = { - [ts_aux_sym_token7] = REDUCE(ts_sym__operand3, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand3, 1), - }, - [82] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(83), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(83), - }, - [83] = { - [ts_aux_sym_token2] = SHIFT(84), - }, - [84] = { - [ts_aux_sym_token7] = REDUCE(ts_sym_grouping, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_grouping, 3), - }, - [85] = { - [ts_sym__operand2] = SHIFT(86), - [ts_sym__operand3] = SHIFT(7), - [ts_sym_exponent] = SHIFT(80), - [ts_sym_grouping] = SHIFT(81), - [ts_sym_number] = SHIFT(81), - [ts_sym_variable] = SHIFT(81), - [ts_aux_sym_token1] = SHIFT(82), - }, - [86] = { - [ts_builtin_sym_end] = REDUCE(ts_sym_quotient, 3), - }, - [87] = { - [ts_aux_sym_token5] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token7] = SHIFT(88), - [ts_builtin_sym_end] = REDUCE(ts_sym_exponent, 1), - }, - [88] = { - [ts_sym__operand3] = SHIFT(89), - [ts_sym_grouping] = SHIFT(90), - [ts_sym_number] = SHIFT(90), - [ts_sym_variable] = SHIFT(90), - [ts_aux_sym_token1] = SHIFT(91), - }, - [89] = { - [ts_aux_sym_token5] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_exponent, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_exponent, 3), - }, - [90] = { - [ts_aux_sym_token5] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand3, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand3, 1), - }, - [91] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(92), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(92), - }, - [92] = { - [ts_aux_sym_token2] = SHIFT(93), - }, - [93] = { - [ts_aux_sym_token5] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_grouping, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_grouping, 3), - }, - [94] = { - [ts_aux_sym_token5] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand2, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand2, 1), - }, - [95] = { - [ts_aux_sym_token5] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token7] = REDUCE(ts_sym__operand3, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand3, 1), - }, - [96] = { - [ts_builtin_sym_end] = REDUCE(ts_sym__operand1, 1), - }, - [97] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(98), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(98), - }, - [98] = { - [ts_aux_sym_token2] = SHIFT(99), - }, - [99] = { - [ts_aux_sym_token5] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token7] = REDUCE(ts_sym_grouping, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_grouping, 3), - }, - [100] = { - [ts_sym__operand1] = SHIFT(101), - [ts_sym__operand2] = SHIFT(4), - [ts_sym__operand3] = SHIFT(87), - [ts_sym_exponent] = SHIFT(94), - [ts_sym_grouping] = SHIFT(95), - [ts_sym_number] = SHIFT(95), - [ts_sym_product] = SHIFT(96), - [ts_sym_quotient] = SHIFT(96), - [ts_sym_variable] = SHIFT(95), - [ts_aux_sym_token1] = SHIFT(97), - }, - [101] = { - [ts_builtin_sym_end] = REDUCE(ts_sym_difference, 3), - }, - [102] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_product, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym_quotient, 1), - [ts_aux_sym_token5] = SHIFT(103), - [ts_aux_sym_token6] = SHIFT(117), - [ts_builtin_sym_end] = REDUCE(ts_sym_product, 1), - }, - [103] = { - [ts_sym__operand2] = SHIFT(104), - [ts_sym__operand3] = SHIFT(105), - [ts_sym_exponent] = SHIFT(112), - [ts_sym_grouping] = SHIFT(113), - [ts_sym_number] = SHIFT(113), - [ts_sym_variable] = SHIFT(113), - [ts_aux_sym_token1] = SHIFT(114), - }, - [104] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_product, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_product, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_product, 3), - }, - [105] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token7] = SHIFT(106), - [ts_builtin_sym_end] = REDUCE(ts_sym_exponent, 1), - }, - [106] = { - [ts_sym__operand3] = SHIFT(107), - [ts_sym_grouping] = SHIFT(108), - [ts_sym_number] = SHIFT(108), - [ts_sym_variable] = SHIFT(108), - [ts_aux_sym_token1] = SHIFT(109), - }, - [107] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_exponent, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_exponent, 3), - }, - [108] = { - [ts_aux_sym_token3] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand3, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand3, 1), - }, - [109] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(110), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(110), - }, - [110] = { - [ts_aux_sym_token2] = SHIFT(111), - }, - [111] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_grouping, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_grouping, 3), - }, - [112] = { - [ts_aux_sym_token3] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand2, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand2, 1), - }, - [113] = { - [ts_aux_sym_token3] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token7] = REDUCE(ts_sym__operand3, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand3, 1), - }, - [114] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(115), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(115), - }, - [115] = { - [ts_aux_sym_token2] = SHIFT(116), - }, - [116] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token7] = REDUCE(ts_sym_grouping, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_grouping, 3), - }, - [117] = { - [ts_sym__operand2] = SHIFT(118), - [ts_sym__operand3] = SHIFT(105), - [ts_sym_exponent] = SHIFT(112), - [ts_sym_grouping] = SHIFT(113), - [ts_sym_number] = SHIFT(113), - [ts_sym_variable] = SHIFT(113), - [ts_aux_sym_token1] = SHIFT(114), - }, - [118] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_quotient, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_quotient, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_quotient, 3), - }, - [119] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym_exponent, 1), - [ts_aux_sym_token7] = SHIFT(120), - [ts_builtin_sym_end] = REDUCE(ts_sym_exponent, 1), - }, - [120] = { - [ts_sym__operand3] = SHIFT(121), - [ts_sym_grouping] = SHIFT(122), - [ts_sym_number] = SHIFT(122), - [ts_sym_variable] = SHIFT(122), - [ts_aux_sym_token1] = SHIFT(123), - }, - [121] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token5] = REDUCE(ts_sym_exponent, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_exponent, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_exponent, 3), - }, - [122] = { - [ts_aux_sym_token3] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand3, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand3, 1), - }, - [123] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(124), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(124), - }, - [124] = { - [ts_aux_sym_token2] = SHIFT(125), - }, - [125] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token5] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_grouping, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_grouping, 3), - }, - [126] = { + [ts_aux_sym_token3] = REDUCE(ts_sym_expression, 1), + [ts_aux_sym_token4] = REDUCE(ts_sym_expression, 1), + [ts_aux_sym_token5] = REDUCE(ts_sym_expression, 1), [ts_builtin_sym_end] = REDUCE(ts_sym_expression, 1), }, - [127] = { - [ts_aux_sym_token3] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym__operand2, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand2, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand2, 1), - }, - [128] = { + [2] = { + [ts_aux_sym_token1] = SHIFT(3), + [ts_aux_sym_token2] = SHIFT(5), + [ts_aux_sym_token3] = SHIFT(7), + [ts_aux_sym_token4] = SHIFT(9), + [ts_aux_sym_token5] = SHIFT(11), [ts_builtin_sym_end] = ACCEPT_INPUT(), }, - [129] = { - [ts_aux_sym_token3] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token5] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token6] = REDUCE(ts_sym__operand3, 1), - [ts_aux_sym_token7] = REDUCE(ts_sym__operand3, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand3, 1), + [3] = { + [ts_sym_difference] = SHIFT(1), + [ts_sym_exponent] = SHIFT(1), + [ts_sym_expression] = SHIFT(4), + [ts_sym_group] = SHIFT(1), + [ts_sym_number] = SHIFT(1), + [ts_sym_product] = SHIFT(1), + [ts_sym_quotient] = SHIFT(1), + [ts_sym_sum] = SHIFT(1), + [ts_sym_variable] = SHIFT(1), + [ts_aux_sym_token6] = SHIFT(13), }, - [130] = { - [ts_aux_sym_token3] = REDUCE(ts_sym__operand1, 1), - [ts_aux_sym_token4] = REDUCE(ts_sym__operand1, 1), - [ts_builtin_sym_end] = REDUCE(ts_sym__operand1, 1), + [4] = { + [ts_aux_sym_token1] = SHIFT(3), + [ts_aux_sym_token2] = SHIFT(5), + [ts_aux_sym_token3] = SHIFT(7), + [ts_aux_sym_token4] = SHIFT(9), + [ts_aux_sym_token5] = SHIFT(11), + [ts_builtin_sym_end] = REDUCE(ts_sym_sum, 3), }, - [131] = { - [ts_sym__operand1] = SHIFT(12), - [ts_sym__operand2] = SHIFT(23), - [ts_sym__operand3] = SHIFT(31), - [ts_sym_difference] = SHIFT(36), - [ts_sym_exponent] = SHIFT(37), - [ts_sym_expression] = SHIFT(132), - [ts_sym_grouping] = SHIFT(40), - [ts_sym_number] = SHIFT(40), - [ts_sym_product] = SHIFT(41), - [ts_sym_quotient] = SHIFT(41), - [ts_sym_sum] = SHIFT(36), - [ts_sym_variable] = SHIFT(40), - [ts_aux_sym_token1] = SHIFT(42), - [ts_builtin_sym_error] = SHIFT(132), + [5] = { + [ts_sym_difference] = SHIFT(1), + [ts_sym_exponent] = SHIFT(1), + [ts_sym_expression] = SHIFT(6), + [ts_sym_group] = SHIFT(1), + [ts_sym_number] = SHIFT(1), + [ts_sym_product] = SHIFT(1), + [ts_sym_quotient] = SHIFT(1), + [ts_sym_sum] = SHIFT(1), + [ts_sym_variable] = SHIFT(1), + [ts_aux_sym_token6] = SHIFT(13), }, - [132] = { - [ts_aux_sym_token2] = SHIFT(133), + [6] = { + [ts_aux_sym_token1] = SHIFT(3), + [ts_aux_sym_token2] = SHIFT(5), + [ts_aux_sym_token3] = SHIFT(7), + [ts_aux_sym_token4] = SHIFT(9), + [ts_aux_sym_token5] = SHIFT(11), + [ts_builtin_sym_end] = REDUCE(ts_sym_difference, 3), }, - [133] = { - [ts_aux_sym_token3] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token4] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token5] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token6] = REDUCE(ts_sym_grouping, 3), - [ts_aux_sym_token7] = REDUCE(ts_sym_grouping, 3), - [ts_builtin_sym_end] = REDUCE(ts_sym_grouping, 3), + [7] = { + [ts_sym_difference] = SHIFT(1), + [ts_sym_exponent] = SHIFT(1), + [ts_sym_expression] = SHIFT(8), + [ts_sym_group] = SHIFT(1), + [ts_sym_number] = SHIFT(1), + [ts_sym_product] = SHIFT(1), + [ts_sym_quotient] = SHIFT(1), + [ts_sym_sum] = SHIFT(1), + [ts_sym_variable] = SHIFT(1), + [ts_aux_sym_token6] = SHIFT(13), + }, + [8] = { + [ts_aux_sym_token1] = REDUCE(ts_sym_product, 3), + [ts_aux_sym_token2] = REDUCE(ts_sym_product, 3), + [ts_aux_sym_token3] = SHIFT(7), + [ts_aux_sym_token4] = SHIFT(9), + [ts_aux_sym_token5] = SHIFT(11), + [ts_builtin_sym_end] = REDUCE(ts_sym_product, 3), + }, + [9] = { + [ts_sym_difference] = SHIFT(1), + [ts_sym_exponent] = SHIFT(1), + [ts_sym_expression] = SHIFT(10), + [ts_sym_group] = SHIFT(1), + [ts_sym_number] = SHIFT(1), + [ts_sym_product] = SHIFT(1), + [ts_sym_quotient] = SHIFT(1), + [ts_sym_sum] = SHIFT(1), + [ts_sym_variable] = SHIFT(1), + [ts_aux_sym_token6] = SHIFT(13), + }, + [10] = { + [ts_aux_sym_token1] = REDUCE(ts_sym_quotient, 3), + [ts_aux_sym_token2] = REDUCE(ts_sym_quotient, 3), + [ts_aux_sym_token3] = SHIFT(7), + [ts_aux_sym_token4] = SHIFT(9), + [ts_aux_sym_token5] = SHIFT(11), + [ts_builtin_sym_end] = REDUCE(ts_sym_quotient, 3), + }, + [11] = { + [ts_sym_difference] = SHIFT(1), + [ts_sym_exponent] = SHIFT(1), + [ts_sym_expression] = SHIFT(12), + [ts_sym_group] = SHIFT(1), + [ts_sym_number] = SHIFT(1), + [ts_sym_product] = SHIFT(1), + [ts_sym_quotient] = SHIFT(1), + [ts_sym_sum] = SHIFT(1), + [ts_sym_variable] = SHIFT(1), + [ts_aux_sym_token6] = SHIFT(13), + }, + [12] = { + [ts_aux_sym_token1] = REDUCE(ts_sym_exponent, 3), + [ts_aux_sym_token2] = REDUCE(ts_sym_exponent, 3), + [ts_aux_sym_token3] = REDUCE(ts_sym_exponent, 3), + [ts_aux_sym_token4] = REDUCE(ts_sym_exponent, 3), + [ts_aux_sym_token5] = SHIFT(11), + [ts_builtin_sym_end] = REDUCE(ts_sym_exponent, 3), + }, + [13] = { + [ts_sym_difference] = SHIFT(14), + [ts_sym_exponent] = SHIFT(14), + [ts_sym_expression] = SHIFT(15), + [ts_sym_group] = SHIFT(14), + [ts_sym_number] = SHIFT(14), + [ts_sym_product] = SHIFT(14), + [ts_sym_quotient] = SHIFT(14), + [ts_sym_sum] = SHIFT(14), + [ts_sym_variable] = SHIFT(14), + [ts_aux_sym_token6] = SHIFT(26), + [ts_builtin_sym_error] = SHIFT(31), + }, + [14] = { + [ts_aux_sym_token1] = REDUCE(ts_sym_expression, 1), + [ts_aux_sym_token2] = REDUCE(ts_sym_expression, 1), + [ts_aux_sym_token3] = REDUCE(ts_sym_expression, 1), + [ts_aux_sym_token4] = REDUCE(ts_sym_expression, 1), + [ts_aux_sym_token5] = REDUCE(ts_sym_expression, 1), + [ts_aux_sym_token7] = REDUCE(ts_sym_expression, 1), + }, + [15] = { + [ts_aux_sym_token1] = SHIFT(16), + [ts_aux_sym_token2] = SHIFT(18), + [ts_aux_sym_token3] = SHIFT(20), + [ts_aux_sym_token4] = SHIFT(22), + [ts_aux_sym_token5] = SHIFT(24), + [ts_aux_sym_token7] = SHIFT(30), + }, + [16] = { + [ts_sym_difference] = SHIFT(14), + [ts_sym_exponent] = SHIFT(14), + [ts_sym_expression] = SHIFT(17), + [ts_sym_group] = SHIFT(14), + [ts_sym_number] = SHIFT(14), + [ts_sym_product] = SHIFT(14), + [ts_sym_quotient] = SHIFT(14), + [ts_sym_sum] = SHIFT(14), + [ts_sym_variable] = SHIFT(14), + [ts_aux_sym_token6] = SHIFT(26), + }, + [17] = { + [ts_aux_sym_token1] = SHIFT(16), + [ts_aux_sym_token2] = SHIFT(18), + [ts_aux_sym_token3] = SHIFT(20), + [ts_aux_sym_token4] = SHIFT(22), + [ts_aux_sym_token5] = SHIFT(24), + [ts_aux_sym_token7] = REDUCE(ts_sym_sum, 3), + }, + [18] = { + [ts_sym_difference] = SHIFT(14), + [ts_sym_exponent] = SHIFT(14), + [ts_sym_expression] = SHIFT(19), + [ts_sym_group] = SHIFT(14), + [ts_sym_number] = SHIFT(14), + [ts_sym_product] = SHIFT(14), + [ts_sym_quotient] = SHIFT(14), + [ts_sym_sum] = SHIFT(14), + [ts_sym_variable] = SHIFT(14), + [ts_aux_sym_token6] = SHIFT(26), + }, + [19] = { + [ts_aux_sym_token1] = SHIFT(16), + [ts_aux_sym_token2] = SHIFT(18), + [ts_aux_sym_token3] = SHIFT(20), + [ts_aux_sym_token4] = SHIFT(22), + [ts_aux_sym_token5] = SHIFT(24), + [ts_aux_sym_token7] = REDUCE(ts_sym_difference, 3), + }, + [20] = { + [ts_sym_difference] = SHIFT(14), + [ts_sym_exponent] = SHIFT(14), + [ts_sym_expression] = SHIFT(21), + [ts_sym_group] = SHIFT(14), + [ts_sym_number] = SHIFT(14), + [ts_sym_product] = SHIFT(14), + [ts_sym_quotient] = SHIFT(14), + [ts_sym_sum] = SHIFT(14), + [ts_sym_variable] = SHIFT(14), + [ts_aux_sym_token6] = SHIFT(26), + }, + [21] = { + [ts_aux_sym_token1] = REDUCE(ts_sym_product, 3), + [ts_aux_sym_token2] = REDUCE(ts_sym_product, 3), + [ts_aux_sym_token3] = SHIFT(20), + [ts_aux_sym_token4] = SHIFT(22), + [ts_aux_sym_token5] = SHIFT(24), + [ts_aux_sym_token7] = REDUCE(ts_sym_product, 3), + }, + [22] = { + [ts_sym_difference] = SHIFT(14), + [ts_sym_exponent] = SHIFT(14), + [ts_sym_expression] = SHIFT(23), + [ts_sym_group] = SHIFT(14), + [ts_sym_number] = SHIFT(14), + [ts_sym_product] = SHIFT(14), + [ts_sym_quotient] = SHIFT(14), + [ts_sym_sum] = SHIFT(14), + [ts_sym_variable] = SHIFT(14), + [ts_aux_sym_token6] = SHIFT(26), + }, + [23] = { + [ts_aux_sym_token1] = REDUCE(ts_sym_quotient, 3), + [ts_aux_sym_token2] = REDUCE(ts_sym_quotient, 3), + [ts_aux_sym_token3] = SHIFT(20), + [ts_aux_sym_token4] = SHIFT(22), + [ts_aux_sym_token5] = SHIFT(24), + [ts_aux_sym_token7] = REDUCE(ts_sym_quotient, 3), + }, + [24] = { + [ts_sym_difference] = SHIFT(14), + [ts_sym_exponent] = SHIFT(14), + [ts_sym_expression] = SHIFT(25), + [ts_sym_group] = SHIFT(14), + [ts_sym_number] = SHIFT(14), + [ts_sym_product] = SHIFT(14), + [ts_sym_quotient] = SHIFT(14), + [ts_sym_sum] = SHIFT(14), + [ts_sym_variable] = SHIFT(14), + [ts_aux_sym_token6] = SHIFT(26), + }, + [25] = { + [ts_aux_sym_token1] = REDUCE(ts_sym_exponent, 3), + [ts_aux_sym_token2] = REDUCE(ts_sym_exponent, 3), + [ts_aux_sym_token3] = REDUCE(ts_sym_exponent, 3), + [ts_aux_sym_token4] = REDUCE(ts_sym_exponent, 3), + [ts_aux_sym_token5] = SHIFT(24), + [ts_aux_sym_token7] = REDUCE(ts_sym_exponent, 3), + }, + [26] = { + [ts_sym_difference] = SHIFT(14), + [ts_sym_exponent] = SHIFT(14), + [ts_sym_expression] = SHIFT(27), + [ts_sym_group] = SHIFT(14), + [ts_sym_number] = SHIFT(14), + [ts_sym_product] = SHIFT(14), + [ts_sym_quotient] = SHIFT(14), + [ts_sym_sum] = SHIFT(14), + [ts_sym_variable] = SHIFT(14), + [ts_aux_sym_token6] = SHIFT(26), + [ts_builtin_sym_error] = SHIFT(29), + }, + [27] = { + [ts_aux_sym_token1] = SHIFT(16), + [ts_aux_sym_token2] = SHIFT(18), + [ts_aux_sym_token3] = SHIFT(20), + [ts_aux_sym_token4] = SHIFT(22), + [ts_aux_sym_token5] = SHIFT(24), + [ts_aux_sym_token7] = SHIFT(28), + }, + [28] = { + [ts_aux_sym_token1] = REDUCE(ts_sym_group, 3), + [ts_aux_sym_token2] = REDUCE(ts_sym_group, 3), + [ts_aux_sym_token3] = REDUCE(ts_sym_group, 3), + [ts_aux_sym_token4] = REDUCE(ts_sym_group, 3), + [ts_aux_sym_token5] = REDUCE(ts_sym_group, 3), + [ts_aux_sym_token7] = REDUCE(ts_sym_group, 3), + }, + [29] = { + [ts_aux_sym_token7] = SHIFT(28), + }, + [30] = { + [ts_aux_sym_token1] = REDUCE(ts_sym_group, 3), + [ts_aux_sym_token2] = REDUCE(ts_sym_group, 3), + [ts_aux_sym_token3] = REDUCE(ts_sym_group, 3), + [ts_aux_sym_token4] = REDUCE(ts_sym_group, 3), + [ts_aux_sym_token5] = REDUCE(ts_sym_group, 3), + [ts_builtin_sym_end] = REDUCE(ts_sym_group, 3), + }, + [31] = { + [ts_aux_sym_token7] = SHIFT(30), }, }; diff --git a/include/tree_sitter/compiler.h b/include/tree_sitter/compiler.h index 941e2c6d..93678b86 100644 --- a/include/tree_sitter/compiler.h +++ b/include/tree_sitter/compiler.h @@ -20,6 +20,7 @@ namespace tree_sitter { rule_ptr pattern(const std::string &value); rule_ptr str(const std::string &value); rule_ptr err(const rule_ptr &rule); + rule_ptr prec(int precedence, rule_ptr rule); } class Grammar { diff --git a/include/tree_sitter/parser.h b/include/tree_sitter/parser.h index 3e9e74dd..a96ac7e3 100644 --- a/include/tree_sitter/parser.h +++ b/include/tree_sitter/parser.h @@ -55,7 +55,7 @@ ts_lexer_start_token(lexer); { return ts_lexer_build_node(lexer, ts_builtin_sym_error); } #define LEX_PANIC() \ -{ DEBUG_LEX("\nLex error: unexpected state %d", lex_state); return NULL; } +{ DEBUG_LEX("LEX ERROR: unexpected state %d", lex_state); return NULL; } #define PARSE_TABLE \ static const ts_parse_action ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] diff --git a/spec/compiler/build_tables/conflict_manager_spec.cc b/spec/compiler/build_tables/conflict_manager_spec.cc index 2a8c237e..cd569f7b 100644 --- a/spec/compiler/build_tables/conflict_manager_spec.cc +++ b/spec/compiler/build_tables/conflict_manager_spec.cc @@ -59,49 +59,117 @@ describe("resolving parse conflicts", []() { Symbol sym2("rule2"); it("favors non-errors over parse errors", [&]() { - should_update = manager->resolve_parse_action(sym1, ParseAction::Error(), ParseAction::Shift(2)); + should_update = manager->resolve_parse_action(sym1, ParseAction::Error(), ParseAction::Shift(2, { 0 })); AssertThat(should_update, IsTrue()); - should_update = manager->resolve_parse_action(sym1, ParseAction::Shift(2), ParseAction::Error()); + should_update = manager->resolve_parse_action(sym1, ParseAction::Shift(2, { 0 }), ParseAction::Error()); AssertThat(should_update, IsFalse()); }); describe("shift/reduce conflicts", [&]() { - it("records a conflict", [&]() { - manager->resolve_parse_action(sym1, ParseAction::Reduce(sym2, 1), ParseAction::Shift(2)); - manager->resolve_parse_action(sym1, ParseAction::Shift(2), ParseAction::Reduce(sym2, 1)); - - AssertThat(manager->conflicts(), Equals(vector({ - Conflict("rule1: shift / reduce rule2") - }))); + describe("when the shift has higher precedence", [&]() { + ParseAction shift = ParseAction::Shift(2, { 3 }); + ParseAction reduce = ParseAction::Reduce(sym2, 1, 1); + + it("does not record a conflict", [&]() { + manager->resolve_parse_action(sym1, shift, reduce); + manager->resolve_parse_action(sym1, reduce, shift); + AssertThat(manager->conflicts(), IsEmpty()); + }); + + it("favors the shift", [&]() { + AssertThat(manager->resolve_parse_action(sym1, shift, reduce), IsFalse()); + AssertThat(manager->resolve_parse_action(sym1, reduce, shift), IsTrue()); + }); }); + + describe("when the reduce has higher precedence", [&]() { + ParseAction shift = ParseAction::Shift(2, { 1 }); + ParseAction reduce = ParseAction::Reduce(sym2, 1, 3); + + it("does not record a conflict", [&]() { + manager->resolve_parse_action(sym1, reduce, shift); + manager->resolve_parse_action(sym1, shift, reduce); + AssertThat(manager->conflicts(), IsEmpty()); + }); + + it("favors the reduce", [&]() { + AssertThat(manager->resolve_parse_action(sym1, reduce, shift), IsFalse()); + AssertThat(manager->resolve_parse_action(sym1, shift, reduce), IsTrue()); + }); + }); + + describe("when the precedences are equal", [&]() { + ParseAction shift = ParseAction::Shift(2, { 0 }); + ParseAction reduce = ParseAction::Reduce(sym2, 1, 0); - it("favors the shift", [&]() { - should_update = manager->resolve_parse_action(sym1, ParseAction::Reduce(sym2, 1), ParseAction::Shift(2)); - AssertThat(should_update, IsTrue()); - - should_update = manager->resolve_parse_action(sym1, ParseAction::Shift(2), ParseAction::Reduce(sym2, 1)); - AssertThat(should_update, IsFalse()); + it("records a conflict", [&]() { + manager->resolve_parse_action(sym1, reduce, shift); + manager->resolve_parse_action(sym1, shift, reduce); + AssertThat(manager->conflicts(), Equals(vector({ + Conflict("rule1: shift (precedence 0) / reduce rule2 (precedence 0)") + }))); + }); + + it("favors the shift", [&]() { + AssertThat(manager->resolve_parse_action(sym1, shift, reduce), IsFalse()); + AssertThat(manager->resolve_parse_action(sym1, reduce, shift), IsTrue()); + }); + }); + + describe("when the shift has conflicting precedences compared to the reduce", [&]() { + ParseAction shift = ParseAction::Shift(2, { 0, 1, 3 }); + ParseAction reduce = ParseAction::Reduce(sym2, 1, 2); + + it("records a conflict", [&]() { + manager->resolve_parse_action(sym1, reduce, shift); + manager->resolve_parse_action(sym1, shift, reduce); + AssertThat(manager->conflicts(), Equals(vector({ + Conflict("rule1: shift (precedence 0, 1, 3) / reduce rule2 (precedence 2)") + }))); + }); + + it("favors the shift", [&]() { + AssertThat(manager->resolve_parse_action(sym1, shift, reduce), IsFalse()); + AssertThat(manager->resolve_parse_action(sym1, reduce, shift), IsTrue()); + }); }); }); describe("reduce/reduce conflicts", [&]() { - it("records a conflict", [&]() { - manager->resolve_parse_action(sym1, ParseAction::Reduce(sym2, 1), ParseAction::Reduce(sym1, 1)); - manager->resolve_parse_action(sym1, ParseAction::Reduce(sym1, 1), ParseAction::Reduce(sym2, 1)); - - AssertThat(manager->conflicts(), Equals(vector({ - Conflict("rule1: reduce rule2 / reduce rule1"), - Conflict("rule1: reduce rule1 / reduce rule2") - }))); + describe("when one action has higher precedence", [&]() { + ParseAction left = ParseAction::Reduce(sym2, 1, 0); + ParseAction right = ParseAction::Reduce(sym2, 1, 3); + + it("favors that action", [&]() { + AssertThat(manager->resolve_parse_action(sym1, left, right), IsTrue()); + AssertThat(manager->resolve_parse_action(sym1, right, left), IsFalse()); + }); + + it("does not record a conflict", [&]() { + manager->resolve_parse_action(sym1, left, right); + manager->resolve_parse_action(sym1, right, left); + AssertThat(manager->conflicts(), IsEmpty()); + }); }); + + describe("when the actions have the same precedence", [&]() { + ParseAction left = ParseAction::Reduce(sym1, 1, 0); + ParseAction right = ParseAction::Reduce(sym2, 1, 0); + + it("favors the symbol listed earlier in the grammar", [&]() { + AssertThat(manager->resolve_parse_action(sym1, right, left), IsTrue()); + AssertThat(manager->resolve_parse_action(sym1, left, right), IsFalse()); + }); - it("favors the symbol listed earlier in the grammar", [&]() { - should_update = manager->resolve_parse_action(sym1, ParseAction::Reduce(sym2, 1), ParseAction::Reduce(sym1, 1)); - AssertThat(should_update, IsTrue()); - - should_update = manager->resolve_parse_action(sym1, ParseAction::Reduce(sym1, 1), ParseAction::Reduce(sym2, 1)); - AssertThat(should_update, IsFalse()); + it("records a conflict", [&]() { + manager->resolve_parse_action(sym1, left, right); + manager->resolve_parse_action(sym1, right, left); + AssertThat(manager->conflicts(), Equals(vector({ + Conflict("rule1: reduce rule2 (precedence 0) / reduce rule1 (precedence 0)"), + Conflict("rule1: reduce rule1 (precedence 0) / reduce rule2 (precedence 0)") + }))); + }); }); }); }); diff --git a/spec/compiler/build_tables/rule_transitions_spec.cc b/spec/compiler/build_tables/rule_transitions_spec.cc index 9e5e60f4..22c3834f 100644 --- a/spec/compiler/build_tables/rule_transitions_spec.cc +++ b/spec/compiler/build_tables/rule_transitions_spec.cc @@ -1,5 +1,6 @@ #include "compiler_spec_helper.h" #include "compiler/build_tables/rule_transitions.h" +#include "compiler/rules/metadata.h" using namespace rules; using namespace build_tables; @@ -182,6 +183,19 @@ describe("rule transitions", []() { { CharacterSet({ 'a' }), rule } }))); }); + + it("preserves metadata", [&]() { + map metadata_value({ + { PRECEDENCE, 5 } + }); + + rule_ptr rule = make_shared(seq({ sym("x"), sym("y") }), metadata_value); + AssertThat( + sym_transitions(rule), + Equals(rule_map({ + { Symbol("x"), make_shared(sym("y"), metadata_value)}, + }))); + }); describe("regression tests (somewhat redundant, should maybe be deleted later)", []() { it("handles sequences that start with repeating characters", [&]() { diff --git a/spec/runtime/languages/arithmetic/errors.txt b/spec/runtime/languages/arithmetic/errors.txt index adbd9cd1..37ec51fc 100644 --- a/spec/runtime/languages/arithmetic/errors.txt +++ b/spec/runtime/languages/arithmetic/errors.txt @@ -12,6 +12,4 @@ x + (y * + z) * 5 --- (expression (sum (variable) - (product - (grouping (ERROR)) - (number)))) \ No newline at end of file + (product (group (ERROR)) (number)))) \ No newline at end of file diff --git a/spec/runtime/languages/arithmetic/main.txt b/spec/runtime/languages/arithmetic/main.txt index 8f307048..86b67210 100644 --- a/spec/runtime/languages/arithmetic/main.txt +++ b/spec/runtime/languages/arithmetic/main.txt @@ -30,14 +30,14 @@ x + x (variable) (variable))) -==================== -parses complex trees -==================== -x * y + z / a +=============================================== +binds multiplication more tightly than addition +=============================================== +a * b + c * d --- (expression (sum (product (variable) (variable)) - (quotient (variable) (variable)))) + (product (variable) (variable)))) ============================ parses exponents @@ -50,4 +50,4 @@ x + y * z^(a + b) (variable) (exponent (variable) - (grouping (sum (variable) (variable))))))) + (group (sum (variable) (variable))))))) diff --git a/spec/runtime/node_position_spec.cc b/spec/runtime/node_position_spec.cc index 79208a1a..aa605c1f 100644 --- a/spec/runtime/node_position_spec.cc +++ b/spec/runtime/node_position_spec.cc @@ -18,8 +18,8 @@ describe("tracking the positions of AST nodes", []() { it("records the widths and offsets of nodes", [&]() { ts_document_set_input_string(doc, " [12, 5]"); - const ts_tree *tree = ts_document_tree(doc); + const ts_tree *tree = ts_document_tree(doc); const ts_tree *array = ts_tree_children(tree, NULL)[0]; const ts_tree *number1 = ts_tree_children(array, NULL)[0]; const ts_tree *number2 = ts_tree_children(array, NULL)[1]; diff --git a/src/compiler/build_tables/build_tables.cc b/src/compiler/build_tables/build_tables.cc index 6adaf274..bf867fa2 100644 --- a/src/compiler/build_tables/build_tables.cc +++ b/src/compiler/build_tables/build_tables.cc @@ -2,11 +2,13 @@ #include #include #include +#include #include #include "compiler/prepared_grammar.h" #include "compiler/rules/built_in_symbols.h" #include "compiler/rules/metadata.h" #include "compiler/rules/repeat.h" +#include "compiler/rules/blank.h" #include "compiler/rules/seq.h" #include "compiler/build_tables/conflict_manager.h" #include "compiler/build_tables/item.h" @@ -19,6 +21,7 @@ namespace tree_sitter { using std::string; using std::map; using std::vector; + using std::set; using std::unordered_map; using std::make_shared; using rules::Symbol; @@ -32,17 +35,27 @@ namespace tree_sitter { unordered_map parse_state_ids; unordered_map lex_state_ids; + set precedence_values_for_item_set(const ParseItemSet &item_set) { + set result; + for (const auto &item : item_set) + if (item.consumed_symbol_count > 0) + result.insert(item.precedence()); + return result; + } + void add_shift_actions(const ParseItemSet &item_set, ParseStateId state_id) { for (auto &transition : sym_transitions(item_set, grammar)) { const Symbol &symbol = transition.first; const ParseItemSet &item_set = transition.second; + set precedence_values = precedence_values_for_item_set(item_set); auto current_actions = parse_table.states[state_id].actions; auto current_action = current_actions.find(symbol); + if (current_action == current_actions.end() || - conflict_manager.resolve_parse_action(symbol, current_action->second, ParseAction::Shift(0))) { + conflict_manager.resolve_parse_action(symbol, current_action->second, ParseAction::Shift(0, precedence_values))) { ParseStateId new_state_id = add_parse_state(item_set); - parse_table.add_action(state_id, symbol, ParseAction::Shift(new_state_id)); + parse_table.add_action(state_id, symbol, ParseAction::Shift(new_state_id, precedence_values)); } } } @@ -59,7 +72,7 @@ namespace tree_sitter { void add_token_start(const LexItemSet &item_set, LexStateId state_id) { for (auto &item : item_set) - if (item.get_metadata(rules::START_TOKEN)) + if (item.is_token_start()) lex_table.state(state_id).is_token_start = true; } @@ -79,12 +92,14 @@ namespace tree_sitter { if (item.is_done()) { ParseAction action = (item.lhs == rules::START()) ? ParseAction::Accept() : - ParseAction::Reduce(item.lhs, item.consumed_symbol_count); + ParseAction::Reduce(item.lhs, item.consumed_symbol_count, item.precedence()); auto current_actions = parse_table.states[state_id].actions; auto current_action = current_actions.find(item.lookahead_sym); + if (current_action == current_actions.end() || - conflict_manager.resolve_parse_action(item.lookahead_sym, current_action->second, action)) + conflict_manager.resolve_parse_action(item.lookahead_sym, current_action->second, action)) { parse_table.add_action(state_id, item.lookahead_sym, action); + } } } } @@ -92,7 +107,10 @@ namespace tree_sitter { rules::rule_ptr after_separators(rules::rule_ptr rule) { return rules::Seq::Build({ make_shared(CharacterSet({ ' ', '\t', '\n', '\r' }).copy()), - make_shared(rule, map({ {rules::START_TOKEN, 1} })) + make_shared(make_shared(), map({ + {rules::START_TOKEN, 1}, + })), + rule }); } diff --git a/src/compiler/build_tables/conflict_manager.cc b/src/compiler/build_tables/conflict_manager.cc index 03d8bb29..7ffc3b1a 100644 --- a/src/compiler/build_tables/conflict_manager.cc +++ b/src/compiler/build_tables/conflict_manager.cc @@ -3,35 +3,16 @@ #include #include #include +#include "compiler/util/string_helpers.h" namespace tree_sitter { namespace build_tables { using rules::Symbol; - using std::vector; using std::string; + using std::to_string; using std::map; - - string message_for_action(const ParseAction &action, const map &rule_names) { - switch (action.type) { - case ParseActionTypeShift: - return "shift"; - case ParseActionTypeReduce: { - auto pair = rule_names.find(action.symbol); - if (pair != rule_names.end()) - return "reduce " + pair->second; - else - return "ERROR " + action.symbol.name; - } - case ParseActionTypeAccept: - return "accept"; - default: - return "error"; - } - } - - void ConflictManager::record_conflict(const rules::Symbol &symbol, const ParseAction &left, const ParseAction &right) { - conflicts_.insert(Conflict(rule_names.find(symbol)->second + ": " + message_for_action(left, rule_names) + " / " + message_for_action(right, rule_names))); - } + using std::set; + using std::vector; ConflictManager::ConflictManager(const PreparedGrammar &parse_grammar, const PreparedGrammar &lex_grammar, @@ -50,24 +31,42 @@ namespace tree_sitter { switch (old_action.type) { case ParseActionTypeError: return true; - case ParseActionTypeShift: + case ParseActionTypeShift: { + int min_precedence = *old_action.precedence_values.begin(); + int max_precedence = *old_action.precedence_values.rbegin(); switch (new_action.type) { - case ParseActionTypeShift: - record_conflict(symbol, old_action, new_action); - return false; - case ParseActionTypeReduce: - record_conflict(symbol, old_action, new_action); - return false; + case ParseActionTypeReduce: { + int new_precedence = *new_action.precedence_values.rbegin(); + if (max_precedence > new_precedence) { + if (min_precedence < new_precedence) + record_conflict(symbol, old_action, new_action); + return false; + } else if (max_precedence < new_precedence) { + return true; + } else { + record_conflict(symbol, old_action, new_action); + return false; + } + } default: return false; } + } case ParseActionTypeReduce: switch (new_action.type) { case ParseActionTypeReduce: { - record_conflict(symbol, old_action, new_action); - size_t old_index = parse_grammar.index_of(old_action.symbol); - size_t new_index = parse_grammar.index_of(new_action.symbol); - return new_index < old_index; + int old_precedence = *old_action.precedence_values.begin(); + int new_precedence = *new_action.precedence_values.begin(); + if (new_precedence > old_precedence) { + return true; + } else if (new_precedence < old_precedence) { + return false; + } else { + record_conflict(symbol, old_action, new_action); + size_t old_index = parse_grammar.index_of(old_action.symbol); + size_t new_index = parse_grammar.index_of(new_action.symbol); + return new_index < old_index; + } } default: return false; @@ -98,5 +97,42 @@ namespace tree_sitter { result.insert(result.end(), conflicts_.begin(), conflicts_.end()); return result; } + + string precedence_string(const ParseAction &action) { + string precedences = "(precedence "; + bool started = false; + for (auto value : action.precedence_values) { + if (started) precedences += ", "; + started = true; + precedences += to_string(value); + } + return precedences + ")"; + } + + string message_for_action(const ParseAction &action, const map &rule_names) { + switch (action.type) { + case ParseActionTypeShift: + return "shift " + precedence_string(action); + case ParseActionTypeReduce: { + auto pair = rule_names.find(action.symbol); + if (pair == rule_names.end()) + return "ERROR " + action.symbol.name; + else + return "reduce " + pair->second + " " + precedence_string(action); + } + case ParseActionTypeAccept: + return "accept"; + default: + return "error"; + } + } + + void ConflictManager::record_conflict(const rules::Symbol &symbol, + const ParseAction &left, + const ParseAction &right) { + conflicts_.insert(Conflict(rule_names.find(symbol)->second + ": " + + message_for_action(left, rule_names) + " / " + + message_for_action(right, rule_names))); + } } } \ No newline at end of file diff --git a/src/compiler/build_tables/get_metadata.cc b/src/compiler/build_tables/get_metadata.cc index 52d61553..6fa52983 100644 --- a/src/compiler/build_tables/get_metadata.cc +++ b/src/compiler/build_tables/get_metadata.cc @@ -10,8 +10,7 @@ namespace tree_sitter { class GetMetadata : public rules::RuleFn { rules::MetadataKey metadata_key; public: - GetMetadata(rules::MetadataKey key) : - metadata_key(key) {} + GetMetadata(rules::MetadataKey key) : metadata_key(key) {} int apply_to(const rules::Choice *rule) { return apply(rule->left) || apply(rule->right); diff --git a/src/compiler/build_tables/item.cc b/src/compiler/build_tables/item.cc index 0d57711b..5e50df96 100644 --- a/src/compiler/build_tables/item.cc +++ b/src/compiler/build_tables/item.cc @@ -20,10 +20,6 @@ namespace tree_sitter { return rule_can_be_blank(rule); } - int Item::get_metadata(rules::MetadataKey key) const { - return build_tables::get_metadata(rule, key); - } - ostream& operator<<(ostream &stream, const LexItem &item) { return stream << string("# @@ -92,7 +93,9 @@ namespace tree_sitter { } map apply_to(const rules::Metadata *rule) { - return this->apply(rule->rule); + return map_transitions(this->apply(rule->rule), [&](const rule_ptr &to_rule) { + return make_shared(to_rule, rule->value); + }); } map apply_to(const rules::String *rule) { diff --git a/src/compiler/generate_code/c_code.cc b/src/compiler/generate_code/c_code.cc index dc337f32..afbb7c0c 100644 --- a/src/compiler/generate_code/c_code.cc +++ b/src/compiler/generate_code/c_code.cc @@ -4,7 +4,7 @@ #include #include #include "compiler/generate_code/c_code.h" -#include "compiler/generate_code/helpers.h" +#include "compiler/util/string_helpers.h" #include "compiler/rules/built_in_symbols.h" namespace tree_sitter { @@ -14,6 +14,9 @@ namespace tree_sitter { using std::vector; using std::set; using std::pair; + using util::join; + using util::indent; + using util::character_code; namespace generate_code { string _switch(string condition, string body) { diff --git a/src/compiler/generate_code/helpers.cc b/src/compiler/generate_code/helpers.cc deleted file mode 100644 index ac6f7563..00000000 --- a/src/compiler/generate_code/helpers.cc +++ /dev/null @@ -1,49 +0,0 @@ -#include "compiler/generate_code/helpers.h" -#include "compiler/util/string_helpers.h" - -namespace tree_sitter { - using std::string; - using std::vector; - - namespace generate_code { - string join(vector lines, string separator) { - string result; - bool started = false; - for (auto line : lines) { - if (started) result += separator; - started = true; - result += line; - } - return result; - } - - string join(vector lines) { - return join(lines, "\n"); - } - - string indent(string input) { - string tab = " "; - util::str_replace(&input, "\n", "\n" + tab); - return tab + input; - } - - string character_code(char character) { - switch (character) { - case '\0': - return "\\0"; - case '"': - return "\\\""; - case '\n': - return "\\n"; - case '\r': - return "\\r"; - case '\t': - return "\\t"; - case '\\': - return "\\\\"; - default: - return string() + character; - } - } - } -} \ No newline at end of file diff --git a/src/compiler/generate_code/helpers.h b/src/compiler/generate_code/helpers.h deleted file mode 100644 index 7686a5fd..00000000 --- a/src/compiler/generate_code/helpers.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef COMPILER_GENERATE_CODE_HELPERS_H_ -#define COMPILER_GENERATE_CODE_HELPERS_H_ - -#include -#include - -namespace tree_sitter { - namespace generate_code { - std::string indent(std::string input); - std::string join(std::vector lines, std::string separator); - std::string join(std::vector lines); - std::string character_code(char character); - } -} - -#endif // COMPILER_GENERATE_CODE_HELPERS_H_ diff --git a/src/compiler/parse_table.cc b/src/compiler/parse_table.cc index 0c71f317..b5282261 100644 --- a/src/compiler/parse_table.cc +++ b/src/compiler/parse_table.cc @@ -12,11 +12,13 @@ namespace tree_sitter { ParseAction::ParseAction(ParseActionType type, size_t state_index, Symbol symbol, - size_t consumed_symbol_count) : + size_t consumed_symbol_count, + set precedence_values) : type(type), symbol(symbol), state_index(state_index), - consumed_symbol_count(consumed_symbol_count) {} + consumed_symbol_count(consumed_symbol_count), + precedence_values(precedence_values) {} ParseAction::ParseAction() : type(ParseActionTypeError), @@ -25,19 +27,19 @@ namespace tree_sitter { consumed_symbol_count(0) {} ParseAction ParseAction::Error() { - return ParseAction(ParseActionTypeError, -1, Symbol(""), {}); + return ParseAction(ParseActionTypeError, -1, Symbol(""), 0, { 0 }); } ParseAction ParseAction::Accept() { - return ParseAction(ParseActionTypeAccept, -1, Symbol(""), {}); + return ParseAction(ParseActionTypeAccept, -1, Symbol(""), 0, { 0 }); } - ParseAction ParseAction::Shift(size_t state_index) { - return ParseAction(ParseActionTypeShift, state_index, Symbol(""), {}); + ParseAction ParseAction::Shift(size_t state_index, set precedence_values) { + return ParseAction(ParseActionTypeShift, state_index, Symbol(""), 0, precedence_values); } - ParseAction ParseAction::Reduce(Symbol symbol, size_t consumed_symbol_count) { - return ParseAction(ParseActionTypeReduce, -1, symbol, consumed_symbol_count); + ParseAction ParseAction::Reduce(Symbol symbol, size_t consumed_symbol_count, int precedence) { + return ParseAction(ParseActionTypeReduce, -1, symbol, consumed_symbol_count, { precedence }); } bool ParseAction::operator==(const ParseAction &other) const { @@ -90,6 +92,6 @@ namespace tree_sitter { void ParseTable::add_action(ParseStateId id, Symbol symbol, ParseAction action) { symbols.insert(symbol); - states[id].actions.insert({ symbol, action }); + states[id].actions[symbol] = action; } } diff --git a/src/compiler/parse_table.h b/src/compiler/parse_table.h index bd7073f4..409594ec 100644 --- a/src/compiler/parse_table.h +++ b/src/compiler/parse_table.h @@ -20,19 +20,21 @@ namespace tree_sitter { ParseAction(ParseActionType type, size_t state_index, rules::Symbol symbol, - size_t consumed_symbol_count); + size_t consumed_symbol_count, + std::set precedence_values); public: ParseAction(); static ParseAction Accept(); static ParseAction Error(); - static ParseAction Shift(size_t state_index); - static ParseAction Reduce(rules::Symbol symbol, size_t consumed_symbol_count); + static ParseAction Shift(size_t state_index, std::set precedence_values); + static ParseAction Reduce(rules::Symbol symbol, size_t consumed_symbol_count, int precedence); bool operator==(const ParseAction &action) const; ParseActionType type; rules::Symbol symbol; size_t state_index; size_t consumed_symbol_count; + std::set precedence_values; }; std::ostream& operator<<(std::ostream &stream, const ParseAction &item); diff --git a/src/compiler/rules/rules.cc b/src/compiler/rules/rules.cc index 842b7d57..b04ea6f6 100644 --- a/src/compiler/rules/rules.cc +++ b/src/compiler/rules/rules.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include "tree_sitter/compiler.h" @@ -8,6 +9,7 @@ #include "compiler/rules/choice.h" #include "compiler/rules/seq.h" #include "compiler/rules/string.h" +#include "compiler/rules/metadata.h" #include "compiler/rules/pattern.h" #include "compiler/rules/character_set.h" #include "compiler/rules/repeat.h" @@ -18,6 +20,7 @@ namespace tree_sitter { using std::string; using std::set; using std::vector; + using std::map; namespace rules { rule_ptr blank() { @@ -51,5 +54,11 @@ namespace tree_sitter { rule_ptr err(const rule_ptr &rule) { return choice({ rule, ERROR().copy() }); } + + rule_ptr prec(int precedence, rule_ptr rule) { + return std::make_shared(rule, map({ + { PRECEDENCE, precedence } + })); + } } } diff --git a/src/compiler/util/string_helpers.cc b/src/compiler/util/string_helpers.cc index b7bc0d36..c54c75dd 100644 --- a/src/compiler/util/string_helpers.cc +++ b/src/compiler/util/string_helpers.cc @@ -1,7 +1,10 @@ #include "compiler/util/string_helpers.h" +#include namespace tree_sitter { using std::string; + using std::vector; + using std::set; namespace util { void str_replace(string *input, const string &search, const string &replace) { @@ -20,5 +23,45 @@ namespace tree_sitter { str_replace(&input, "\n", "\\n"); return input; } + + string join(vector lines, string separator) { + string result; + bool started = false; + for (auto line : lines) { + if (started) result += separator; + started = true; + result += line; + } + return result; + } + + string join(vector lines) { + return join(lines, "\n"); + } + + string indent(string input) { + string tab = " "; + util::str_replace(&input, "\n", "\n" + tab); + return tab + input; + } + + string character_code(char character) { + switch (character) { + case '\0': + return "\\0"; + case '"': + return "\\\""; + case '\n': + return "\\n"; + case '\r': + return "\\r"; + case '\t': + return "\\t"; + case '\\': + return "\\\\"; + default: + return string() + character; + } + } } } \ No newline at end of file diff --git a/src/compiler/util/string_helpers.h b/src/compiler/util/string_helpers.h index cd4e2308..bd7cc6e4 100644 --- a/src/compiler/util/string_helpers.h +++ b/src/compiler/util/string_helpers.h @@ -2,11 +2,17 @@ #define COMPILER_UTIL_STRING_HELPERS_H_ #include +#include +#include namespace tree_sitter { namespace util { void str_replace(std::string *input, const std::string &search, const std::string &replace); std::string escape_string(std::string input); + std::string indent(std::string input); + std::string join(std::vector lines, std::string separator); + std::string join(std::vector lines); + std::string character_code(char character); } }