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

using namespace std;

class Parser
{
    public:
        Parser(Context * context);
        Context * context;

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

    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);
        void report(string s);

        ASTStatement * statement(ASTNode * node);

        ASTExpression * mul_expr(ASTNode * node);
        ASTExpression * add_expr(ASTNode * node);
        ASTExpression * prim_expr(ASTNode * node);
        ASTExpression * postfix_expr(ASTNode * node);
        ASTExpression * rel_expr(ASTNode * node);
        ASTExpression * eq_expr(ASTNode * node);
        ASTExpression * expr(ASTNode * node);
};

#endif // PARSER_H
