compiler / tree.h
tree.h
Raw
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
using std::string;
using std::vector;
using std::map;
using std::pair;

class AnalysisError {
    string type;

    public:
        AnalysisError(string type);
        const string what() const;
};

class Tree;

class Node {
    public:
        string rule;
        string symbol;
        bool isTerminal;
        string value;
        vector<Node *> children;
        Tree *t;

        Node(string rule, Tree *t);
        ~Node();

        void print();
        void traverse();
        void checkParam();
        void checkVar();
        string getType();
        void generate();
};

class Tree {
    public:
        Node *root;
        vector<string> &parsedTokens;
        map<string, pair<vector<string>, map<string, string>>> tables;
        map<string, string> table;
        vector<string> params;
        string currentProcedure;
        int varCount;
        int argCount;
        map<string, int> varOffset;
        map<string, pair<map<string, int>, int>> varOffsets;
        int loopCount;

        Tree(vector<string> &parsedTokens);
        ~Tree();
        void print();
        void traverse();
        void generate();
        string getNextToken();
};