Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Generator {
- class RuleBase { public: virtual ~RuleBase() {} };
- public:
- RuleBase* start;
- class Token : public RuleBase {
- std::wstring ICE;
- public:
- Token(std::wstring ice)
- : ICE(std::move(ice)) {}
- };
- class Rule : public RuleBase {
- std::vector<RuleBase*> contents;
- public:
- void Add(RuleBase* something) {
- contents.push_back(something);
- }
- };
- class Branch : public RuleBase {
- std::vector<RuleBase*> options;
- public:
- void Add(RuleBase* rule) {
- options.push_back(rule);
- }
- };
- Token* CreateToken(std::wstring ICE) {
- return new Token(std::move(ICE));
- }
- Rule* CreateRule() {
- return new Rule;
- }
- Branch* CreateBranch() {
- return new Branch;
- }
- void operator()() {
- // WTF GOES HERE
- }
- };
- int main() {
- Generator g;
- auto identifier = g.CreateToken(L"Wide::Lexer::TokenType::Identifier");
- auto plus = g.CreateToken(L"Wide::Lexer::TokenType::Plus");
- auto expr = g.CreateBranch();
- auto exprplusident = g.CreateRule();
- exprplusident->Add(expr);
- exprplusident->Add(plus);
- exprplusident->Add(identifier);
- expr->Add(exprplusident);
- expr->Add(identifier);
- g.start = exprplusident;
- g();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement