From 66bcf26aa0377489f6806aaa835a35b9cd55e049 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 30 Aug 2013 11:40:38 -0700 Subject: [PATCH] Entity Lists - LRParser::addEntity accumulates categorized entities for the parser. --- src/parser/LRParser.cpp | 6 ++++++ src/parser/LRParser.h | 7 ++++++- src/parser/bnf.cpp | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/parser/LRParser.cpp b/src/parser/LRParser.cpp index 09cbb43ba..b068a655b 100644 --- a/src/parser/LRParser.cpp +++ b/src/parser/LRParser.cpp @@ -62,6 +62,12 @@ Tree* LRParser::parse (const std::string& tokens) return tree; } +//////////////////////////////////////////////////////////////////////////////// +void LRParser::addEntity (const std::string& name, const std::string& value) +{ + _entities.insert (std::pair (name, value)); +} + //////////////////////////////////////////////////////////////////////////////// // Wraps calls to matchRule, while properly handling the quantifier. bool LRParser::matchRuleQuant ( diff --git a/src/parser/LRParser.h b/src/parser/LRParser.h index 489f1136a..fe761aa79 100644 --- a/src/parser/LRParser.h +++ b/src/parser/LRParser.h @@ -28,13 +28,15 @@ #ifndef INCLUDED_LRPARSER #define INCLUDED_LRPARSER -#include "Parser.h" +#include +#include class LRParser : public Parser { public: LRParser (); Tree* parse (const std::string&); + void addEntity (const std::string&, const std::string&); private: bool matchRuleQuant (const std::string&, char, unsigned int&, const std::string&, Tree*); @@ -46,6 +48,9 @@ private: bool tokenMatchLiteral (const Token&, unsigned int&, const std::string&, Tree*); bool tokenMatchRegex (const Token&, unsigned int&, const std::string&, Tree*); bool tokenMatchRule (const std::string&, char, unsigned int, unsigned int, const Token&, unsigned int&, const std::string&, Tree*); + +private: + std::multimap _entities; }; #endif diff --git a/src/parser/bnf.cpp b/src/parser/bnf.cpp index 2d4f81ea1..2e99adddf 100644 --- a/src/parser/bnf.cpp +++ b/src/parser/bnf.cpp @@ -103,9 +103,14 @@ int main (int argc, char** argv) LRParser p; if (verbose) p.verbose (); - p.grammar (grammar); + // TODO Initialize entity lists. + p.addEntity ("report", "list"); + // Load and verify grammar. + p.grammar (grammar); if (verbose) p.dump (); + + // Either returns a parse-tree or throws. Tree* t = p.parse (commandLine); if (t) {