Skip to content

Commit

Permalink
Update asmexpr.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
ogamespec committed Sep 15, 2023
1 parent 92c442a commit 108972f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Tools/Breakasm/asmexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ static node_t* addnode(std::list<node_t*>& tree, token_t* token, int depth)
}

// executing the tree (semantic analysis)
static node_t * evaluate (std::list<node_t*>& tree, node_t * expr, long *lvalue, bool quiet)
static node_t * evaluate (std::list<node_t*>& tree, node_t * expr, long *lvalue, bool quiet, bool& syntax_error)
{
node_t * curr;
long rvalue = 0, mvalue;
Expand All @@ -379,6 +379,7 @@ static node_t * evaluate (std::list<node_t*>& tree, node_t * expr, long *lvalue,
token = curr->token;
if ( token->type == TOKEN_OP && isunary(token->op) ) {
if (curr->rvalue == NULL) {
syntax_error = true;
if (!quiet) {
printf("Missing identifier\n");
errors++;
Expand All @@ -401,7 +402,7 @@ static node_t * evaluate (std::list<node_t*>& tree, node_t * expr, long *lvalue,

if ( curr->depth > expr->depth ) { // nested expression
if (debug) printf ( "SUBEVAL " );
curr = evaluate (tree, curr, &mvalue, quiet);
curr = evaluate (tree, curr, &mvalue, quiet, syntax_error);
//printf ( "SUB LVALUE : %i\n", mvalue.num.value );
}
else if ( token->type == TOKEN_IDENT) {
Expand All @@ -413,10 +414,11 @@ static node_t * evaluate (std::list<node_t*>& tree, node_t * expr, long *lvalue,
}
else {
label_s* label = label_lookup(token->string);
if (label && label->orig != UNDEF) {
if (label && label->orig != UNDEF && !label->composite) {
mvalue = label->orig;
}
else {
syntax_error = true;
if (!quiet) {
printf("Undefined identifier: %s", token->string);
errors++;
Expand Down Expand Up @@ -468,6 +470,7 @@ static node_t * evaluate (std::list<node_t*>& tree, node_t * expr, long *lvalue,
else rvalue = mvalue;
}
else {
syntax_error = true;
if (!quiet) {
printf("Identifier required\n");
errors++;
Expand Down Expand Up @@ -583,8 +586,12 @@ long eval_expr(char* text, bool debug, bool quiet)
// Execute the tree

long result = 0;
bool syntax_error = false;
if (root) {
evaluate(tree.nodes, root->rvalue->rvalue, &result, quiet);
evaluate(tree.nodes, root->rvalue->rvalue, &result, quiet, syntax_error);
}
if (syntax_error) {
result = 0;
}

if (debug)
Expand Down

0 comments on commit 108972f

Please sign in to comment.