diff lwasm/expr.c @ 170:bf69160da467

Added ability to use 0x and 0X as prefixes for hexadecimal numbers
author lost
date Sun, 01 Mar 2009 00:53:21 +0000
parents 427e268e876b
children 29ba546ceea0
line wrap: on
line diff
--- a/lwasm/expr.c	Sun Feb 08 03:00:44 2009 +0000
+++ b/lwasm/expr.c	Sun Mar 01 00:53:21 2009 +0000
@@ -382,6 +382,27 @@
 		lwasm_expr_term_free(t);
 		return 0;
 	}
+	else if (**p == '0' && tolower(*(*p + 1)) == 'x')
+	{
+		// "C" style hexadecimal constant
+		int val = 0, val2;
+		
+		(*p)+=2;
+		debug_message(3, "Found \"C\" style prefix hex constant: %s", *p);
+		while (**p && strchr("0123456789ABCDEFabcdef", **p))
+		{
+			val2 = toupper(**p) - '0';
+			if (val2 > 9)
+				val2 -= 7;
+			debug_message(3, "Got char: %c (%d)", **p, val2);
+			val = val * 16 + val2;
+			(*p)++;
+		}
+		t = lwasm_expr_term_create_int(val);
+		lwasm_expr_stack_push(s, t);
+		lwasm_expr_term_free(t);
+		return 0;
+	}
 	// an @ followed by a digit is an octal number
 	// but if it's followed by anything else, it is a symbol
 	else if (**p == '@' && isdigit(*(*p + 1)))
@@ -400,7 +421,7 @@
 		lwasm_expr_term_free(t);
 		return 0;
 	}
-	
+
 	// symbol or bare decimal or suffix identified constant here
 	// all numbers will start with a digit at this point
 	if (**p < '0' || **p > '9')