Skip to content
Snippets Groups Projects
Commit 34930217 authored by Martin Kočička's avatar Martin Kočička Committed by Jan Trávníček
Browse files

added SLR(1) goto table generator

parent cced0790
No related branches found
No related tags found
1 merge request!18Bp kocicma3
......@@ -67,6 +67,23 @@ LRActionTable SLR1ParseTable::getActionTable ( grammar::CFG originalGrammar ) {
return actionTable;
}
 
LRGotoTable SLR1ParseTable::getGotoTable ( grammar::CFG originalGrammar ) {
LRGotoTable gotoTable;
grammar::CFG augmentedGrammar = LRParser::getAugmentedGrammar ( originalGrammar );
automaton::DFA parsingAutomaton = LR0Parser::getAutomaton ( originalGrammar );
for ( const automaton::State & state : parsingAutomaton.getStates ( ) ) {
std::map < std::pair < automaton::State, alphabet::Symbol >, automaton::State > transitionsFromCurrentState = parsingAutomaton.getTransitionsFromState ( state );
for ( const alphabet::Symbol & nonterminal : augmentedGrammar.getNonterminalAlphabet ( ) ) {
std::map < std::pair<automaton::State, alphabet::Symbol >, automaton::State >::iterator transitionIterator = transitionsFromCurrentState.find ( { state, nonterminal } );
if ( transitionIterator != transitionsFromCurrentState.end ( ) ) {
gotoTable.insert ( { { state, nonterminal }, transitionIterator->second } );
}
}
}
return gotoTable;
}
} /* namespace parsing */
 
} /* namespace grammar */
......@@ -22,6 +22,8 @@ class SLR1ParseTable {
 
public:
static LRActionTable getActionTable ( grammar::CFG originalGrammar );
static LRGotoTable getGotoTable ( grammar::CFG originalGrammar );
};
 
} /* namespace parsing */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment