+int constant_to_int(constant_t*c)
+{
+ switch(c->type) {
+ case CONSTANT_INT: return c->i;
+ case CONSTANT_UINT: return (int)c->u;
+ case CONSTANT_FLOAT: return c->f;
+ case CONSTANT_TRUE: return 1;
+ case CONSTANT_FALSE: return 0;
+ case CONSTANT_STRING: return atoi(c->s->str);
+ default: syntaxerror("can't convert this constant to an integer");
+ }
+}
+
+double constant_to_float(constant_t*c)
+{
+ switch(c->type) {
+ case CONSTANT_INT: return (double)c->i;
+ case CONSTANT_UINT: return (double)c->u;
+ case CONSTANT_FLOAT: return c->f;
+ case CONSTANT_TRUE: return (double)1;
+ case CONSTANT_FALSE: return (double)0;
+ case CONSTANT_STRING: return atof(c->s->str);
+ default: syntaxerror("can't convert this constant to a float");
+ }
+}
+