summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Parser.h
blob: 261d3ef89256c2c077020039d8f779dabd866258 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#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 is initialized with pointer or reference to ContextManager,
		 * which is then used to manage contexts in AST created by Parser.
		 */
        Parser(ContextManager * context_manager);
        ContextManager * context_manager;


        virtual ~Parser();
        /**
         * interpret() is essential method in Parser. If given tokens, Parser prepares
         * AST and returns ProgramNode (root node).
         */
        ProgramNode * interpret();

        string error_message;
        void add_tokens(vector<Token> tokens);

        /**
         * show_token() shows token which Parser stores and uses for creating an AST.
         * It's useful during debugging.
         */
        string show_tokens();
        AST tree;
        ProgramNode * program;

        /**
         * resets all info, best to use, when one wants to parse whole new tree
         */
        void erase_all();


    protected:

    private:
        //Not used in current implementation, delete?
        bool is_function_name();
        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 peek_one_ahead(string s);
        bool accept(string s);
        bool expect(string s);
        bool is_type();

        void error(string s);

        /**
         * statement() is function used for parsing statements,
         * it is used as a first in sequence of recurrent calls.
         */
        ASTStatement * statement();
        ASTExpression * expr();
        ASTExpression * log_expr();
        ASTExpression * eq_expr();
        ASTExpression * rel_expr();
        ASTExpression * add_expr();
        ASTExpression * mul_expr();
        ASTExpression * unary_expr();
        ASTExpression * postfix_expr();
        ASTExpression * prim_expr();

};

#endif // PARSER_H