fix compile errors
This commit is contained in:
parent
b2a1883369
commit
aaeb6438a1
27 changed files with 19 additions and 21 deletions
|
|
@ -96,20 +96,20 @@ namespace tp {
|
||||||
Map<const AutomataState*, ualni> states;
|
Map<const AutomataState*, ualni> states;
|
||||||
ualni stateIndex = 0;
|
ualni stateIndex = 0;
|
||||||
for (auto state : *automata.getStates()) {
|
for (auto state : *automata.getStates()) {
|
||||||
states.put(state.data(), { stateIndex });
|
states.put(&state.data(), { stateIndex });
|
||||||
stateIndex++;
|
stateIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
stateIndex = 0;
|
stateIndex = 0;
|
||||||
for (auto state : *automata.getStates()) {
|
for (auto state : *automata.getStates()) {
|
||||||
if (state.data() == automata.getStartState()) {
|
if (&state.data() == automata.getStartState()) {
|
||||||
mStartState = stateIndex;
|
mStartState = stateIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state->isAccepting()) {
|
if (state->isAccepting()) {
|
||||||
ASSERT(state->getTransitions().size() == 0)
|
ASSERT(state->getTransitions()->size() == 0)
|
||||||
for (auto symbolIndex : Range<ualni>(numSymbols)) {
|
for (auto symbolIndex : Range<ualni>(numSymbols)) {
|
||||||
mTable.set({ stateIndex, symbolIndex }, { Action::REDUCE, state->getStateVal() });
|
mTable.set({ stateIndex, symbolIndex }, { Action::REDUCE, state->getStateVal().numArgs() });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto transition : *state->getTransitions()) {
|
for (auto transition : *state->getTransitions()) {
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,19 @@
|
||||||
namespace tp {
|
namespace tp {
|
||||||
|
|
||||||
class ContextFreeCompiler {
|
class ContextFreeCompiler {
|
||||||
|
public:
|
||||||
typedef ualni SymbolID;
|
typedef ualni SymbolID;
|
||||||
|
|
||||||
struct Symbol {
|
|
||||||
String mId;
|
|
||||||
bool mIsTerminal = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Item {
|
struct Item {
|
||||||
const ContextFreeGrammar::Rule* mRule = nullptr;
|
const ContextFreeGrammar::Rule* mRule = nullptr;
|
||||||
ualni mAdvanceIdx = 0;
|
ualni mAdvanceIdx = 0;
|
||||||
|
ualni numArgs() const { return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Symbol {
|
||||||
|
String mId;
|
||||||
|
bool mIsTerminal = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NonTerminal {
|
struct NonTerminal {
|
||||||
|
|
@ -90,7 +92,7 @@ namespace tp {
|
||||||
|
|
||||||
for (auto nonTerminal : mNonTerminals) {
|
for (auto nonTerminal : mNonTerminals) {
|
||||||
if (!nonTerminal->val.isProductive()) {
|
if (!nonTerminal->val.isProductive()) {
|
||||||
printf("Non-terminal '%s' is not productive\n", nonTerminal->val.rules.first()->data->id.read());
|
printf("Non-terminal '%s' is not productive\n", nonTerminal->val.rules.first()->getId().read());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -102,6 +104,8 @@ namespace tp {
|
||||||
}
|
}
|
||||||
|
|
||||||
initSymbols(grammar);
|
initSymbols(grammar);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void findNonTerminals(const ContextFreeGrammar& grammar) {
|
void findNonTerminals(const ContextFreeGrammar& grammar) {
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ namespace tp {
|
||||||
void addRule(const String& id, const InitialierList<Arg>& args);
|
void addRule(const String& id, const InitialierList<Arg>& args);
|
||||||
void setStart(const String& startRule);
|
void setStart(const String& startRule);
|
||||||
[[nodiscard]] const Buffer<Rule>* getRules() const { return &mRules; }
|
[[nodiscard]] const Buffer<Rule>* getRules() const { return &mRules; }
|
||||||
[[nodiscard]] bool isValid() const { return false; }
|
|
||||||
[[nodiscard]] const String& getStartTerminal() const { return mStartTerminal; }
|
[[nodiscard]] const String& getStartTerminal() const { return mStartTerminal; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace tp {
|
||||||
typedef RegularGrammar<tAlphabetType, TokenType> RegularGrammar;
|
typedef RegularGrammar<tAlphabetType, TokenType> RegularGrammar;
|
||||||
typedef RegularCompiler<tAlphabetType, TokenType, MinSymbol, MaxSymbol> RegularCompiler;
|
typedef RegularCompiler<tAlphabetType, TokenType, MinSymbol, MaxSymbol> RegularCompiler;
|
||||||
typedef FiniteStateAutomation<tAlphabetType, TokenType> RegularGraph;
|
typedef FiniteStateAutomation<tAlphabetType, TokenType> RegularGraph;
|
||||||
typedef RegularAutomata<tAlphabetType, TokenType, TokenType::InTransition, TokenType::Failed> RegularAutomata;
|
typedef RegularAutomata<tAlphabetType, TokenType> RegularAutomata;
|
||||||
|
|
||||||
// ContextFreeGrammar;
|
// ContextFreeGrammar;
|
||||||
// ContextFreeCompiler;
|
// ContextFreeCompiler;
|
||||||
|
|
@ -31,10 +31,6 @@ namespace tp {
|
||||||
bool compileTables(const ContextFreeGrammar& cfGrammar, const RegularGrammar& reGrammar) {
|
bool compileTables(const ContextFreeGrammar& cfGrammar, const RegularGrammar& reGrammar) {
|
||||||
// Compile Regular Grammar
|
// Compile Regular Grammar
|
||||||
{
|
{
|
||||||
if (!reGrammar.isValid()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
RegularGraph graph;
|
RegularGraph graph;
|
||||||
RegularCompiler compiler;
|
RegularCompiler compiler;
|
||||||
compiler.compile(graph, reGrammar);
|
compiler.compile(graph, reGrammar);
|
||||||
|
|
@ -44,10 +40,6 @@ namespace tp {
|
||||||
|
|
||||||
// compile context free grammar
|
// compile context free grammar
|
||||||
{
|
{
|
||||||
if (!cfGrammar.isValid()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ContextFreeGraph graph;
|
ContextFreeGraph graph;
|
||||||
ContextFreeCompiler compiler;
|
ContextFreeCompiler compiler;
|
||||||
compiler.compile(cfGrammar, graph);
|
compiler.compile(cfGrammar, graph);
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ namespace tp {
|
||||||
return v + 1;
|
return v + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ualni hash(const void* bytes) { return hash((const char*) bytes); }
|
||||||
|
|
||||||
ualni hash(const char* bytes) {
|
ualni hash(const char* bytes) {
|
||||||
unsigned long hash = 5381;
|
unsigned long hash = 5381;
|
||||||
int c;
|
int c;
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ namespace tp {
|
||||||
uhalni next2pow(uhalni v);
|
uhalni next2pow(uhalni v);
|
||||||
ufalni next2pow(ufalni v);
|
ufalni next2pow(ufalni v);
|
||||||
|
|
||||||
|
ualni hash(const void* bytes);
|
||||||
ualni hash(const char* bytes);
|
ualni hash(const char* bytes);
|
||||||
ualni hash(alni bytes);
|
ualni hash(alni bytes);
|
||||||
ualni hash(halni bytes);
|
ualni hash(halni bytes);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue