Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. AST ast;
  2. ast.getRoot();
  3.  
  4. #include "AST.h"
  5.  
  6. Compiler::AST::AST() {
  7.  
  8. }
  9.  
  10. void Compiler::AST::addNode(Node node) {
  11. if(rootNull){
  12. setRoot(node);
  13. rootNull = false;
  14. }else{
  15. root.childNodes.push_back(node);
  16. }
  17. }
  18.  
  19. Compiler::AST::Node Compiler::AST::getRoot() {
  20. return root;
  21. }
  22.  
  23. void Compiler::AST::setRoot(Compiler::AST::Node node) {
  24. this->root = node;
  25. }
  26.  
  27. #ifndef COMPILERS_ASSIGNMENT_AST_H
  28. #define COMPILERS_ASSIGNMENT_AST_H
  29.  
  30. #include <string>
  31. #include <vector>
  32. #include <iostream>
  33.  
  34. namespace Compiler {
  35.  
  36.  
  37. class AST {
  38. public:
  39. struct Node{
  40. std::string descriptor;
  41. std::vector <Node> childNodes;
  42. };
  43. typedef Node Node;
  44. AST();
  45. void addNode(Node);
  46. Node getRoot();
  47. private:
  48. Node root;
  49. bool rootNull = true;
  50. void setRoot(Node);
  51. };
  52. }
  53.  
  54. #endif //COMPILERS_ASSIGNMENT_AST_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement