1
0
mirror of https://github.com/brouhaha/dis6502.git synced 2024-06-07 13:39:33 +00:00
dis6502/lex.l

75 lines
1.1 KiB
Plaintext
Raw Normal View History

2000-04-27 23:29:28 +00:00
%{
#undef ECHO
#include <stdint.h>
2003-09-12 08:06:16 +00:00
#include <string.h>
2000-04-27 23:29:28 +00:00
#include "dis.h"
int lineno = 0;
char *strcpy();
%}
2003-09-12 08:06:16 +00:00
%option nounput
2000-04-27 23:29:28 +00:00
digit [0-9]
hexdigit [0-9a-fA-F]
alpha [a-zA-Z]
alphanum [0-9a-zA-Z_]
%%
[ \t] { ; }
[\n] { lineno++; return '\n'; }
\.[Ee][Qq][Uu] { return EQ; }
\.[Ee][Qq] { return EQ; }
\.[Ll][Ii] { return LI; }
\.[Tt][Rr][Aa][Cc][Ee] { return TSTART; }
\.[Ss][Tt][Oo][Pp] { return TSTOP; }
\.[Rr][Tt][Ss][Tt][Aa][Bb] { return TRTSTAB; }
2000-11-21 02:16:32 +00:00
\.[Jj][Tt][Aa][Bb]2 { return TJTAB2; }
2000-04-27 23:29:28 +00:00
{digit}+ {
(void)sscanf(yytext, "%d", &token.ival);
return NUMBER;
}
\${hexdigit}+ {
(void)sscanf(yytext+1, "%x", &token.ival);
return NUMBER;
}
{alpha}{alphanum}* {
token.sval = emalloc((unsigned) strlen(yytext)+1);
(void)strcpy((char *)token.sval, (char *)yytext);
return NAME;
}
\*.* {
return COMMENT;
}
\;.* {
return COMMENT;
}
. { return yytext[0]; }
%%
char *
emalloc(n)
unsigned n;
{
char *ptr, *malloc();
if ((ptr = malloc(n)) == (char *) 0) {
(void) fprintf(stderr,"out of core");
exit(1);
}
return ptr;
}