9 date 2007.11.11.22.35.46; author khansen; state Exp;
14 date 2007.08.19.11.19.47; author khansen; state Exp;
19 date 2007.08.12.18.58.49; author khansen; state Exp;
24 date 2007.08.11.01.25.39; author khansen; state Exp;
29 date 2007.08.10.20.21.36; author khansen; state Exp;
34 date 2007.07.22.13.34.16; author khansen; state Exp;
39 date 2005.01.09.11.20.31; author kenth; state Exp;
44 date 2004.12.19.19.59.08; author kenth; state Exp;
49 date 2004.12.16.13.22.08; author kenth; state Exp;
54 date 2004.12.14.01.50.33; author kenth; state Exp;
59 date 2004.12.11.02.12.32; author kenth; state Exp;
64 date 2004.12.10.22.43.53; author kenth; state Exp;
69 date 2004.12.09.11.15.28; author kenth; state Exp;
74 date 2004.12.06.05.06.29; author kenth; state Exp;
79 date 2004.06.30.07.56.59; author kenth; state Exp;
95 * $Id: scanner.l,v 1.14 2007/08/19 11:19:47 khansen Exp khansen $
97 * Revision 1.14 2007/08/19 11:19:47 khansen
98 * --case-insensitive option
100 * Revision 1.13 2007/08/12 18:58:49 khansen
101 * ability to generate pure 6502 binary
103 * Revision 1.12 2007/08/11 01:25:39 khansen
104 * includepaths support (-I option)
106 * Revision 1.11 2007/08/10 20:21:36 khansen
107 * *** empty log message ***
109 * Revision 1.10 2007/07/22 13:34:16 khansen
110 * convert tabs to whitespaces
112 * Revision 1.9 2005/01/09 11:20:31 kenth
116 * Revision 1.8 2004/12/19 19:59:08 kenth
119 * Revision 1.7 2004/12/16 13:22:08 kenth
120 * added DEFINE parsing
122 * Revision 1.6 2004/12/14 01:50:33 kenth
125 * Revision 1.5 2004/12/11 02:12:32 kenth
128 * Revision 1.4 2004/12/10 22:43:53 kenth
129 * removed FILE_PATH recognition: ".db <a, >b" is erronously parsed otherwise
131 * Revision 1.3 2004/12/09 11:15:28 kenth
132 * bugfix: close file handle
133 * added: "WARNING", "ERROR" recognition
135 * Revision 1.2 2004/12/06 05:06:29 kenth
138 * Revision 1.1 2004/06/30 07:56:59 kenth
144 void yyerror(const char *); /* See below */
145 char *strip_label(); /* See below */
146 const char *maybe_ignorecase(char *);
153 /* Each time we match a string, move the end cursor to its end. */
154 #define YY_USER_ACTION yylloc.last_column += yyleng;
158 string_literal \"[^\n"]*\"
159 binary_literal [0-1]+
160 octal_literal 0[0-7]*
161 decimal_literal [1-9][0-9]*
162 hex_literal [0-9A-F]+
163 hex_literal2 [0-9][0-9A-F]*
164 hex_literal3 0[A-F][0-9A-F]*
165 identifier [A-Z_][A-Z0-9_]{0,254}
166 local_id [0-9A-Z_]{1,255}
171 /* At each yylex invocation, mark the current position as the
172 start of the next token. */
173 LOCATION_STEP (yylloc);
175 {whitespace} { LOCATION_STEP (yylloc); }
176 {comment} { LOCATION_STEP (yylloc); }
177 "%"{binary_literal} { yylval.integer = strtol(&yytext[1], NULL, 2); return(INTEGER_LITERAL); }
178 {binary_literal}"B" { yylval.integer = strtol(yytext, NULL, 2); return(INTEGER_LITERAL); }
179 {octal_literal} { yylval.integer = strtol(yytext, NULL, 8); return(INTEGER_LITERAL); }
180 {decimal_literal} { yylval.integer = strtol(yytext, NULL, 10); return(INTEGER_LITERAL); }
181 "0X"{hex_literal} { yylval.integer = strtol(&yytext[2], NULL, 16); return(INTEGER_LITERAL); }
182 "$"{hex_literal} { yylval.integer = strtol(&yytext[1], NULL, 16); return(INTEGER_LITERAL); }
183 {hex_literal3}"H" { yylval.integer = strtol(yytext, NULL, 16); return(INTEGER_LITERAL); }
184 {hex_literal2}"H" { yylval.integer = strtol(yytext, NULL, 16); return(INTEGER_LITERAL); }
185 "'"."'" { yylval.integer = yytext[1]; return(INTEGER_LITERAL); }
186 "ADC" { yylval.mnemonic = ADC_MNEMONIC; return(MNEMONIC); }
187 "AND" { yylval.mnemonic = AND_MNEMONIC; return(MNEMONIC); }
188 "ASL" { yylval.mnemonic = ASL_MNEMONIC; return(MNEMONIC); }
189 "BCC" { yylval.mnemonic = BCC_MNEMONIC; return(MNEMONIC); }
190 "BCS" { yylval.mnemonic = BCS_MNEMONIC; return(MNEMONIC); }
191 "BLT" { yylval.mnemonic = BCC_MNEMONIC; return(MNEMONIC); }
192 "BGE" { yylval.mnemonic = BCS_MNEMONIC; return(MNEMONIC); }
193 "BEQ" { yylval.mnemonic = BEQ_MNEMONIC; return(MNEMONIC); }
194 "BIT" { yylval.mnemonic = BIT_MNEMONIC; return(MNEMONIC); }
195 "BMI" { yylval.mnemonic = BMI_MNEMONIC; return(MNEMONIC); }
196 "BNE" { yylval.mnemonic = BNE_MNEMONIC; return(MNEMONIC); }
197 "BPL" { yylval.mnemonic = BPL_MNEMONIC; return(MNEMONIC); }
198 "BRK" { yylval.mnemonic = BRK_MNEMONIC; return(MNEMONIC); }
199 "BVC" { yylval.mnemonic = BVC_MNEMONIC; return(MNEMONIC); }
200 "BVS" { yylval.mnemonic = BVS_MNEMONIC; return(MNEMONIC); }
201 "CLC" { yylval.mnemonic = CLC_MNEMONIC; return(MNEMONIC); }
202 "CLD" { yylval.mnemonic = CLD_MNEMONIC; return(MNEMONIC); }
203 "CLI" { yylval.mnemonic = CLI_MNEMONIC; return(MNEMONIC); }
204 "CLV" { yylval.mnemonic = CLV_MNEMONIC; return(MNEMONIC); }
205 "CMP" { yylval.mnemonic = CMP_MNEMONIC; return(MNEMONIC); }
206 "CPX" { yylval.mnemonic = CPX_MNEMONIC; return(MNEMONIC); }
207 "CPY" { yylval.mnemonic = CPY_MNEMONIC; return(MNEMONIC); }
208 "DEC" { yylval.mnemonic = DEC_MNEMONIC; return(MNEMONIC); }
209 "DEX" { yylval.mnemonic = DEX_MNEMONIC; return(MNEMONIC); }
210 "DEY" { yylval.mnemonic = DEY_MNEMONIC; return(MNEMONIC); }
211 "EOR" { yylval.mnemonic = EOR_MNEMONIC; return(MNEMONIC); }
212 "INC" { yylval.mnemonic = INC_MNEMONIC; return(MNEMONIC); }
213 "INX" { yylval.mnemonic = INX_MNEMONIC; return(MNEMONIC); }
214 "INY" { yylval.mnemonic = INY_MNEMONIC; return(MNEMONIC); }
215 "JMP" { yylval.mnemonic = JMP_MNEMONIC; return(MNEMONIC); }
216 "JSR" { yylval.mnemonic = JSR_MNEMONIC; return(MNEMONIC); }
217 "LDA" { yylval.mnemonic = LDA_MNEMONIC; return(MNEMONIC); }
218 "LDX" { yylval.mnemonic = LDX_MNEMONIC; return(MNEMONIC); }
219 "LDY" { yylval.mnemonic = LDY_MNEMONIC; return(MNEMONIC); }
220 "LSR" { yylval.mnemonic = LSR_MNEMONIC; return(MNEMONIC); }
221 "NOP" { yylval.mnemonic = NOP_MNEMONIC; return(MNEMONIC); }
222 "ORA" { yylval.mnemonic = ORA_MNEMONIC; return(MNEMONIC); }
223 "PHA" { yylval.mnemonic = PHA_MNEMONIC; return(MNEMONIC); }
224 "PHP" { yylval.mnemonic = PHP_MNEMONIC; return(MNEMONIC); }
225 "PLA" { yylval.mnemonic = PLA_MNEMONIC; return(MNEMONIC); }
226 "PLP" { yylval.mnemonic = PLP_MNEMONIC; return(MNEMONIC); }
227 "ROL" { yylval.mnemonic = ROL_MNEMONIC; return(MNEMONIC); }
228 "ROR" { yylval.mnemonic = ROR_MNEMONIC; return(MNEMONIC); }
229 "RTI" { yylval.mnemonic = RTI_MNEMONIC; return(MNEMONIC); }
230 "RTS" { yylval.mnemonic = RTS_MNEMONIC; return(MNEMONIC); }
231 "SBC" { yylval.mnemonic = SBC_MNEMONIC; return(MNEMONIC); }
232 "SEC" { yylval.mnemonic = SEC_MNEMONIC; return(MNEMONIC); }
233 "SED" { yylval.mnemonic = SED_MNEMONIC; return(MNEMONIC); }
234 "SEI" { yylval.mnemonic = SEI_MNEMONIC; return(MNEMONIC); }
235 "STA" { yylval.mnemonic = STA_MNEMONIC; return(MNEMONIC); }
236 "STX" { yylval.mnemonic = STX_MNEMONIC; return(MNEMONIC); }
237 "STY" { yylval.mnemonic = STY_MNEMONIC; return(MNEMONIC); }
238 "TAX" { yylval.mnemonic = TAX_MNEMONIC; return(MNEMONIC); }
239 "TAY" { yylval.mnemonic = TAY_MNEMONIC; return(MNEMONIC); }
240 "TSX" { yylval.mnemonic = TSX_MNEMONIC; return(MNEMONIC); }
241 "TXA" { yylval.mnemonic = TXA_MNEMONIC; return(MNEMONIC); }
242 "TXS" { yylval.mnemonic = TXS_MNEMONIC; return(MNEMONIC); }
243 "TYA" { yylval.mnemonic = TYA_MNEMONIC; return(MNEMONIC); }
247 "MASK" { return(MASK); }
248 "SIZEOF" { return(SIZEOF); }
249 {pragma_prefix}"DATA" { return(DATASEG); }
250 {pragma_prefix}"CODE" { return(CODESEG); }
251 {pragma_prefix}"DATASEG" { return(DATASEG); }
252 {pragma_prefix}"CODESEG" { return(CODESEG); }
253 {pragma_prefix}"IF" { return(IF); }
254 {pragma_prefix}"IFDEF" { return(IFDEF); }
255 {pragma_prefix}"IFNDEF" { return(IFNDEF); }
256 {pragma_prefix}"ELSE" { return(ELSE); }
257 {pragma_prefix}"ELIF" { return(ELIF); }
258 {pragma_prefix}"ENDIF" { return(ENDIF); }
259 {pragma_prefix}"MACRO" { return(MACRO); }
260 {pragma_prefix}"END" { return(END); }
261 {pragma_prefix}"ENDE" { return(ENDE); }
262 {pragma_prefix}"ENDM" { return(ENDM); }
263 {pragma_prefix}"ENDP" { return(ENDP); }
264 {pragma_prefix}"ENDS" { return(ENDS); }
265 {pragma_prefix}"EQU" { return(EQU); }
266 {pragma_prefix}"DEFINE" { return(DEFINE); }
267 {pragma_prefix}"INCLUDE" { return(INCSRC); }
268 {pragma_prefix}"INCSRC" { return(INCSRC); }
269 {pragma_prefix}"INCBIN" { return(INCBIN); }
270 {pragma_prefix}"ALIGN" { return(ALIGN); }
271 {pragma_prefix}"PUBLIC" { return(PUBLIC); }
272 {pragma_prefix}"EXTRN" { return(EXTRN); }
273 {pragma_prefix}"ZEROPAGE" { return(ZEROPAGE); }
274 {pragma_prefix}"CHARMAP" { return(CHARMAP); }
275 {pragma_prefix}"STRUC" { return(STRUC); }
276 {pragma_prefix}"UNION" { return(UNION); }
277 {pragma_prefix}"RECORD" { return(RECORD); }
278 {pragma_prefix}"ENUM" { return(ENUM); }
279 {pragma_prefix}"PROC" { return(PROC); }
280 {pragma_prefix}"REPT" { return(REPT); }
281 {pragma_prefix}"TAG" { return(TAG); }
282 {pragma_prefix}"TYPE" { return(TAG); }
283 {pragma_prefix}"LABEL" { return(_LABEL_); }
284 {pragma_prefix}"MESSAGE" { return(MESSAGE); }
285 {pragma_prefix}"WARNING" { return(WARNING); }
286 {pragma_prefix}"ERROR" { return(ERROR); }
287 {pragma_prefix}"WHILE" { return(WHILE); }
288 {pragma_prefix}"PAD" { return(DSB); }
289 {pragma_prefix}"DB" { return(BYTE); }
290 {pragma_prefix}"BYTE" { return(BYTE); }
291 {pragma_prefix}"CHAR" { return(CHAR); }
292 {pragma_prefix}"ASC" { return(CHAR); }
293 {pragma_prefix}"DW" { return(WORD); }
294 {pragma_prefix}"WORD" { return(WORD); }
295 {pragma_prefix}"DD" { return(DWORD); }
296 {pragma_prefix}"DWORD" { return(DWORD); }
297 {pragma_prefix}"DSB" { return(DSB); }
298 {pragma_prefix}"DSW" { return(DSW); }
299 {pragma_prefix}"DSD" { return(DSD); }
300 {pragma_prefix}"ORG" { return(ORG); }
301 {label_prefix}{identifier}":" { yylval.label = maybe_ignorecase(strip_label()); return(LABEL); }
302 {label_prefix}"@@@@"{local_id}":" { yylval.label = maybe_ignorecase(strip_label()); return(LOCAL_LABEL); }
303 "@@@@"{local_id} { yylval.ident = maybe_ignorecase(yytext); return(LOCAL_ID); }
304 {identifier} { yylval.ident = maybe_ignorecase(yytext); return(IDENTIFIER); }
305 {string_literal} { yytext[yyleng-1] = '\0'; yylval.string = &yytext[1]; return(STRING_LITERAL); }
306 "+"{2,8} { yylval.ident = yytext; return(FORWARD_BRANCH); }
307 "-"{2,8} { yylval.ident = yytext; return(BACKWARD_BRANCH); }
308 "::" { return(SCOPE_OP); }
310 \n { LOCATION_LINES (yylloc, yyleng); LOCATION_STEP (yylloc); return('\n'); }
315 "(" { return( yyparswap ? '[' : '(' ); }
316 ")" { return( yyparswap ? ']' : ')' ); }
317 "[" { return( yyparswap ? '(' : '[' ); }
318 "]" { return( yyparswap ? ')' : ']'); }
333 ">>" { return(SHR_OP); }
334 "<<" { return(SHL_OP); }
335 "<=" { return(LE_OP); }
336 ">=" { return(GE_OP); }
337 "==" { return(EQ_OP); }
338 "!=" { return(NE_OP); }
340 "@@" { return('@@'); }
341 . { yyerror("Skipping invalid character(s)"); LOCATION_STEP (yylloc); }
344 * Describes a file stack record.
345 * It holds name, location and buffer state for it.
347 typedef struct tag_file_stack_rec {
348 const char *name; /* Name of the file */
349 YY_BUFFER_STATE buf; /* flex input buffer */
350 YYLTYPE loc; /* Current position in file */
351 FILE *fp; /* File handle */
354 /* Max. nesting depth */
355 #define FILE_STACK_SIZE 32
358 static file_stack_rec file_stack[FILE_STACK_SIZE];
360 /* File stack pointer */
361 static int file_stack_ptr;
363 /* Macro to access top of file stack */
364 #define FTOS() file_stack[file_stack_ptr]
367 * Resets the location described by yylloc.
369 void yyresetloc(void)
371 LOCATION_RESET(yylloc);
375 * Function called by lexer upon EOF(yyin).
379 /* Discard of buffer that has been scanned */
380 yy_delete_buffer(YY_CURRENT_BUFFER);
381 /* Close current file */
383 /* Resume scanning of previous buffer, if any */
384 if (file_stack_ptr > 0) {
387 /* Restore location */
389 /* Resume scanning from this buffer */
390 yy_switch_to_buffer(FTOS().buf);
391 /* Not end of all input. */
395 /* We have reached end of all input. */
401 * Opens a file and resumes scanning from there.
402 * The current file's status is pushed on stack.
403 * @@param filename Name of new file to start scanning
404 * @@return error code (0, 1 or 2)
406 int yypushandrestart(const char *filename)
409 /* Check for stack overflow */
410 if (file_stack_ptr == FILE_STACK_SIZE-1) {
411 /* Error, stack overflow */
414 /* Attempt to open file */
415 fp = fopen(filename, "rt");
416 if (!fp && (filename[0] != '/')) {
417 /* Try search paths */
419 for (i = 0; i < xasm_args.include_path_count; ++i) {
420 const char *include_path = xasm_args.include_paths[i];
421 char *path = (char *)malloc(
422 strlen(include_path) + strlen("/") + strlen(filename) + 1);
423 strcpy(path, include_path);
425 strcat(path, filename);
426 fp = fopen(path, "rt");
433 /* Save position in current file */
435 /* Push the new file */
437 FTOS().name = filename;
438 FTOS().buf = yy_create_buffer(fp, YY_BUF_SIZE);
440 /* Reset file location */
442 /* Resume scanning from the new buffer */
443 yy_switch_to_buffer(FTOS().buf);
448 /* Error, couldn't open file */
454 * Initializes the lexer, tells it to start tokenizing from the given file.
455 * @@param filename Name of file where scanning is initiated
456 * @@param swap_parens Use ( ) for indirection if 1, [ ] otherwise
457 * @@return 1 if success, 0 otherwise
459 int yybegin(const char *filename, int swap_parens, int ignore_case)
462 yyparswap = swap_parens;
463 yyignorecase = ignore_case;
464 /* Attempt to open the given file */
465 fp = fopen(filename, "rt");
469 FTOS().name = filename;
470 FTOS().buf = yy_create_buffer(fp, YY_BUF_SIZE);
472 /* Reset file location */
474 /* Use the new buffer */
475 yy_switch_to_buffer(FTOS().buf);
480 /* Couldn't open file */
486 * Gets the name of the file that is currently being tokenized.
488 const char *yy_current_filename()
494 * Called by the parser to report an error during parsing.
495 * @@param s Error message
497 void yyerror(const char *s) {
499 /* Print line of form: file:pos:message */
500 fprintf(stderr, "%s:", yy_current_filename());
501 LOCATION_PRINT(stderr, yylloc);
502 fprintf(stderr, ": %s\n", s);
503 /* Print include-trace */
504 for (i=file_stack_ptr-1; i>=0; i--) {
505 fprintf(stderr, "(%s:", file_stack[i].name);
506 LOCATION_PRINT(stderr, file_stack[i].loc);
507 fprintf(stderr, ")\n");
512 * Call when yytext is a label to remove whitespace and punctuation.
517 /* Kill the ':' at the end */
518 yytext[strlen(yytext)-1] = 0;
519 /* Skip the whitespace, if any */
521 while ((yytext[start] == ' ') || (yytext[start] == '\t')) start++;
522 return &yytext[start];
525 static char *__strupr(char *str)
535 const char *maybe_ignorecase(char *str)
546 @--case-insensitive option
551 * $Id: scanner.l,v 1.13 2007/08/12 18:58:49 khansen Exp khansen $
557 return yyignorecase ? strupr(str) : str;
563 @ability to generate pure 6502 binary
568 * $Id: scanner.l,v 1.12 2007/08/11 01:25:39 khansen Exp khansen $
572 void yyerror(char *); /* See below */
576 {label_prefix}{identifier}":" { yylval.label = strip_label(); return(LABEL); }
577 {label_prefix}"@@@@"{local_id}":" { yylval.label = strip_label(); return(LOCAL_LABEL); }
578 "@@@@"{local_id} { yylval.ident = yytext; return(LOCAL_ID); }
579 {identifier} { yylval.ident = yytext; return(IDENTIFIER); }
582 int yypushandrestart(char *filename)
585 int yybegin(const char *filename, int swap_parens)
589 void yyerror(char *s) {
596 @includepaths support (-I option)
601 * $Id: scanner.l,v 1.11 2007/08/10 20:21:36 khansen Exp khansen $
609 @*** empty log message ***
614 * $Id: scanner.l,v 1.10 2007/07/22 13:34:16 khansen Exp khansen $
623 @convert tabs to whitespaces
628 * $Id: scanner.l,v 1.9 2005/01/09 11:20:31 kenth Exp khansen $
632 char *name; /* Name of the file */
635 int yybegin(char *filename, int swap_parens)
638 char *yy_current_filename()
650 * $Id: scanner.l,v 1.8 2004/12/19 19:59:08 kenth Exp kenth $
654 void yyerror(char *); /* See below */
655 char *strip_label(); /* See below */
660 string_literal \"[^\n"]*\"
661 binary_literal [0-1]+
662 octal_literal 0[0-7]*
663 decimal_literal [1-9][0-9]*
664 hex_literal [0-9A-F]+
665 hex_literal2 [0-9][0-9A-F]*
666 hex_literal3 0[A-F][0-9A-F]*
667 identifier [A-Z_][A-Z0-9_]{0,254}
668 local_id [0-9A-Z_]{1,255}
673 start of the next token. */
676 {whitespace} { LOCATION_STEP (yylloc); }
677 {comment} { LOCATION_STEP (yylloc); }
678 "%"{binary_literal} { yylval.integer = strtol(&yytext[1], NULL, 2); return(INTEGER_LITERAL); }
679 {binary_literal}"B" { yylval.integer = strtol(yytext, NULL, 2); return(INTEGER_LITERAL); }
680 {octal_literal} { yylval.integer = strtol(yytext, NULL, 8); return(INTEGER_LITERAL); }
681 {decimal_literal} { yylval.integer = strtol(yytext, NULL, 10); return(INTEGER_LITERAL); }
682 "0X"{hex_literal} { yylval.integer = strtol(&yytext[2], NULL, 16); return(INTEGER_LITERAL); }
683 "$"{hex_literal} { yylval.integer = strtol(&yytext[1], NULL, 16); return(INTEGER_LITERAL); }
684 {hex_literal3}"H" { yylval.integer = strtol(yytext, NULL, 16); return(INTEGER_LITERAL); }
685 {hex_literal2}"H" { yylval.integer = strtol(yytext, NULL, 16); return(INTEGER_LITERAL); }
686 "'"."'" { yylval.integer = yytext[1]; return(INTEGER_LITERAL); }
687 "ADC" { yylval.mnemonic = ADC_MNEMONIC; return(MNEMONIC); }
688 "AND" { yylval.mnemonic = AND_MNEMONIC; return(MNEMONIC); }
689 "ASL" { yylval.mnemonic = ASL_MNEMONIC; return(MNEMONIC); }
690 "BCC" { yylval.mnemonic = BCC_MNEMONIC; return(MNEMONIC); }
691 "BCS" { yylval.mnemonic = BCS_MNEMONIC; return(MNEMONIC); }
692 "BLT" { yylval.mnemonic = BCC_MNEMONIC; return(MNEMONIC); }
693 "BGE" { yylval.mnemonic = BCS_MNEMONIC; return(MNEMONIC); }
694 "BEQ" { yylval.mnemonic = BEQ_MNEMONIC; return(MNEMONIC); }
695 "BIT" { yylval.mnemonic = BIT_MNEMONIC; return(MNEMONIC); }
696 "BMI" { yylval.mnemonic = BMI_MNEMONIC; return(MNEMONIC); }
697 "BNE" { yylval.mnemonic = BNE_MNEMONIC; return(MNEMONIC); }
698 "BPL" { yylval.mnemonic = BPL_MNEMONIC; return(MNEMONIC); }
699 "BRK" { yylval.mnemonic = BRK_MNEMONIC; return(MNEMONIC); }
700 "BVC" { yylval.mnemonic = BVC_MNEMONIC; return(MNEMONIC); }
701 "BVS" { yylval.mnemonic = BVS_MNEMONIC; return(MNEMONIC); }
702 "CLC" { yylval.mnemonic = CLC_MNEMONIC; return(MNEMONIC); }
703 "CLD" { yylval.mnemonic = CLD_MNEMONIC; return(MNEMONIC); }
704 "CLI" { yylval.mnemonic = CLI_MNEMONIC; return(MNEMONIC); }
705 "CLV" { yylval.mnemonic = CLV_MNEMONIC; return(MNEMONIC); }
706 "CMP" { yylval.mnemonic = CMP_MNEMONIC; return(MNEMONIC); }
707 "CPX" { yylval.mnemonic = CPX_MNEMONIC; return(MNEMONIC); }
708 "CPY" { yylval.mnemonic = CPY_MNEMONIC; return(MNEMONIC); }
709 "DEC" { yylval.mnemonic = DEC_MNEMONIC; return(MNEMONIC); }
710 "DEX" { yylval.mnemonic = DEX_MNEMONIC; return(MNEMONIC); }
711 "DEY" { yylval.mnemonic = DEY_MNEMONIC; return(MNEMONIC); }
712 "EOR" { yylval.mnemonic = EOR_MNEMONIC; return(MNEMONIC); }
713 "INC" { yylval.mnemonic = INC_MNEMONIC; return(MNEMONIC); }
714 "INX" { yylval.mnemonic = INX_MNEMONIC; return(MNEMONIC); }
715 "INY" { yylval.mnemonic = INY_MNEMONIC; return(MNEMONIC); }
716 "JMP" { yylval.mnemonic = JMP_MNEMONIC; return(MNEMONIC); }
717 "JSR" { yylval.mnemonic = JSR_MNEMONIC; return(MNEMONIC); }
718 "LDA" { yylval.mnemonic = LDA_MNEMONIC; return(MNEMONIC); }
719 "LDX" { yylval.mnemonic = LDX_MNEMONIC; return(MNEMONIC); }
720 "LDY" { yylval.mnemonic = LDY_MNEMONIC; return(MNEMONIC); }
721 "LSR" { yylval.mnemonic = LSR_MNEMONIC; return(MNEMONIC); }
722 "NOP" { yylval.mnemonic = NOP_MNEMONIC; return(MNEMONIC); }
723 "ORA" { yylval.mnemonic = ORA_MNEMONIC; return(MNEMONIC); }
724 "PHA" { yylval.mnemonic = PHA_MNEMONIC; return(MNEMONIC); }
725 "PHP" { yylval.mnemonic = PHP_MNEMONIC; return(MNEMONIC); }
726 "PLA" { yylval.mnemonic = PLA_MNEMONIC; return(MNEMONIC); }
727 "PLP" { yylval.mnemonic = PLP_MNEMONIC; return(MNEMONIC); }
728 "ROL" { yylval.mnemonic = ROL_MNEMONIC; return(MNEMONIC); }
729 "ROR" { yylval.mnemonic = ROR_MNEMONIC; return(MNEMONIC); }
730 "RTI" { yylval.mnemonic = RTI_MNEMONIC; return(MNEMONIC); }
731 "RTS" { yylval.mnemonic = RTS_MNEMONIC; return(MNEMONIC); }
732 "SBC" { yylval.mnemonic = SBC_MNEMONIC; return(MNEMONIC); }
733 "SEC" { yylval.mnemonic = SEC_MNEMONIC; return(MNEMONIC); }
734 "SED" { yylval.mnemonic = SED_MNEMONIC; return(MNEMONIC); }
735 "SEI" { yylval.mnemonic = SEI_MNEMONIC; return(MNEMONIC); }
736 "STA" { yylval.mnemonic = STA_MNEMONIC; return(MNEMONIC); }
737 "STX" { yylval.mnemonic = STX_MNEMONIC; return(MNEMONIC); }
738 "STY" { yylval.mnemonic = STY_MNEMONIC; return(MNEMONIC); }
739 "TAX" { yylval.mnemonic = TAX_MNEMONIC; return(MNEMONIC); }
740 "TAY" { yylval.mnemonic = TAY_MNEMONIC; return(MNEMONIC); }
741 "TSX" { yylval.mnemonic = TSX_MNEMONIC; return(MNEMONIC); }
742 "TXA" { yylval.mnemonic = TXA_MNEMONIC; return(MNEMONIC); }
743 "TXS" { yylval.mnemonic = TXS_MNEMONIC; return(MNEMONIC); }
744 "TYA" { yylval.mnemonic = TYA_MNEMONIC; return(MNEMONIC); }
748 "MASK" { return(MASK); }
749 "SIZEOF" { return(SIZEOF); }
752 {pragma_prefix}"IF" { return(IF); }
753 {pragma_prefix}"IFDEF" { return(IFDEF); }
754 {pragma_prefix}"IFNDEF" { return(IFNDEF); }
755 {pragma_prefix}"ELSE" { return(ELSE); }
756 {pragma_prefix}"ELIF" { return(ELIF); }
757 {pragma_prefix}"ENDIF" { return(ENDIF); }
758 {pragma_prefix}"MACRO" { return(MACRO); }
759 {pragma_prefix}"END" { return(END); }
760 {pragma_prefix}"ENDE" { return(ENDE); }
761 {pragma_prefix}"ENDM" { return(ENDM); }
762 {pragma_prefix}"ENDP" { return(ENDP); }
763 {pragma_prefix}"ENDS" { return(ENDS); }
764 {pragma_prefix}"EQU" { return(EQU); }
767 {pragma_prefix}"INCSRC" { return(INCSRC); }
768 {pragma_prefix}"INCBIN" { return(INCBIN); }
769 {pragma_prefix}"ALIGN" { return(ALIGN); }
770 {pragma_prefix}"PUBLIC" { return(PUBLIC); }
771 {pragma_prefix}"EXTRN" { return(EXTRN); }
774 {pragma_prefix}"TAG" { return(TAG); }
775 {pragma_prefix}"TYPE" { return(TAG); }
776 {pragma_prefix}"LABEL" { return(_LABEL_); }
779 {pragma_prefix}"PAD" { return(DSB); }
780 {pragma_prefix}"DB" { return(BYTE); }
781 {pragma_prefix}"BYTE" { return(BYTE); }
782 {pragma_prefix}"CHAR" { return(CHAR); }
783 {pragma_prefix}"ASC" { return(CHAR); }
784 {pragma_prefix}"DW" { return(WORD); }
785 {pragma_prefix}"WORD" { return(WORD); }
786 {pragma_prefix}"DD" { return(DWORD); }
787 {pragma_prefix}"DWORD" { return(DWORD); }
788 {pragma_prefix}"DSB" { return(DSB); }
789 {pragma_prefix}"DSW" { return(DSW); }
790 {pragma_prefix}"DSD" { return(DSD); }
793 "@@@@"{local_id} { yylval.ident = yytext; return(LOCAL_ID); }
794 {identifier} { yylval.ident = yytext; return(IDENTIFIER); }
795 {string_literal} { yytext[yyleng-1] = '\0'; yylval.string = &yytext[1]; return(STRING_LITERAL); }
796 "+"{2,8} { yylval.ident = yytext; return(FORWARD_BRANCH); }
797 "-"{2,8} { yylval.ident = yytext; return(BACKWARD_BRANCH); }
798 "::" { return(SCOPE_OP); }
800 \n { LOCATION_LINES (yylloc, yyleng); LOCATION_STEP (yylloc); return('\n'); }
805 "(" { return( yyparswap ? '[' : '(' ); }
806 ")" { return( yyparswap ? ']' : ')' ); }
807 "[" { return( yyparswap ? '(' : '[' ); }
808 "]" { return( yyparswap ? ')' : ']'); }
826 "@@" { return('@@'); }
827 . { yyerror("Skipping invalid character(s)"); LOCATION_STEP (yylloc); }
830 char *name; /* Name of the file */
831 YY_BUFFER_STATE buf; /* flex input buffer */
832 YYLTYPE loc; /* Current position in file */
833 FILE *fp; /* File handle */
836 LOCATION_RESET(yylloc);
839 /* Discard of buffer that has been scanned */
840 yy_delete_buffer(YY_CURRENT_BUFFER);
841 /* Close current file */
843 /* Resume scanning of previous buffer, if any */
844 if (file_stack_ptr > 0) {
847 /* Restore location */
849 /* Resume scanning from this buffer */
850 yy_switch_to_buffer(FTOS().buf);
851 /* Not end of all input. */
855 /* We have reached end of all input. */
861 /* Check for stack overflow */
862 if (file_stack_ptr == FILE_STACK_SIZE-1) {
863 /* Error, stack overflow */
866 /* Attempt to open file */
867 fp = fopen(filename, "rt");
869 /* Save position in current file */
871 /* Push the new file */
873 FTOS().name = filename;
874 FTOS().buf = yy_create_buffer(fp, YY_BUF_SIZE);
876 /* Reset file location */
878 /* Resume scanning from the new buffer */
879 yy_switch_to_buffer(FTOS().buf);
884 /* Error, couldn't open file */
890 yyparswap = swap_parens;
891 /* Attempt to open the given file */
892 fp = fopen(filename, "rt");
896 FTOS().name = filename;
897 FTOS().buf = yy_create_buffer(fp, YY_BUF_SIZE);
899 /* Reset file location */
901 /* Use the new buffer */
902 yy_switch_to_buffer(FTOS().buf);
907 /* Couldn't open file */
916 /* Print line of form: file:pos:message */
917 fprintf(stderr, "%s:", yy_current_filename());
918 LOCATION_PRINT(stderr, yylloc);
919 fprintf(stderr, ": %s\n", s);
920 /* Print include-trace */
921 for (i=file_stack_ptr-1; i>=0; i--) {
922 fprintf(stderr, "(%s:", file_stack[i].name);
923 LOCATION_PRINT(stderr, file_stack[i].loc);
924 fprintf(stderr, ")\n");
929 /* Kill the ':' at the end */
930 yytext[strlen(yytext)-1] = 0;
931 /* Skip the whitespace, if any */
933 while ((yytext[start] == ' ') || (yytext[start] == '\t')) start++;
934 return &yytext[start];
945 * $Id: scanner.l,v 1.7 2004/12/16 13:22:08 kenth Exp kenth $
953 @added DEFINE parsing
958 * $Id: scanner.l,v 1.6 2004/12/14 01:50:33 kenth Exp kenth $
972 * $Id: scanner.l,v 1.5 2004/12/11 02:12:32 kenth Exp kenth $
985 * $Id: scanner.l,v 1.4 2004/12/10 22:43:53 kenth Exp kenth $
989 identifier [A-Z_][A-Z0-9_]{1,255}
997 @removed FILE_PATH recognition: ".db <a, >b" is erronously parsed otherwise
1002 * $Id: scanner.l,v 1.3 2004/12/09 11:15:28 kenth Exp kenth $
1010 @bugfix: close file handle
1011 added: "WARNING", "ERROR" recognition
1016 * $Id: scanner.l,v 1.2 2004/12/06 05:06:29 kenth Exp kenth $
1021 {file_path} { yylval.string = yytext; return(FILE_PATH); }
1032 * $Id: scanner.l,v 1.1 2004/06/30 07:56:59 kenth Exp kenth $
1054 identifier [A-Z_][A-Z0-9_]{0,255}
1055 local_id [0-9A-Z_]{1,256}
1061 {pragma_prefix}"DB" { yylval.datatype = BYTE_DATATYPE; return(DATATYPE); }
1062 {pragma_prefix}"BYTE" { yylval.datatype = BYTE_DATATYPE; return(DATATYPE); }
1063 {pragma_prefix}"CHAR" { yylval.datatype = CHAR_DATATYPE; return(DATATYPE); }
1064 {pragma_prefix}"ASC" { yylval.datatype = CHAR_DATATYPE; return(DATATYPE); }
1065 {pragma_prefix}"DW" { yylval.datatype = WORD_DATATYPE; return(DATATYPE); }
1066 {pragma_prefix}"WORD" { yylval.datatype = WORD_DATATYPE; return(DATATYPE); }
1067 {pragma_prefix}"DD" { yylval.datatype = DWORD_DATATYPE; return(DATATYPE); }
1068 {pragma_prefix}"DWORD" { yylval.datatype = DWORD_DATATYPE; return(DATATYPE); }
1069 {pragma_prefix}"DSB" { yylval.datatype = BYTE_DATATYPE; return(STORAGE); }
1070 {pragma_prefix}"DSW" { yylval.datatype = WORD_DATATYPE; return(STORAGE); }
1071 {pragma_prefix}"DSD" { yylval.datatype = DWORD_DATATYPE; return(STORAGE); }
1075 "(" { return('('); }
1076 ")" { return(')'); }
1077 "[" { return('['); }
1078 "]" { return(']'); }
1082 int yybegin(char *filename)