1 // THIS FILE IS GENERATED
2 // WARNING! All changes made in this file will be lost!
3 
4 #ifndef cool_H_INCLUDED
5 #define cool_H_INCLUDED
6 
7 #include "cool_ast.h"
8 #include "kdev-pg-memory-pool.h"
9 #include "kdev-pg-allocator.h"
10 #include "kdev-pg-token-stream.h"
11 
12 namespace cool
13   {
14 
15   class parser
16     {
17     public:
18       typedef kdev_pg_token_stream token_stream_type;
19       typedef kdev_pg_token_stream::token_type token_type;
20       kdev_pg_token_stream *token_stream;
21       int yytoken;
22 
23       inline token_type LA(std::size_t k = 1) const
24         {
25           return token_stream->token(token_stream->index() - 1 + k - 1);
26         }
yylex()27       inline int yylex()
28       {
29         return (yytoken = token_stream->next_token());
30       }
rewind(std::size_t index)31       inline void rewind(std::size_t index)
32       {
33         token_stream->rewind(index);
34         yylex();
35       }
36 
37       // token stream
set_token_stream(kdev_pg_token_stream * s)38       void set_token_stream(kdev_pg_token_stream *s)
39       {
40         token_stream = s;
41       }
42 
43       // error handling
44       void yy_expected_symbol(int kind, char const *name);
45       void yy_expected_token(int kind, std::size_t token, char const *name);
46 
47       bool yy_block_errors;
block_errors(bool block)48       inline bool block_errors(bool block)
49       {
50         bool previous = yy_block_errors;
51         yy_block_errors = block;
52         return previous;
53       }
54 
55       // memory pool
56       typedef kdev_pg_memory_pool memory_pool_type;
57 
58       kdev_pg_memory_pool *memory_pool;
set_memory_pool(kdev_pg_memory_pool * p)59       void set_memory_pool(kdev_pg_memory_pool *p)
60       {
61         memory_pool = p;
62       }
63       template <class T>
create()64       inline T *create()
65       {
66         T *node = new (memory_pool->allocate(sizeof(T))) T();
67         node->kind = T::KIND;
68         return node;
69       }
70 
71       enum token_type_enum
72       {
73         Token_ARROW_LEFT = 1000,
74         Token_ARROW_RIGHT = 1001,
75         Token_AT = 1002,
76         Token_CASE = 1003,
77         Token_CLASS = 1004,
78         Token_COLON = 1005,
79         Token_COMMA = 1006,
80         Token_DOT = 1007,
81         Token_ELSE = 1008,
82         Token_EOF = 1009,
83         Token_EQUAL = 1010,
84         Token_ESAC = 1011,
85         Token_FALSE = 1012,
86         Token_FI = 1013,
87         Token_IDENTIFIER = 1014,
88         Token_IF = 1015,
89         Token_IN = 1016,
90         Token_INHERITS = 1017,
91         Token_INTEGER = 1018,
92         Token_INVALID = 1019,
93         Token_ISVOID = 1020,
94         Token_LBRACE = 1021,
95         Token_LESS = 1022,
96         Token_LESS_EQUAL = 1023,
97         Token_LET = 1024,
98         Token_LOOP = 1025,
99         Token_LPAREN = 1026,
100         Token_MINUS = 1027,
101         Token_NEW = 1028,
102         Token_NOT = 1029,
103         Token_OF = 1030,
104         Token_PLUS = 1031,
105         Token_POOL = 1032,
106         Token_RBRACE = 1033,
107         Token_RPAREN = 1034,
108         Token_SEMICOLON = 1035,
109         Token_SLASH = 1036,
110         Token_STAR = 1037,
111         Token_STRING = 1038,
112         Token_THEN = 1039,
113         Token_TILDE = 1040,
114         Token_TRUE = 1041,
115         Token_TYPE = 1042,
116         Token_WHILE = 1043,
117         token_type_size
118       }; // token_type_enum
119 
120       // user defined declarations:
121     public:
122 
123       /**
124        * Transform the raw input into tokens.
125        * When this method returns, the parser's token stream has been filled
126        * and any parse_*() method can be called.
127        */
128       void tokenize( char *contents );
129 
130       enum problem_type {
131         error,
132         warning,
133         info
134       };
135       void report_problem( parser::problem_type type, const char* message );
136       void report_problem( parser::problem_type type, std::string message );
137 
138 
139     public:
parser()140       parser()
141       {
142         memory_pool = 0;
143         token_stream = 0;
144         yytoken = Token_EOF;
145         yy_block_errors = false;
146       }
147 
~parser()148       virtual ~parser()
149       {}
150 
151       bool parse_additive_expression(additive_expression_ast **yynode);
152       bool parse_block_expression(block_expression_ast **yynode);
153       bool parse_case_condition(case_condition_ast **yynode);
154       bool parse_case_expression(case_expression_ast **yynode);
155       bool parse_class(class_ast **yynode);
156       bool parse_expression(expression_ast **yynode);
157       bool parse_feature(feature_ast **yynode);
158       bool parse_formal(formal_ast **yynode);
159       bool parse_if_expression(if_expression_ast **yynode);
160       bool parse_let_declaration(let_declaration_ast **yynode);
161       bool parse_let_expression(let_expression_ast **yynode);
162       bool parse_multiplicative_expression(multiplicative_expression_ast **yynode);
163       bool parse_postfix_expression(postfix_expression_ast **yynode);
164       bool parse_primary_expression(primary_expression_ast **yynode);
165       bool parse_program(program_ast **yynode);
166       bool parse_relational_expression(relational_expression_ast **yynode);
167       bool parse_unary_expression(unary_expression_ast **yynode);
168       bool parse_while_expression(while_expression_ast **yynode);
169     };
170 
171 } // end of namespace cool
172 
173 #endif
174 
175 
176