absyntax_utils/absyntax_utils.cc
changeset 366 1aeb29ee9381
parent 350 2c3c4dc34979
child 433 1355adcdad58
equal deleted inserted replaced
365:84ad67170c11 366:1aeb29ee9381
    48 #include <iostream>
    48 #include <iostream>
    49 #include <sstream>
    49 #include <sstream>
    50 #include <typeinfo>
    50 #include <typeinfo>
    51 #include <list>
    51 #include <list>
    52 #include <strings.h>
    52 #include <strings.h>
       
    53 #include <string.h>  /* required for strlen() */
    53 #include <stdlib.h>  /* required for atoi() */
    54 #include <stdlib.h>  /* required for atoi() */
    54 
    55 
    55 #include "../util/symtable.hh"
    56 #include "../util/symtable.hh"
    56 #include "../util/dsymtable.hh"
    57 #include "../util/dsymtable.hh"
    57 #include "../absyntax/visitor.hh"
    58 #include "../absyntax/visitor.hh"
    96 
    97 
    97 
    98 
    98 /* extract the value of an integer from an integer_c object !! */
    99 /* extract the value of an integer from an integer_c object !! */
    99 /* NOTE: it must ignore underscores! */
   100 /* NOTE: it must ignore underscores! */
   100 int extract_integer(symbol_c *sym) {
   101 int extract_integer(symbol_c *sym) {
   101   integer_c *integer = dynamic_cast<integer_c *>(sym);  
   102   std::string str = "";
   102   if (integer == NULL) ERROR;
   103   integer_c *integer;
   103   
   104   neg_integer_c * neg_integer;
   104   return atoi(integer->value);
   105 
       
   106   if ((neg_integer = dynamic_cast<neg_integer_c *>(sym)) != NULL)
       
   107     return - extract_integer((integer_c *)neg_integer->exp);
       
   108   
       
   109   if ((integer = dynamic_cast<integer_c *>(sym)) == NULL) ERROR;
       
   110 
       
   111   for(unsigned int i = 0; i < strlen(integer->value); i++)
       
   112     if (integer->value[i] != '_')  str += integer->value[i];
       
   113 
       
   114   return atoi(str.c_str());
   105 }
   115 }
       
   116 
   106 
   117 
   107 
   118 
   108 /***********************************************************************/
   119 /***********************************************************************/
   109 /***********************************************************************/
   120 /***********************************************************************/
   110 /***********************************************************************/
   121 /***********************************************************************/