Last active
August 29, 2015 13:57
-
-
Save d11wtq/9575063 to your computer and use it in GitHub Desktop.
Revisions
-
d11wtq revised this gist
Mar 15, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,7 @@ class ASTNode { template <class T> virtual T accept(Visitor<T> *visitor); }; template <class T> class Visitor { public: virtual T visit(CallNode *node) = 0; virtual T visit(BinExprNode *node) = 0; -
d11wtq revised this gist
Mar 15, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ class ASTNode { public: template <class T> virtual T accept(Visitor<T> *visitor); }; template <class T> -
d11wtq revised this gist
Mar 15, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,6 @@ class Optimizer : public Visitor<ASTNode *> { ASTNode *visit(BinExprNode *node) { ASTNode *optimizedL = <ASTNode *>node->left()->accept(this); ASTNode *optimizedR = <ASTNode *>node->right()->accept(this); return new BinExprNode(optimizedL, node->op(), optimizedR); } }; -
d11wtq revised this gist
Mar 15, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,6 @@ class Optimizer : public Visitor<ASTNode *> { ASTNode *visit(BinExprNode *node) { ASTNode *optimizedL = <ASTNode *>node->left()->accept(this); ASTNode *optimizedR = <ASTNode *>node->right()->accept(this); return new BinExprNode(optimizedL, node->operator(), optimizedR); } }; -
d11wtq revised this gist
Mar 15, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,9 +13,9 @@ class Visitor { class Optimizer : public Visitor<ASTNode *> { public: ASTNode *visit(BinExprNode *node) { ASTNode *optimizedL = <ASTNode *>node->left()->accept(this); ASTNode *optimizedR = <ASTNode *>node->right()->accept(this); return new BinExprNode(optimizedL, optimizedR); } }; -
d11wtq revised this gist
Mar 15, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ class ASTNode { public: template <class T> virtual T accept(Visitor<T> *visitor); }; template <class T> -
d11wtq created this gist
Mar 15, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ class ASTNode { public: template <class T> virtual T accept(Visitor *visitor); }; template <class T> class Visitor { public: virtual T visit(CallNode *node) = 0; virtual T visit(BinExprNode *node) = 0; }; class Optimizer : public Visitor<ASTNode *> { public: ASTNode *visit(CallNode *node) { ASTNode *optimizedL = <ASTNode *>node->left()->accept(this); ASTNode *optimizedR = <ASTNode *>node->right()->accept(this); return new CallNode(optimizedL, optimizedR); } };