Compress the tables in c++ backend, fixes #2

This commit is contained in:
Robin Jadoul 2016-05-26 17:13:20 +02:00
parent 1e460a94bd
commit a4dbf3d195
2 changed files with 28 additions and 6 deletions

View File

@ -117,12 +117,33 @@ namespace lxs { namespace backends {
return templ::make_array(tokenList);
}
std::pair<std::vector<unsigned char>, int> CppBackend::buildTransitionIndices(const DFA& /* dfa */) const {
//FIXME: this is not really optimal ;-)
std::vector<unsigned char> transition_idx;
for (int i = 0; i < 256; i++)
transition_idx.push_back(i);
return std::make_pair(transition_idx, 256);
std::pair<std::vector<unsigned char>, int> CppBackend::buildTransitionIndices(const DFA& dfa) const {
std::vector<unsigned char> transition_idx(256);
int count = 0;
for (int i = 0; i < 256; i++) {
int found = i;
for (int j = 0; j < i; j++) {
bool differ = false;
for (State s = 0; s < dfa.numStates; s++) {
if (dfa.delta.find(s)->second.find(i)->second != dfa.delta.find(s)->second.find(j)->second) {
differ = true;
break;
}
}
if (!differ) {
found = j;
break;
}
}
if (found != i)
{
transition_idx[i] = transition_idx[found];
} else {
transition_idx[i] = count++;
}
}
return std::make_pair(transition_idx, count);
}
templ::TemplateContext CppBackend::transformTransitionIndices(const std::vector<unsigned char>& transition_indices) const {

View File

@ -30,6 +30,7 @@ int main(int argc, char** argv) {
}
std::string lexername = options["lexername"];
//FIXME: this really needs some more work...
if (!lexername.length()) {
if (args[0].length() >= 4 && args[0].substr(args[0].length() - 4, 4) == ".lxs") {
lexername = args[0].substr(0, args[0].length() - 4); //Drop the .lxs