File indexing completed on 2024-05-05 04:37:07
0001 // THIS FILE IS GENERATED 0002 // WARNING! All changes made in this file will be lost! 0003 0004 #ifndef cool_H_INCLUDED 0005 #define cool_H_INCLUDED 0006 0007 #include "cool_ast.h" 0008 #include "kdev-pg-memory-pool.h" 0009 #include "kdev-pg-allocator.h" 0010 #include "kdev-pg-token-stream.h" 0011 0012 namespace cool 0013 { 0014 0015 class parser 0016 { 0017 public: 0018 typedef kdev_pg_token_stream token_stream_type; 0019 typedef kdev_pg_token_stream::token_type token_type; 0020 kdev_pg_token_stream *token_stream; 0021 int yytoken; 0022 0023 inline token_type LA(std::size_t k = 1) const 0024 { 0025 return token_stream->token(token_stream->index() - 1 + k - 1); 0026 } 0027 inline int yylex() 0028 { 0029 return (yytoken = token_stream->next_token()); 0030 } 0031 inline void rewind(std::size_t index) 0032 { 0033 token_stream->rewind(index); 0034 yylex(); 0035 } 0036 0037 // token stream 0038 void set_token_stream(kdev_pg_token_stream *s) 0039 { 0040 token_stream = s; 0041 } 0042 0043 // error handling 0044 void yy_expected_symbol(int kind, char const *name); 0045 void yy_expected_token(int kind, std::size_t token, char const *name); 0046 0047 bool yy_block_errors; 0048 inline bool block_errors(bool block) 0049 { 0050 bool previous = yy_block_errors; 0051 yy_block_errors = block; 0052 return previous; 0053 } 0054 0055 // memory pool 0056 typedef kdev_pg_memory_pool memory_pool_type; 0057 0058 kdev_pg_memory_pool *memory_pool; 0059 void set_memory_pool(kdev_pg_memory_pool *p) 0060 { 0061 memory_pool = p; 0062 } 0063 template <class T> 0064 inline T *create() 0065 { 0066 T *node = new (memory_pool->allocate(sizeof(T))) T(); 0067 node->kind = T::KIND; 0068 return node; 0069 } 0070 0071 enum token_type_enum 0072 { 0073 Token_ARROW_LEFT = 1000, 0074 Token_ARROW_RIGHT = 1001, 0075 Token_AT = 1002, 0076 Token_CASE = 1003, 0077 Token_CLASS = 1004, 0078 Token_COLON = 1005, 0079 Token_COMMA = 1006, 0080 Token_DOT = 1007, 0081 Token_ELSE = 1008, 0082 Token_EOF = 1009, 0083 Token_EQUAL = 1010, 0084 Token_ESAC = 1011, 0085 Token_FALSE = 1012, 0086 Token_FI = 1013, 0087 Token_IDENTIFIER = 1014, 0088 Token_IF = 1015, 0089 Token_IN = 1016, 0090 Token_INHERITS = 1017, 0091 Token_INTEGER = 1018, 0092 Token_INVALID = 1019, 0093 Token_ISVOID = 1020, 0094 Token_LBRACE = 1021, 0095 Token_LESS = 1022, 0096 Token_LESS_EQUAL = 1023, 0097 Token_LET = 1024, 0098 Token_LOOP = 1025, 0099 Token_LPAREN = 1026, 0100 Token_MINUS = 1027, 0101 Token_NEW = 1028, 0102 Token_NOT = 1029, 0103 Token_OF = 1030, 0104 Token_PLUS = 1031, 0105 Token_POOL = 1032, 0106 Token_RBRACE = 1033, 0107 Token_RPAREN = 1034, 0108 Token_SEMICOLON = 1035, 0109 Token_SLASH = 1036, 0110 Token_STAR = 1037, 0111 Token_STRING = 1038, 0112 Token_THEN = 1039, 0113 Token_TILDE = 1040, 0114 Token_TRUE = 1041, 0115 Token_TYPE = 1042, 0116 Token_WHILE = 1043, 0117 token_type_size 0118 }; // token_type_enum 0119 0120 // user defined declarations: 0121 public: 0122 0123 /** 0124 * Transform the raw input into tokens. 0125 * When this method returns, the parser's token stream has been filled 0126 * and any parse_*() method can be called. 0127 */ 0128 void tokenize( char *contents ); 0129 0130 enum problem_type { 0131 error, 0132 warning, 0133 info 0134 }; 0135 void report_problem( parser::problem_type type, const char* message ); 0136 void report_problem( parser::problem_type type, std::string message ); 0137 0138 0139 public: 0140 parser() 0141 { 0142 memory_pool = 0; 0143 token_stream = 0; 0144 yytoken = Token_EOF; 0145 yy_block_errors = false; 0146 } 0147 0148 virtual ~parser() 0149 {} 0150 0151 bool parse_additive_expression(additive_expression_ast **yynode); 0152 bool parse_block_expression(block_expression_ast **yynode); 0153 bool parse_case_condition(case_condition_ast **yynode); 0154 bool parse_case_expression(case_expression_ast **yynode); 0155 bool parse_class(class_ast **yynode); 0156 bool parse_expression(expression_ast **yynode); 0157 bool parse_feature(feature_ast **yynode); 0158 bool parse_formal(formal_ast **yynode); 0159 bool parse_if_expression(if_expression_ast **yynode); 0160 bool parse_let_declaration(let_declaration_ast **yynode); 0161 bool parse_let_expression(let_expression_ast **yynode); 0162 bool parse_multiplicative_expression(multiplicative_expression_ast **yynode); 0163 bool parse_postfix_expression(postfix_expression_ast **yynode); 0164 bool parse_primary_expression(primary_expression_ast **yynode); 0165 bool parse_program(program_ast **yynode); 0166 bool parse_relational_expression(relational_expression_ast **yynode); 0167 bool parse_unary_expression(unary_expression_ast **yynode); 0168 bool parse_while_expression(while_expression_ast **yynode); 0169 }; 0170 0171 } // end of namespace cool 0172 0173 #endif 0174 0175