Grammar: Added ::items, for seeding the LR0 parse table

This commit is contained in:
Paul Beckingham 2015-12-26 12:29:39 -05:00
parent c73464b39f
commit 5719191467
2 changed files with 18 additions and 0 deletions

View file

@ -166,6 +166,23 @@ std::vector <std::string> Grammar::terminals () const
return results;
}
////////////////////////////////////////////////////////////////////////////////
std::map <std::string, std::vector <std::string>> Grammar::items () const
{
std::map <std::string, std::vector <std::string>> results;
for (auto& rule : _rules)
for (auto& production : rule.second)
{
std::vector <std::string> terms;
for (auto& token : production)
terms.push_back (token._token);
results.insert (std::pair <std::string, std::vector <std::string>>(rule.first, terms));
}
return results;
}
////////////////////////////////////////////////////////////////////////////////
std::string Grammar::dump () const
{

View file

@ -41,6 +41,7 @@ public:
std::string start () const;
std::vector <std::string> rules () const;
std::vector <std::string> terminals () const;
std::map <std::string, std::vector <std::string>> items () const;
std::string dump () const;
protected: