Ignore underscores when extracting value of integer.
authorMario de Sousa <msousa@fe.up.pt>
Thu, 25 Aug 2011 17:55:48 +0100
changeset 366 1aeb29ee9381
parent 365 84ad67170c11
child 367 6d94128ba5ad
Ignore underscores when extracting value of integer.
absyntax_utils/absyntax_utils.cc
--- a/absyntax_utils/absyntax_utils.cc	Tue Aug 23 17:18:37 2011 +0100
+++ b/absyntax_utils/absyntax_utils.cc	Thu Aug 25 17:55:48 2011 +0100
@@ -50,6 +50,7 @@
 #include <typeinfo>
 #include <list>
 #include <strings.h>
+#include <string.h>  /* required for strlen() */
 #include <stdlib.h>  /* required for atoi() */
 
 #include "../util/symtable.hh"
@@ -98,13 +99,23 @@
 /* extract the value of an integer from an integer_c object !! */
 /* NOTE: it must ignore underscores! */
 int extract_integer(symbol_c *sym) {
-  integer_c *integer = dynamic_cast<integer_c *>(sym);  
-  if (integer == NULL) ERROR;
-  
-  return atoi(integer->value);
+  std::string str = "";
+  integer_c *integer;
+  neg_integer_c * neg_integer;
+
+  if ((neg_integer = dynamic_cast<neg_integer_c *>(sym)) != NULL)
+    return - extract_integer((integer_c *)neg_integer->exp);
+  
+  if ((integer = dynamic_cast<integer_c *>(sym)) == NULL) ERROR;
+
+  for(unsigned int i = 0; i < strlen(integer->value); i++)
+    if (integer->value[i] != '_')  str += integer->value[i];
+
+  return atoi(str.c_str());
 }
 
 
+
 /***********************************************************************/
 /***********************************************************************/
 /***********************************************************************/