Grammar: Added ::terminals

This commit is contained in:
Paul Beckingham 2015-12-22 23:40:22 -05:00
parent 35d246aa32
commit 0cd1d48290
2 changed files with 14 additions and 0 deletions

View file

@ -153,6 +153,19 @@ std::vector <std::string> Grammar::rules () const
return results;
}
////////////////////////////////////////////////////////////////////////////////
std::vector <std::string> Grammar::terminals () const
{
std::vector <std::string> results;
for (auto& rule : _rules)
for (auto& production : rule.second)
for (auto& token : production)
if (_rules.find (token._token) == _rules.end ())
results.push_back (token._token);
return results;
}
////////////////////////////////////////////////////////////////////////////////
std::string Grammar::dump () const
{

View file

@ -40,6 +40,7 @@ public:
void loadFromString (const std::string&);
std::string start () const;
std::vector <std::string> rules () const;
std::vector <std::string> terminals () const;
std::string dump () const;
protected: