Grammar: Updated ::items to ::augmented, returning the full augmented grammar

This commit is contained in:
Paul Beckingham 2015-12-26 13:35:15 -05:00
parent 5719191467
commit 49ca83ad10
2 changed files with 6 additions and 4 deletions

View file

@ -167,17 +167,19 @@ std::vector <std::string> Grammar::terminals () const
}
////////////////////////////////////////////////////////////////////////////////
std::map <std::string, std::vector <std::string>> Grammar::items () const
std::vector <std::vector <std::string>> Grammar::augmented () const
{
std::map <std::string, std::vector <std::string>> results;
std::vector <std::vector <std::string>> results {{"S", "-->", _start}};
for (auto& rule : _rules)
for (auto& production : rule.second)
{
std::vector <std::string> terms;
terms.push_back (rule.first);
terms.push_back ("-->");
for (auto& token : production)
terms.push_back (token._token);
results.insert (std::pair <std::string, std::vector <std::string>>(rule.first, terms));
results.push_back (terms);
}
return results;

View file

@ -41,7 +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::vector <std::vector <std::string>> augmented () const;
std::string dump () const;
protected: