#ifndef PARSER_H
#define PARSER_H
#include <string>
#include <vector>
#include <cstdlib>
#include "Token.h"
#include "ContextManager.h"
#include "AST/AllTypesOfASTNodes.h"
#include "AST/AST.h"

using namespace std;

class Parser
{
    public:
        Parser(ContextManager * context_manager);
        ContextManager * context_manager;

        virtual ~Parser();
        void interpret();
        string error_message;
        void add_tokens(vector<Token> tokens);
        string show_tokens();
        AST tree;
        ProgramNode * program;
        void erase_all();
        bool is_function_name();

    protected:

    private:
        Token current_token;
        string tok_value;
        vector<Token> token_stream;
        unsigned int position_in_stream;

        bool in_statement;
        bool read_next();
        bool peek(string s);
        bool accept(string s);
        bool expect(string s);
        bool is_type();

        void error(string s);


        ASTStatement * statement();

        ASTExpression * log_expr();
        ASTExpression * mul_expr();
        ASTExpression * add_expr();
        ASTExpression * prim_expr();
        ASTExpression * unary_expr();
        ASTExpression * postfix_expr();
        ASTExpression * rel_expr();
        ASTExpression * eq_expr();
        ASTExpression * expr();
};

#endif // PARSER_H
