grammars: update reps parsing to bring ? / * / + closer to before
This commit is contained in:
parent
1fb778750f
commit
15585e0f20
2 changed files with 106 additions and 249 deletions
|
@ -161,76 +161,48 @@ namespace grammar_parser {
|
|||
|
||||
// apply transformation to previous symbol (last_sym_start to end) according to
|
||||
// the following rewrite rules:
|
||||
// S{m,n} --> S S S (m times) S'(n-m)
|
||||
// S'(x) ::= S S'(x-1) |
|
||||
// S'(1) ::= S |
|
||||
// S{m,} --> S S S (m times) S'
|
||||
// S' ::= S S' |
|
||||
// S* --> S{0,}
|
||||
// --> S' ::= S S' |
|
||||
// S+ --> S{1,}
|
||||
// --> S S'
|
||||
// S' ::= S S' |
|
||||
// S? --> S{0,1}
|
||||
// S{m,n} --> S' ::= Scopy Scopy Scopy... (m times) S(n-m)
|
||||
// Scopy ::= S
|
||||
// S(x) ::= Scopy S(x-1) |
|
||||
// S(x-1) ::= Scopy S(x-2) |
|
||||
// S(1) ::= Scopy |
|
||||
// S{m,} --> S' ::= Scopy Scopy Scopy (m times) Sstar
|
||||
// Scopy ::= S
|
||||
// Sstar ::= Scopy Sstar |
|
||||
// And if S is a reference to a rule, then we skip the S_copy indirection
|
||||
// --> S'
|
||||
// S' ::= S |
|
||||
|
||||
uint32_t content_rule_id = 0;
|
||||
if (last_sym_start == out_elements.size() - 1 && out_elements[last_sym_start].type == LLAMA_GRETYPE_RULE_REF) {
|
||||
// The repeated content is already a rule ref, no need to copy it
|
||||
content_rule_id = out_elements[last_sym_start].value;
|
||||
std::vector<llama_grammar_element> previous_elements(out_elements.begin() + last_sym_start, out_elements.end());
|
||||
if (min_times == 0) {
|
||||
out_elements.resize(last_sym_start);
|
||||
} else {
|
||||
content_rule_id = generate_symbol_id(state, rule_name + "_copy");
|
||||
// add preceding symbol to generated copy rule
|
||||
std::vector<llama_grammar_element> copy_rule(out_elements.begin() + last_sym_start, out_elements.end());
|
||||
copy_rule.push_back({LLAMA_GRETYPE_END, 0});
|
||||
add_rule(state, content_rule_id, copy_rule);
|
||||
}
|
||||
|
||||
uint32_t sub_rule_id = generate_symbol_id(state, rule_name);
|
||||
std::vector<llama_grammar_element> sub_rule;
|
||||
for (int i = 0; i < min_times; i++) {
|
||||
sub_rule.push_back({LLAMA_GRETYPE_RULE_REF, content_rule_id});
|
||||
}
|
||||
if (max_times < 0) {
|
||||
uint32_t star_rule_id = generate_symbol_id(state, rule_name + "_star");
|
||||
add_rule(state, star_rule_id, {
|
||||
{LLAMA_GRETYPE_RULE_REF, content_rule_id},
|
||||
{LLAMA_GRETYPE_RULE_REF, star_rule_id},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0}
|
||||
});
|
||||
sub_rule.push_back({LLAMA_GRETYPE_RULE_REF, star_rule_id});
|
||||
} else {
|
||||
uint32_t last_rec_rule_id = 0;
|
||||
auto n_opt = max_times - min_times;
|
||||
for (int i = 0; i < n_opt; i++) {
|
||||
uint32_t rec_rule_id = generate_symbol_id(state, rule_name + "_" + std::to_string(i + 1));
|
||||
if (i == 0) {
|
||||
add_rule(state, rec_rule_id, {
|
||||
{LLAMA_GRETYPE_RULE_REF, content_rule_id},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0}
|
||||
});
|
||||
} else {
|
||||
add_rule(state, rec_rule_id, {
|
||||
{LLAMA_GRETYPE_RULE_REF, content_rule_id},
|
||||
{LLAMA_GRETYPE_RULE_REF, last_rec_rule_id},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0}
|
||||
});
|
||||
}
|
||||
last_rec_rule_id = rec_rule_id;
|
||||
}
|
||||
if (n_opt > 0) {
|
||||
sub_rule.push_back({LLAMA_GRETYPE_RULE_REF, last_rec_rule_id});
|
||||
// Repeat the previous elements (min_times - 1) times
|
||||
for (int i = 1; i < min_times; i++) {
|
||||
out_elements.insert(out_elements.end(), previous_elements.begin(), previous_elements.end());
|
||||
}
|
||||
}
|
||||
sub_rule.push_back({LLAMA_GRETYPE_END, 0});
|
||||
add_rule(state, sub_rule_id, sub_rule);
|
||||
|
||||
// in original rule, replace previous symbol with reference to generated rule
|
||||
out_elements.resize(last_sym_start);
|
||||
out_elements.push_back({LLAMA_GRETYPE_RULE_REF, sub_rule_id});
|
||||
uint32_t last_rec_rule_id = 0;
|
||||
auto n_opt = max_times < 0 ? 1 : max_times - min_times;
|
||||
|
||||
std::vector<llama_grammar_element> rec_rule(previous_elements);
|
||||
for (int i = 0; i < n_opt; i++) {
|
||||
rec_rule.resize(previous_elements.size());
|
||||
uint32_t rec_rule_id = generate_symbol_id(state, rule_name);
|
||||
if (i > 0 || max_times < 0) {
|
||||
rec_rule.push_back({LLAMA_GRETYPE_RULE_REF, max_times < 0 ? rec_rule_id : last_rec_rule_id});
|
||||
}
|
||||
rec_rule.push_back({LLAMA_GRETYPE_ALT, 0});
|
||||
rec_rule.push_back({LLAMA_GRETYPE_END, 0});
|
||||
add_rule(state, rec_rule_id, rec_rule);
|
||||
last_rec_rule_id = rec_rule_id;
|
||||
}
|
||||
if (n_opt > 0) {
|
||||
out_elements.push_back({LLAMA_GRETYPE_RULE_REF, last_rec_rule_id});
|
||||
}
|
||||
};
|
||||
|
||||
while (*pos) {
|
||||
|
|
|
@ -180,9 +180,9 @@ int main()
|
|||
{"a", 1},
|
||||
{"root", 0},
|
||||
{"root_2", 2},
|
||||
{"root_star_3", 3},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* a */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// a (index 1)
|
||||
|
@ -190,11 +190,7 @@ int main()
|
|||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* a */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_3 */ 3},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_star_3 (index 3)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* a */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_3 */ 3},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
@ -203,23 +199,15 @@ int main()
|
|||
root ::= "a"+
|
||||
)""", {
|
||||
{"root", 0},
|
||||
{"root_2", 2},
|
||||
{"root_copy_1", 1},
|
||||
{"root_star_3", 3},
|
||||
{"root_1", 1},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_copy_1 (index 1)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_3 */ 3},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_star_3 (index 3)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_3 */ 3},
|
||||
// root_1 (index 1)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
@ -230,7 +218,6 @@ int main()
|
|||
)""", {
|
||||
{"a", 1},
|
||||
{"root", 0},
|
||||
{"root_1_3", 3},
|
||||
{"root_2", 2},
|
||||
}, {
|
||||
// root (index 0)
|
||||
|
@ -240,9 +227,6 @@ int main()
|
|||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1_3 */ 3},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_1_3 (index 3)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* a */ 1},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
|
@ -252,21 +236,13 @@ int main()
|
|||
root ::= "a"?
|
||||
)""", {
|
||||
{"root", 0},
|
||||
{"root_1_3", 3},
|
||||
{"root_2", 2},
|
||||
{"root_copy_1", 1},
|
||||
{"root_1", 1},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_copy_1 (index 1)
|
||||
// root_1 (index 1)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1_3 */ 3},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_1_3 (index 3)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
@ -278,7 +254,6 @@ int main()
|
|||
{"a", 1},
|
||||
{"root", 0},
|
||||
{"root_2", 2},
|
||||
{"root_star_3", 3},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
|
@ -287,11 +262,8 @@ int main()
|
|||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_3 */ 3},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_star_3 (index 3)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* a */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_3 */ 3},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
@ -300,22 +272,14 @@ int main()
|
|||
root ::= "a"*
|
||||
)""", {
|
||||
{"root", 0},
|
||||
{"root_2", 2},
|
||||
{"root_copy_1", 1},
|
||||
{"root_star_3", 3},
|
||||
{"root_1", 1},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_copy_1 (index 1)
|
||||
// root_1 (index 1)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_3 */ 3},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_star_3 (index 3)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_3 */ 3},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
@ -324,18 +288,10 @@ int main()
|
|||
root ::= "a"{2}
|
||||
)""", {
|
||||
{"root", 0},
|
||||
{"root_2", 2},
|
||||
{"root_copy_1", 1},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_copy_1 (index 1)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
||||
|
@ -343,24 +299,16 @@ int main()
|
|||
root ::= "a"{2,}
|
||||
)""", {
|
||||
{"root", 0},
|
||||
{"root_2", 2},
|
||||
{"root_copy_1", 1},
|
||||
{"root_star_3", 3},
|
||||
{"root_1", 1},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_copy_1 (index 1)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_3 */ 3},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_star_3 (index 3)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_3 */ 3},
|
||||
// root_1 (index 1)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
@ -369,20 +317,12 @@ int main()
|
|||
root ::= "a"{ 4}
|
||||
)""", {
|
||||
{"root", 0},
|
||||
{"root_2", 2},
|
||||
{"root_copy_1", 1},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_copy_1 (index 1)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
||||
|
@ -390,29 +330,21 @@ int main()
|
|||
root ::= "a"{2,4}
|
||||
)""", {
|
||||
{"root", 0},
|
||||
{"root_1_3", 3},
|
||||
{"root_1", 1},
|
||||
{"root_2", 2},
|
||||
{"root_2_4", 4},
|
||||
{"root_copy_1", 1},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2 */ 2},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_copy_1 (index 1)
|
||||
// root_1 (index 1)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_2_4 */ 4},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_1_3 (index 3)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_2_4 (index 4)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_copy_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1_3 */ 3},
|
||||
// root_2 (index 2)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
@ -423,19 +355,16 @@ int main()
|
|||
term ::= [0-9]+
|
||||
)""", {
|
||||
{"expr", 2},
|
||||
{"expr_5", 5},
|
||||
{"expr_6", 6},
|
||||
{"expr_7", 7},
|
||||
{"expr_star_8", 8},
|
||||
{"root", 0},
|
||||
{"root_1", 1},
|
||||
{"root_4", 4},
|
||||
{"root_star_5", 5},
|
||||
{"term", 3},
|
||||
{"term_10", 10},
|
||||
{"term_copy_9", 9},
|
||||
{"term_star_11", 11},
|
||||
{"term_7", 7},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_4 */ 4},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_1 (index 1)
|
||||
|
@ -446,46 +375,34 @@ int main()
|
|||
{LLAMA_GRETYPE_END, 0},
|
||||
// expr (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term */ 3},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_7 */ 7},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_6 */ 6},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// term (index 3)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term_10 */ 10},
|
||||
{LLAMA_GRETYPE_CHAR, '0'},
|
||||
{LLAMA_GRETYPE_CHAR_RNG_UPPER, '9'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term_7 */ 7},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_4 (index 4)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_5 */ 5},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_star_5 (index 5)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_5 */ 5},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_4 */ 4},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// expr_6 (index 6)
|
||||
// expr_5 (index 5)
|
||||
{LLAMA_GRETYPE_CHAR, '-'},
|
||||
{LLAMA_GRETYPE_CHAR_ALT, '+'},
|
||||
{LLAMA_GRETYPE_CHAR_ALT, '*'},
|
||||
{LLAMA_GRETYPE_CHAR_ALT, '/'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term */ 3},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// expr_7 (index 7)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_star_8 */ 8},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// expr_star_8 (index 8)
|
||||
// expr_6 (index 6)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_5 */ 5},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_6 */ 6},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_star_8 */ 8},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// term_copy_9 (index 9)
|
||||
// term_7 (index 7)
|
||||
{LLAMA_GRETYPE_CHAR, '0'},
|
||||
{LLAMA_GRETYPE_CHAR_RNG_UPPER, '9'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// term_10 (index 10)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term_copy_9 */ 9},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term_star_11 */ 11},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// term_star_11 (index 11)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term_copy_9 */ 9},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term_star_11 */ 11},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term_7 */ 7},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
@ -499,28 +416,21 @@ int main()
|
|||
ws ::= [ \t\n]*
|
||||
)""", {
|
||||
{"expr", 2},
|
||||
{"expr_6", 6},
|
||||
{"expr_7", 7},
|
||||
{"expr_8", 8},
|
||||
{"expr_star_9", 9},
|
||||
{"ident", 10},
|
||||
{"ident_13", 13},
|
||||
{"ident_copy_12", 12},
|
||||
{"ident_star_14", 14},
|
||||
{"num", 11},
|
||||
{"num_16", 16},
|
||||
{"num_copy_15", 15},
|
||||
{"num_star_17", 17},
|
||||
{"ident", 8},
|
||||
{"ident_10", 10},
|
||||
{"num", 9},
|
||||
{"num_11", 11},
|
||||
{"root", 0},
|
||||
{"root_1", 1},
|
||||
{"root_5", 5},
|
||||
{"root_star_6", 6},
|
||||
{"term", 4},
|
||||
{"ws", 3},
|
||||
{"ws_19", 19},
|
||||
{"ws_copy_18", 18},
|
||||
{"ws_star_20", 20},
|
||||
{"ws_12", 12},
|
||||
}, {
|
||||
// root (index 0)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_5 */ 5},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_1 (index 1)
|
||||
|
@ -532,15 +442,15 @@ int main()
|
|||
{LLAMA_GRETYPE_END, 0},
|
||||
// expr (index 2)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term */ 4},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_8 */ 8},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_7 */ 7},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// ws (index 3)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ws_19 */ 19},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ws_12 */ 12},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// term (index 4)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ident */ 10},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ident */ 8},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* num */ 11},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* num */ 9},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_CHAR, '('},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ws */ 3},
|
||||
|
@ -550,81 +460,56 @@ int main()
|
|||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_5 (index 5)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_6 */ 6},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// root_star_6 (index 6)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_1 */ 1},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_star_6 */ 6},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* root_5 */ 5},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// expr_7 (index 7)
|
||||
// expr_6 (index 6)
|
||||
{LLAMA_GRETYPE_CHAR, '-'},
|
||||
{LLAMA_GRETYPE_CHAR_ALT, '+'},
|
||||
{LLAMA_GRETYPE_CHAR_ALT, '*'},
|
||||
{LLAMA_GRETYPE_CHAR_ALT, '/'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* term */ 4},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// expr_8 (index 8)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_star_9 */ 9},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// expr_star_9 (index 9)
|
||||
// expr_7 (index 7)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_6 */ 6},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_7 */ 7},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* expr_star_9 */ 9},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// ident (index 10)
|
||||
// ident (index 8)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_CHAR_RNG_UPPER, 'z'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ident_13 */ 13},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ident_10 */ 10},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ws */ 3},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// num (index 11)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* num_16 */ 16},
|
||||
// num (index 9)
|
||||
{LLAMA_GRETYPE_CHAR, '0'},
|
||||
{LLAMA_GRETYPE_CHAR_RNG_UPPER, '9'},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* num_11 */ 11},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ws */ 3},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// ident_copy_12 (index 12)
|
||||
// ident_10 (index 10)
|
||||
{LLAMA_GRETYPE_CHAR, 'a'},
|
||||
{LLAMA_GRETYPE_CHAR_RNG_UPPER, 'z'},
|
||||
{LLAMA_GRETYPE_CHAR_ALT, '0'},
|
||||
{LLAMA_GRETYPE_CHAR_RNG_UPPER, '9'},
|
||||
{LLAMA_GRETYPE_CHAR_ALT, '_'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// ident_13 (index 13)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ident_star_14 */ 14},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// ident_star_14 (index 14)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ident_copy_12 */ 12},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ident_star_14 */ 14},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ident_10 */ 10},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// num_copy_15 (index 15)
|
||||
// num_11 (index 11)
|
||||
{LLAMA_GRETYPE_CHAR, '0'},
|
||||
{LLAMA_GRETYPE_CHAR_RNG_UPPER, '9'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// num_16 (index 16)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* num_copy_15 */ 15},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* num_star_17 */ 17},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// num_star_17 (index 17)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* num_copy_15 */ 15},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* num_star_17 */ 17},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* num_11 */ 11},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// ws_copy_18 (index 18)
|
||||
// ws_12 (index 12)
|
||||
{LLAMA_GRETYPE_CHAR, ' '},
|
||||
{LLAMA_GRETYPE_CHAR_ALT, '\t'},
|
||||
{LLAMA_GRETYPE_CHAR_ALT, '\n'},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// ws_19 (index 19)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ws_star_20 */ 20},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
// ws_star_20 (index 20)
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ws_copy_18 */ 18},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ws_star_20 */ 20},
|
||||
{LLAMA_GRETYPE_RULE_REF, /* ws_12 */ 12},
|
||||
{LLAMA_GRETYPE_ALT, 0},
|
||||
{LLAMA_GRETYPE_END, 0},
|
||||
});
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue