mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Grammar: Added ::items, for seeding the LR0 parse table
This commit is contained in:
parent
c73464b39f
commit
5719191467
2 changed files with 18 additions and 0 deletions
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue