Negative literal integers work properly now..

Sat, 28 Jul 2012 17:57:37 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 28 Jul 2012 17:57:37 +0300
changeset 35
3d3f6ed40171
parent 34
0a9a5902beaa
child 36
a8838b5f1213

Negative literal integers work properly now..

commands.def file | annotate | diff | comparison | revisions
parser.cxx file | annotate | diff | comparison | revisions
scriptreader.cxx file | annotate | diff | comparison | revisions
scriptreader.h file | annotate | diff | comparison | revisions
--- a/commands.def	Sat Jul 28 17:41:24 2012 +0300
+++ b/commands.def	Sat Jul 28 17:57:37 2012 +0300
@@ -1,3 +1,8 @@
+/* This file defines the commands botc will treat as valid.
+ * Do not edit unless you know what you are doing!
+ *
+ * Syntax: number:name:returntype:numargs:maxargs[:argumentlist]
+ */
 0:changestate:void:1:1:str(statename)
 1:delay:void:1:1:int(tics)
 2:rand:int:2:2:int(a):int(b)
--- a/parser.cxx	Sat Jul 28 17:41:24 2012 +0300
+++ b/parser.cxx	Sat Jul 28 17:57:37 2012 +0300
@@ -437,16 +437,22 @@
 			ParserError ("bad syntax");
 			break;
 		case TYPE_INT: {
-			if (!token.isnumber ())
+			printf ("value is an integer literal\n");
+			/* if (!token.isnumber ())
 				ParserError ("expected an integer, got `%s`", token.chars());
+			*/
+			MustNumber (true);
+			printf ("literal is `%s` = %d\n", token.chars(), atoi (token.chars()));
 			
 			// All values are written unsigned - thus we need to write the value's
 			// absolute value, followed by an unary minus if it was negative.
 			b->Write<byte> (DH_PUSHNUMBER);
 			long v = atoi (token.chars ());
 			b->Write<byte> (static_cast<byte> (abs (v)));
-			if (v < 0)
+			if (v < 0) {
+				printf ("%ld is negative, write abs value %d and unary minus\n", v, abs(v));
 				b->Write<byte> (DH_UNARYMINUS);
+			}
 			break;
 		}
 		case TYPE_STRING:
--- a/scriptreader.cxx	Sat Jul 28 17:41:24 2012 +0300
+++ b/scriptreader.cxx	Sat Jul 28 17:57:37 2012 +0300
@@ -356,9 +356,10 @@
 	token = string;
 }
 
-void ScriptReader::MustNumber () {
+void ScriptReader::MustNumber (bool fromthis) {
 	str num;
-	MustNext ();
+	if (!fromthis)
+		MustNext ();
 	num += token;
 	
 	// Cater for a possible minus sign, since it
@@ -370,6 +371,8 @@
 	
 	if (!num.isnumber())
 		ParserError ("expected a number, got `%s`", num.chars());
+	
+	token = num;
 }
 
 void ScriptReader::MustBool () {
--- a/scriptreader.h	Sat Jul 28 17:41:24 2012 +0300
+++ b/scriptreader.h	Sat Jul 28 17:57:37 2012 +0300
@@ -81,7 +81,7 @@
 	void MustNext (const char* c = "");
 	void MustThis (const char* c);
 	void MustString (bool gotquote = false);
-	void MustNumber ();
+	void MustNumber (bool fromthis = false);
 	void MustBool ();
 	void MustValue (int type);
 	bool BoolValue ();

mercurial