Made separate tokens for JUMP_ABS and JUMP_STACK
Makes more sense, don't need to fiddle around with strings as much in the parser due to this!
This commit is contained in:
21
asm/lexer.c
21
asm/lexer.c
@@ -86,8 +86,10 @@ const char *token_type_as_cstr(token_type_t type)
|
|||||||
return "MULT";
|
return "MULT";
|
||||||
case TOKEN_PRINT:
|
case TOKEN_PRINT:
|
||||||
return "PRINT";
|
return "PRINT";
|
||||||
case TOKEN_JUMP:
|
case TOKEN_JUMP_ABS:
|
||||||
return "JUMP";
|
return "JUMP_ABS";
|
||||||
|
case TOKEN_JUMP_STACK:
|
||||||
|
return "JUMP_STACK";
|
||||||
case TOKEN_JUMP_IF:
|
case TOKEN_JUMP_IF:
|
||||||
return "JUMP_IF";
|
return "JUMP_IF";
|
||||||
case TOKEN_SYMBOL:
|
case TOKEN_SYMBOL:
|
||||||
@@ -293,16 +295,21 @@ token_t tokenise_symbol(buffer_t *buffer, size_t *column)
|
|||||||
offset = 5;
|
offset = 5;
|
||||||
type = TOKEN_PRINT;
|
type = TOKEN_PRINT;
|
||||||
}
|
}
|
||||||
|
else if (sym_size >= 8 && strncmp(opcode, "JUMP.ABS", 8) == 0)
|
||||||
|
{
|
||||||
|
offset = 8;
|
||||||
|
type = TOKEN_JUMP_ABS;
|
||||||
|
}
|
||||||
|
else if (sym_size >= 10 && strncmp(opcode, "JUMP.STACK", 10) == 0)
|
||||||
|
{
|
||||||
|
offset = 10;
|
||||||
|
type = TOKEN_JUMP_STACK;
|
||||||
|
}
|
||||||
else if (sym_size >= 7 && strncmp(opcode, "JUMP.IF", 7) == 0)
|
else if (sym_size >= 7 && strncmp(opcode, "JUMP.IF", 7) == 0)
|
||||||
{
|
{
|
||||||
offset = 7;
|
offset = 7;
|
||||||
type = TOKEN_JUMP_IF;
|
type = TOKEN_JUMP_IF;
|
||||||
}
|
}
|
||||||
else if (sym_size >= 4 && strncmp(opcode, "JUMP", 4) == 0)
|
|
||||||
{
|
|
||||||
offset = 4;
|
|
||||||
type = TOKEN_JUMP;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
is_opcode = false;
|
is_opcode = false;
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ typedef enum TokenType
|
|||||||
TOKEN_SUB,
|
TOKEN_SUB,
|
||||||
TOKEN_MULT,
|
TOKEN_MULT,
|
||||||
TOKEN_PRINT,
|
TOKEN_PRINT,
|
||||||
TOKEN_JUMP,
|
TOKEN_JUMP_ABS,
|
||||||
|
TOKEN_JUMP_STACK,
|
||||||
TOKEN_JUMP_IF,
|
TOKEN_JUMP_IF,
|
||||||
TOKEN_SYMBOL,
|
TOKEN_SYMBOL,
|
||||||
} token_type_t;
|
} token_type_t;
|
||||||
|
|||||||
24
asm/parser.c
24
asm/parser.c
@@ -404,22 +404,16 @@ perr_t parse_next(token_stream_t *stream, presult_t *ret)
|
|||||||
.type = PRES_COMPLETE_RESULT};
|
.type = PRES_COMPLETE_RESULT};
|
||||||
perr = parse_type_inst(stream, &ret->instruction);
|
perr = parse_type_inst(stream, &ret->instruction);
|
||||||
break;
|
break;
|
||||||
case TOKEN_JUMP: {
|
case TOKEN_JUMP_ABS:
|
||||||
if (token.str_size == 4 && strncmp(token.str, ".ABS", 4) == 0)
|
*ret = (presult_t){.instruction = INST_JUMP_ABS(0)};
|
||||||
{
|
++stream->used;
|
||||||
*ret = (presult_t){.instruction = INST_JUMP_ABS(0)};
|
if (stream->used >= stream->available)
|
||||||
++stream->used;
|
return PERR_EXPECTED_OPERAND;
|
||||||
if (stream->used >= stream->available)
|
return parse_word_label_or_relative(stream, ret);
|
||||||
return PERR_EXPECTED_OPERAND;
|
case TOKEN_JUMP_STACK:
|
||||||
return parse_word_label_or_relative(stream, ret);
|
*ret = (presult_t){.instruction = INST_JUMP_STACK,
|
||||||
}
|
.type = PRES_COMPLETE_RESULT};
|
||||||
else if (token.str_size == 6 && strncmp(token.str, ".STACK", 6) == 0)
|
|
||||||
*ret = (presult_t){.instruction = INST_JUMP_STACK,
|
|
||||||
.type = PRES_COMPLETE_RESULT};
|
|
||||||
else
|
|
||||||
return PERR_UNKNOWN_OPERATOR;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case TOKEN_JUMP_IF: {
|
case TOKEN_JUMP_IF: {
|
||||||
*ret = (presult_t){.instruction = INST_JUMP_IF(BYTE, 0)};
|
*ret = (presult_t){.instruction = INST_JUMP_IF(BYTE, 0)};
|
||||||
return parse_jump_inst_operand(stream, ret);
|
return parse_jump_inst_operand(stream, ret);
|
||||||
|
|||||||
Reference in New Issue
Block a user