summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Parser.h
blob: 91f8d6f63abcd7a8c9a65b74105fbd8cc71ddfcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#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 * postfix_expr();
        ASTExpression * rel_expr();
        ASTExpression * eq_expr();
        ASTExpression * expr();
};

#endif // PARSER_H