Advertisement
Guest User

Untitled

a guest
Feb 1st, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. class Generator {
  2. class RuleBase { public: virtual ~RuleBase() {} };
  3. public:
  4. RuleBase* start;
  5. class Token : public RuleBase {
  6. std::wstring ICE;
  7. public:
  8. Token(std::wstring ice)
  9. : ICE(std::move(ice)) {}
  10. };
  11. class Rule : public RuleBase {
  12. std::vector<RuleBase*> contents;
  13. public:
  14. void Add(RuleBase* something) {
  15. contents.push_back(something);
  16. }
  17. };
  18. class Branch : public RuleBase {
  19. std::vector<RuleBase*> options;
  20. public:
  21. void Add(RuleBase* rule) {
  22. options.push_back(rule);
  23. }
  24. };
  25. Token* CreateToken(std::wstring ICE) {
  26. return new Token(std::move(ICE));
  27. }
  28. Rule* CreateRule() {
  29. return new Rule;
  30. }
  31. Branch* CreateBranch() {
  32. return new Branch;
  33. }
  34. void operator()() {
  35. // WTF GOES HERE
  36. }
  37. };
  38.  
  39. int main() {
  40. Generator g;
  41.  
  42. auto identifier = g.CreateToken(L"Wide::Lexer::TokenType::Identifier");
  43. auto plus = g.CreateToken(L"Wide::Lexer::TokenType::Plus");
  44.  
  45. auto expr = g.CreateBranch();
  46. auto exprplusident = g.CreateRule();
  47. exprplusident->Add(expr);
  48. exprplusident->Add(plus);
  49. exprplusident->Add(identifier);
  50. expr->Add(exprplusident);
  51. expr->Add(identifier);
  52.  
  53. g.start = exprplusident;
  54.  
  55. g();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement