fix compile errors
This commit is contained in:
parent
1d9ef2aa6c
commit
63b0560375
27 changed files with 19 additions and 21 deletions
|
|
@ -96,20 +96,20 @@ namespace tp {
|
|||
Map<const AutomataState*, ualni> states;
|
||||
ualni stateIndex = 0;
|
||||
for (auto state : *automata.getStates()) {
|
||||
states.put(state.data(), { stateIndex });
|
||||
states.put(&state.data(), { stateIndex });
|
||||
stateIndex++;
|
||||
}
|
||||
|
||||
stateIndex = 0;
|
||||
for (auto state : *automata.getStates()) {
|
||||
if (state.data() == automata.getStartState()) {
|
||||
if (&state.data() == automata.getStartState()) {
|
||||
mStartState = stateIndex;
|
||||
}
|
||||
|
||||
if (state->isAccepting()) {
|
||||
ASSERT(state->getTransitions().size() == 0)
|
||||
ASSERT(state->getTransitions()->size() == 0)
|
||||
for (auto symbolIndex : Range<ualni>(numSymbols)) {
|
||||
mTable.set({ stateIndex, symbolIndex }, { Action::REDUCE, state->getStateVal() });
|
||||
mTable.set({ stateIndex, symbolIndex }, { Action::REDUCE, state->getStateVal().numArgs() });
|
||||
}
|
||||
} else {
|
||||
for (auto transition : *state->getTransitions()) {
|
||||
|
|
|
|||
|
|
@ -7,17 +7,19 @@
|
|||
namespace tp {
|
||||
|
||||
class ContextFreeCompiler {
|
||||
|
||||
public:
|
||||
typedef ualni SymbolID;
|
||||
|
||||
struct Symbol {
|
||||
String mId;
|
||||
bool mIsTerminal = false;
|
||||
};
|
||||
|
||||
struct Item {
|
||||
const ContextFreeGrammar::Rule* mRule = nullptr;
|
||||
ualni mAdvanceIdx = 0;
|
||||
ualni numArgs() const { return 0; }
|
||||
};
|
||||
|
||||
private:
|
||||
struct Symbol {
|
||||
String mId;
|
||||
bool mIsTerminal = false;
|
||||
};
|
||||
|
||||
struct NonTerminal {
|
||||
|
|
@ -90,7 +92,7 @@ namespace tp {
|
|||
|
||||
for (auto nonTerminal : mNonTerminals) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -102,6 +104,8 @@ namespace tp {
|
|||
}
|
||||
|
||||
initSymbols(grammar);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void findNonTerminals(const ContextFreeGrammar& grammar) {
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ namespace tp {
|
|||
void addRule(const String& id, const InitialierList<Arg>& args);
|
||||
void setStart(const String& startRule);
|
||||
[[nodiscard]] const Buffer<Rule>* getRules() const { return &mRules; }
|
||||
[[nodiscard]] bool isValid() const { return false; }
|
||||
[[nodiscard]] const String& getStartTerminal() const { return mStartTerminal; }
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace tp {
|
|||
typedef RegularGrammar<tAlphabetType, TokenType> RegularGrammar;
|
||||
typedef RegularCompiler<tAlphabetType, TokenType, MinSymbol, MaxSymbol> RegularCompiler;
|
||||
typedef FiniteStateAutomation<tAlphabetType, TokenType> RegularGraph;
|
||||
typedef RegularAutomata<tAlphabetType, TokenType, TokenType::InTransition, TokenType::Failed> RegularAutomata;
|
||||
typedef RegularAutomata<tAlphabetType, TokenType> RegularAutomata;
|
||||
|
||||
// ContextFreeGrammar;
|
||||
// ContextFreeCompiler;
|
||||
|
|
@ -31,10 +31,6 @@ namespace tp {
|
|||
bool compileTables(const ContextFreeGrammar& cfGrammar, const RegularGrammar& reGrammar) {
|
||||
// Compile Regular Grammar
|
||||
{
|
||||
if (!reGrammar.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RegularGraph graph;
|
||||
RegularCompiler compiler;
|
||||
compiler.compile(graph, reGrammar);
|
||||
|
|
@ -44,10 +40,6 @@ namespace tp {
|
|||
|
||||
// compile context free grammar
|
||||
{
|
||||
if (!cfGrammar.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ContextFreeGraph graph;
|
||||
ContextFreeCompiler compiler;
|
||||
compiler.compile(cfGrammar, graph);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue