1 #ifndef GMQCC_LEXER_HDR_
2 #define GMQCC_LEXER_HDR_
4 typedef struct token_s token;
11 MEM_VECTOR_MAKE(char, value);
27 void token_delete(token*);
28 token* token_copy(const token *cp);
29 void token_delete_all(token *t);
30 token* token_copy_all(const token *cp);
36 /* Other tokens which we can return: */
46 TOKEN_KEYWORD, /* loop */
48 TOKEN_STRINGCONST, /* not the typename but an actual "string" */
56 /* We use '< TOKEN_ERROR', so TOKEN_FATAL must come after it and any
57 * other error related tokens as well
60 TOKEN_FATAL /* internal error, eg out of memory */
63 static const char *_tokennames[] = {
79 _all_tokennames_added_[
80 ((TOKEN_FATAL - TOKEN_START + 1) ==
81 (sizeof(_tokennames)/sizeof(_tokennames[0])))
88 size_t sline; /* line at the start of a token */
100 MEM_VECTOR_PROTO(lex_file, char, token);
102 lex_file* lex_open (const char *file);
103 void lex_close(lex_file *lex);
104 int lex_do (lex_file *lex);
125 static const oper_info operators[] = {
126 { "++", ASSOC_LEFT, 16, OP_SUFFIX},
127 { "--", ASSOC_LEFT, 16, OP_SUFFIX},
129 { ".", ASSOC_LEFT, 15, 0 },
131 { "!", ASSOC_RIGHT, 14, 0 },
132 { "~", ASSOC_RIGHT, 14, 0 },
133 { "+", ASSOC_RIGHT, 14, OP_PREFIX },
134 { "-", ASSOC_RIGHT, 14, OP_PREFIX },
135 { "++", ASSOC_RIGHT, 14, OP_PREFIX },
136 { "--", ASSOC_RIGHT, 14, OP_PREFIX },
137 /* { "&", ASSOC_RIGHT, 14, OP_PREFIX }, */
139 { "*", ASSOC_LEFT, 13, 0 },
140 { "/", ASSOC_LEFT, 13, 0 },
141 { "%", ASSOC_LEFT, 13, 0 },
143 { "+", ASSOC_LEFT, 12, 0 },
144 { "-", ASSOC_LEFT, 12, 0 },
146 { "<<", ASSOC_LEFT, 11, 0 },
147 { ">>", ASSOC_LEFT, 11, 0 },
149 { "<", ASSOC_LEFT, 10, 0 },
150 { ">", ASSOC_LEFT, 10, 0 },
151 { "<=", ASSOC_LEFT, 10, 0 },
152 { ">=", ASSOC_LEFT, 10, 0 },
154 { "==", ASSOC_LEFT, 9, 0 },
155 { "!=", ASSOC_LEFT, 9, 0 },
157 { "&", ASSOC_LEFT, 8, 0 },
159 { "^", ASSOC_LEFT, 7, 0 },
161 { "|", ASSOC_LEFT, 6, 0 },
163 { "&&", ASSOC_LEFT, 5, 0 },
165 { "||", ASSOC_LEFT, 4, 0 },
167 { "?", ASSOC_RIGHT, 3, 0 },
169 { "=", ASSOC_RIGHT, 2, 0 },
170 { "+=", ASSOC_RIGHT, 2, 0 },
171 { "-=", ASSOC_RIGHT, 2, 0 },
172 { "*=", ASSOC_RIGHT, 2, 0 },
173 { "/=", ASSOC_RIGHT, 2, 0 },
174 { "%=", ASSOC_RIGHT, 2, 0 },
175 { ">>=", ASSOC_RIGHT, 2, 0 },
176 { "<<=", ASSOC_RIGHT, 2, 0 },
177 { "&=", ASSOC_RIGHT, 2, 0 },
178 { "^=", ASSOC_RIGHT, 2, 0 },
179 { "|=", ASSOC_RIGHT, 2, 0 },
191 token *tok; /* current token */
193 MEM_VECTOR_MAKE(ast_value*, globals);
196 MEM_VECTOR_PROTO(parse_file, ast_value*, globals);
198 parse_file* parse_open(const char *file);
199 void parse_file_close(parse_file*);
201 bool parse(parse_file*);
203 bool parse_iskey(parse_file *self, const char *ident);
205 void lexerror(lex_file*, const char *fmt, ...);