changeset 194:0d916bcebb90

First pass at allowing symbols starting with digits but containing $
author lost
date Sun, 22 Mar 2009 17:50:42 +0000
parents 716879fc6790
children 383caf808674
files lwasm/expr.c
diffstat 1 files changed, 26 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/expr.c	Sun Mar 22 17:25:19 2009 +0000
+++ b/lwasm/expr.c	Sun Mar 22 17:50:42 2009 +0000
@@ -284,7 +284,7 @@
 	
 	/*
 		- a symbol will be a string of characters introduced by a letter, ".",
-		  "_" but NOT a number
+		  "_" but NOT a number OR it may start with a digit if it contains a $
 		- a decimal constant will consist of only digits, optionally prefixed
 		  with "&"
 		- a binary constant will consist of only 0s and 1s either prefixed with %
@@ -423,32 +423,42 @@
 	}
 
 	// symbol or bare decimal or suffix identified constant here
-	// all numbers will start with a digit at this point
-	if (**p < '0' || **p > '9')
+	
+	// find the end of a potential symbol
+	do
 	{
 		int l = 0;
 		char *sb;
+		int havedol = 0;
 		
 		// evaluate a symbol here
 		static const char *symchars = "_.$@?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
 		while ((*p)[l] && strchr(symchars, (*p)[l]))
+		{
+			if ((*p)[l] == '$')
+				havedol = 1;
 			l++;
-
+		}
 		if (l == 0)
 			return -1;
 
-		sb = lwasm_alloc(l + 1);
-		sb[l] = '\0';
-		memcpy(sb, *p, l);
-		t = lwasm_expr_term_create_sym(sb);
-		lwasm_expr_stack_push(s, t);
-		lwasm_expr_term_free(t);
-		(*p) += l;
-		debug_message(3, "Symbol: '%s'; (%s)", sb, *p);
-		lwasm_free(sb);
-		return 0;
-	}
-	
+		if (havedol || **p < '0' || **p > '9')
+		{
+			// have a symbol here
+
+			sb = lwasm_alloc(l + 1);
+			sb[l] = '\0';
+			memcpy(sb, *p, l);
+			t = lwasm_expr_term_create_sym(sb);
+			lwasm_expr_stack_push(s, t);
+			lwasm_expr_term_free(t);
+			(*p) += l;
+			debug_message(3, "Symbol: '%s'; (%s)", sb, *p);
+			lwasm_free(sb);
+			return 0;
+		}
+	} while (0);
+
 	if (!**p)
 		return -1;