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);
127 #define opid2(a,b) ((a<<8)|b)
128 #define opid3(a,b,c) ((a<<16)|(b<<8)|c)
130 static const oper_info operators[] = {
131 { "++", opid3('S','+','+'), ASSOC_LEFT, 16, OP_SUFFIX},
132 { "--", opid3('S','-','-'), ASSOC_LEFT, 16, OP_SUFFIX},
134 { ".", opid1('.'), ASSOC_LEFT, 15, 0 },
136 { "!", opid2('!', 'P'), ASSOC_RIGHT, 14, 0 },
137 { "~", opid2('~', 'P'), ASSOC_RIGHT, 14, 0 },
138 { "+", opid2('+','P'), ASSOC_RIGHT, 14, OP_PREFIX },
139 { "-", opid2('-','P'), ASSOC_RIGHT, 14, OP_PREFIX },
140 { "++", opid3('+','+','P'), ASSOC_RIGHT, 14, OP_PREFIX },
141 { "--", opid3('-','-','P'), ASSOC_RIGHT, 14, OP_PREFIX },
142 /* { "&", opid2('&','P'), ASSOC_RIGHT, 14, OP_PREFIX }, */
144 { "*", opid1('*'), ASSOC_LEFT, 13, 0 },
145 { "/", opid1('/'), ASSOC_LEFT, 13, 0 },
146 { "%", opid1('%'), ASSOC_LEFT, 13, 0 },
148 { "+", opid1('+'), ASSOC_LEFT, 12, 0 },
149 { "-", opid1('-'), ASSOC_LEFT, 12, 0 },
151 { "<<", opid2('<','<'), ASSOC_LEFT, 11, 0 },
152 { ">>", opid2('>','>'), ASSOC_LEFT, 11, 0 },
154 { "<", opid1('<'), ASSOC_LEFT, 10, 0 },
155 { ">", opid1('>'), ASSOC_LEFT, 10, 0 },
156 { "<=", opid2('<','='), ASSOC_LEFT, 10, 0 },
157 { ">=", opid2('>','='), ASSOC_LEFT, 10, 0 },
159 { "==", opid2('=','='), ASSOC_LEFT, 9, 0 },
160 { "!=", opid2('!','='), ASSOC_LEFT, 9, 0 },
162 { "&", opid1('&'), ASSOC_LEFT, 8, 0 },
164 { "^", opid1('^'), ASSOC_LEFT, 7, 0 },
166 { "|", opid1('|'), ASSOC_LEFT, 6, 0 },
168 { "&&", opid2('&','&'), ASSOC_LEFT, 5, 0 },
170 { "||", opid2('|','|'), ASSOC_LEFT, 4, 0 },
172 { "?", opid2('?',':'), ASSOC_RIGHT, 3, 0 },
174 { "=", opid1('='), ASSOC_RIGHT, 2, 0 },
175 { "+=", opid2('+','='), ASSOC_RIGHT, 2, 0 },
176 { "-=", opid2('-','='), ASSOC_RIGHT, 2, 0 },
177 { "*=", opid2('*','='), ASSOC_RIGHT, 2, 0 },
178 { "/=", opid2('/','='), ASSOC_RIGHT, 2, 0 },
179 { "%=", opid2('%','='), ASSOC_RIGHT, 2, 0 },
180 { ">>=", opid3('>','>','='), ASSOC_RIGHT, 2, 0 },
181 { "<<=", opid3('<','<','='), ASSOC_RIGHT, 2, 0 },
182 { "&=", opid2('&','='), ASSOC_RIGHT, 2, 0 },
183 { "^=", opid2('^','='), ASSOC_RIGHT, 2, 0 },
184 { "|=", opid2('|','='), ASSOC_RIGHT, 2, 0 },
196 token *tok; /* current token */
198 MEM_VECTOR_MAKE(ast_value*, globals);
201 MEM_VECTOR_PROTO(parse_file, ast_value*, globals);
203 parse_file* parse_open(const char *file);
204 void parse_file_close(parse_file*);
206 bool parse(parse_file*);
208 bool parse_iskey(parse_file *self, const char *ident);
210 void lexerror(lex_file*, const char *fmt, ...);