summaryrefslogtreecommitdiff
path: root/lexer.c
diff options
context:
space:
mode:
Diffstat (limited to 'lexer.c')
-rw-r--r--lexer.c115
1 files changed, 35 insertions, 80 deletions
diff --git a/lexer.c b/lexer.c
index a7d50ec..5a79325 100644
--- a/lexer.c
+++ b/lexer.c
@@ -428,6 +428,7 @@ uint64_t lex(char *str, struct line *l, uint64_t address, uint8_t dbg) {
uint8_t k = 0;
uint8_t rs = 0;
uint8_t isop = 0;
+ uint8_t base = 0;
int num = 0;
int isch = 0;
int16_t ln = -1;
@@ -471,6 +472,7 @@ uint64_t lex(char *str, struct line *l, uint64_t address, uint8_t dbg) {
l[line].aop = 0;
l[line].addr = address;
while (str[i] != '\0' && str[i] != '\n') {
+ base = 0;
space = 0;
tab = 0;
while (isspace(str[i+j])) {
@@ -569,75 +571,38 @@ uint64_t lex(char *str, struct line *l, uint64_t address, uint8_t dbg) {
l[line].am = IMM;
lex_type = TOK_IMM;
break;
- case '$':
+ if (str[i] == '$') {
+ case '$': base = 16;
+ } else if (str[i] == '%') {
+ case '%': base = 2;
+ }
i++;
while (isxdigit(str[i]) && (str[i] != '\0' && str[i] != '\n')) {
lexeme[j++] = str[i++];
}
lexeme[j] = '\0';
switch (lex_type) {
- case TOK_SYM:
- l[line].op = strtoull(lexeme, NULL, 16);
- mksymbol(sym, l[line].op, 1, 0, 0, dbg);
- l[line].sym = get_symid(sym, address, line, dbg);
- isfixup += (l[line].sym == 0xFFFF);
- if (dbg) {
- printf("lex(): isfixup: %u\n", isfixup);
- }
- l[line].opbase = BASE_HEX;
- break;
- case TOK_PLUS:
- case TOK_MINUS:
- l[line].aop = strtoull(lexeme, NULL, 16);
- l[line].aopbase = BASE_HEX;
- break;
default:
if (l[line].cm != 0xFF) {
- l[line].aop = strtoull(lexeme, NULL, 16);
- l[line].aopbase = BASE_HEX;
+ case TOK_PLUS :
+ case TOK_MINUS: l[line].aop = strtoull(lexeme, NULL, base);
+ l[line].aopbase = (base & 16) ? TOK_HEX : TOK_BIN;
} else {
- l[line].op = strtoull(lexeme, NULL, 16);
- l[line].opbase = BASE_HEX;
+ case TOK_SYM: l[line].op = strtoull(lexeme, NULL, base);
+ l[line].opbase = (base & 16) ? TOK_HEX : TOK_BIN;
}
- break;
-
- }
- lex_type = TOK_HEX;
- break;
- case '%':
- i++;
- while (isdigit(str[i]) && (str[i] != '\0' && str[i] != '\n')) {
- lexeme[j++] = str[i++];
- }
- lexeme[j] = '\0';
- switch (lex_type) {
- case TOK_SYM:
- l[line].op = strtoull(lexeme, NULL, 2);
- mksymbol(sym, l[line].op, 1, 0, 0, dbg);
- l[line].sym = get_symid(sym, address, line, dbg);
- isfixup += (l[line].sym == 0xFFFF);
- if (dbg) {
- printf("lex(): isfixup: %u\n", isfixup);
- }
- l[line].opbase = BASE_BIN;
- break;
- case TOK_PLUS:
- case TOK_MINUS:
- l[line].aop = strtoull(lexeme, NULL, 2);
- l[line].aopbase = BASE_BIN;
- break;
- default:
- if (l[lineidx].cm != 0xFF) {
- l[line].aop = strtoull(lexeme, NULL, 2);
- l[line].aopbase = BASE_BIN;
- } else {
- l[line].op = strtoull(lexeme, NULL, 2);
- l[line].opbase = BASE_BIN;
+ if (lex_type == TOK_SYM) {
+ mksymbol(sym, l[line].op, 1, 0, 0, dbg);
+ l[line].sym = get_symid(sym, address, line, dbg);
+ isfixup += (l[line].sym == 0xFFFF);
+ if (dbg) {
+ printf("lex(): isfixup: %u\n", isfixup);
+ }
}
break;
-
}
- lex_type = TOK_BIN;
+
+ lex_type = (base & 16) ? TOK_HEX : TOK_BIN;
break;
case '+':
lexeme[j] = '+';
@@ -825,34 +790,24 @@ uint64_t lex(char *str, struct line *l, uint64_t address, uint8_t dbg) {
if (lexeme[k] == '\0') {
if (num) {
switch (lex_type) {
- case TOK_SYM:
- l[line].op = strtoull(lexeme, NULL, 10);
- mksymbol(sym, l[line].op, 1, 0, 0, dbg);
- if (isfixup) {
- isfixup = reslv_fixups(l, dbg);
- }
- l[line].sym = get_symid(sym, address, line, dbg);
- isfixup += l[line].sym == 0xFFFF;
- if (dbg) {
- printf("lex(): isfixup: %u\n", isfixup);
- }
- l[line].opbase = BASE_DEC;
- break;
- case TOK_PLUS:
- case TOK_MINUS:
- l[line].aop = strtoull(lexeme, NULL, 10);
- l[line].aopbase = BASE_DEC;
- break;
default:
- if (l[lineidx].cm != 0xFF) {
- l[line].aop = strtoull(lexeme, NULL, 10);
- l[line].aopbase = BASE_DEC;
+ if (l[line].cm != 0xFF) {
+ case TOK_PLUS :
+ case TOK_MINUS: l[line].aop = strtoull(lexeme, NULL, 10);
+ l[line].aopbase = TOK_DEC;
} else {
- l[line].op = strtoull(lexeme, NULL, 10);
- l[line].opbase = BASE_DEC;
+ case TOK_SYM: l[line].op = strtoull(lexeme, NULL, 10);
+ l[line].opbase = TOK_DEC;
+ }
+ if (lex_type == TOK_SYM) {
+ mksymbol(sym, l[line].op, 1, 0, 0, dbg);
+ l[line].sym = get_symid(sym, address, line, dbg);
+ isfixup += (l[line].sym == 0xFFFF);
+ if (dbg) {
+ printf("lex(): isfixup: %u\n", isfixup);
+ }
}
break;
-
}
lex_type = TOK_DEC;
} else if (isch && lex_type != TOK_HEX && lex_type != TOK_BIN) {