From fcc85aa5f5c8142dc2160fea4fcbb148a98b096a Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Sun, 10 May 2015 17:32:44 +0200 Subject: [PATCH] Fix .asciz ... where an overzealous parsing wants to parse too much of the remaining text In particular, the example was .asciz // where it tried to make a division betweem and the delimited string //. --- assemble.c | 2 +- parse.c | 23 +++++++++++++++++++++++ parse.h | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/assemble.c b/assemble.c index 5ea341c..72bb9ad 100644 --- a/assemble.c +++ b/assemble.c @@ -1077,7 +1077,7 @@ static int assemble( cp = skipwhite(cp); if (*cp == '<' || *cp == '^') { /* A byte value */ - value = parse_expr(cp, 0); + value = parse_unary_expr(cp, 0); cp = value->cp; store_value(stack, tr, 1, value); free_tree(value); diff --git a/parse.c b/parse.c index 91656f6..2409ac4 100644 --- a/parse.c +++ b/parse.c @@ -863,3 +863,26 @@ EX_TREE *parse_expr( return value; } + +/* + parse_unary_expr It parses and evaluates + an arithmetic expression but only a unary: (op)value or . + In particular, it doesn't try to divide in /SOH/. +*/ + +EX_TREE *parse_unary_expr( + char *cp, + int undef) +{ + EX_TREE *expr; + EX_TREE *value; + + expr = parse_unary(cp); /* Parse into a tree */ + value = evaluate(expr, undef); /* Perform the arithmetic */ + value->cp = expr->cp; /* Pointer to end of text is part of + the rootmost node */ + free_tree(expr); /* Discard parse in favor of + evaluation */ + + return value; +} diff --git a/parse.h b/parse.h index 25ae6a6..55a4add 100644 --- a/parse.h +++ b/parse.h @@ -35,6 +35,9 @@ int get_mode( EX_TREE *parse_expr( char *cp, int undef); +EX_TREE *parse_unary_expr( + char *cp, + int undef); int parse_float( char *cp, char **endp,