changeset 44:1bff302e62a3

Accept negative sign after base prefix
author lost@l-w.ca
date Mon, 04 Apr 2011 18:05:18 -0600
parents 18b49cf10ae9
children c42d6dc7df68
files lwasm/lwasm.c
diffstat 1 files changed, 29 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/lwasm.c	Mon Apr 04 17:55:08 2011 -0600
+++ b/lwasm/lwasm.c	Mon Apr 04 18:05:18 2011 -0600
@@ -278,6 +278,7 @@
 lw_expr_t lwasm_parse_term(char **p, void *priv)
 {
 	asmstate_t *as = priv;
+	int neg = 1;
 	int val;
 	
 	if (!**p)
@@ -339,6 +340,12 @@
 		// decimal constant
 		int v = 0;
 		(*p)++;
+		
+		if (**p == '-')
+		{
+			(*p)++;
+			neg = -1;
+		}
 
 		if (!strchr("0123456789", **p))
 			return NULL;
@@ -348,7 +355,7 @@
 			val = val * 10 + (**p - '0');
 			(*p)++;
 		}
-		return lw_expr_build(lw_expr_type_int, v);
+		return lw_expr_build(lw_expr_type_int, v * neg);
 	}
 
 	if (**p == '%')
@@ -357,6 +364,12 @@
 		int v = 0;
 		(*p)++;
 
+		if (**p == '-')
+		{
+			(*p)++;
+			neg = -1;
+		}
+
 		if (**p != '0' && **p != '1')
 			return NULL;
 
@@ -365,7 +378,7 @@
 			val = val * 2 + (**p - '0');
 			(*p)++;
 		}
-		return lw_expr_build(lw_expr_type_int, v);
+		return lw_expr_build(lw_expr_type_int, v * neg);
 	}
 	
 	if (**p == '$')
@@ -373,6 +386,12 @@
 		// hexadecimal constant
 		int v = 0, v2;
 		(*p)++;
+		if (**p == '-')
+		{
+			(*p)++;
+			neg = -1;
+		}
+
 		if (!strchr("0123456789abcdefABCDEF", **p))
 			return NULL;
 
@@ -384,7 +403,7 @@
 			v = v * 16 + v2;
 			(*p)++;
 		}
-		return lw_expr_build(lw_expr_type_int, v);
+		return lw_expr_build(lw_expr_type_int, v * neg);
 	}
 	
 	if (**p == '0' && (*((*p)+1) == 'x' || *((*p)+1) == 'X'))
@@ -412,6 +431,12 @@
 		// octal constant
 		int v = 0;
 		(*p)++;
+		if (**p == '-')
+		{
+			(*p)++;
+			neg = -1;
+		}
+
 
 		if (!strchr("01234567", **p))
 			return NULL;
@@ -421,7 +446,7 @@
 			v = v * 8 + (**p - '0');
 			(*p)++;
 		}
-		return lw_expr_build(lw_expr_type_int, v);
+		return lw_expr_build(lw_expr_type_int, v * neg);
 	}