]> thyrsus.com Git - cupl.git/commitdiff
Make the scalar type a free parameter of the implementation.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 2 Nov 1994 22:09:53 +0000 (22:09 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 2 Nov 1994 22:09:53 +0000 (22:09 +0000)
cupl.h
cupl.l
interpret.c

diff --git a/cupl.h b/cupl.h
index 6bdc971392e5114f80874833ad8bebbff065c395..728dc6230e4b8a4a12a4400b9c64f797bc500fdf 100644 (file)
--- a/cupl.h
+++ b/cupl.h
@@ -24,6 +24,14 @@ typedef int  bool;
 #define FALSE  0
 #endif /* TRUE */
 
+/*
+ * Type used by cupl for representing a CUPL scalar. 
+ * Should be a floating-point type, e.g. float, double, long float, etc.
+ * Also, you must define here the function used to read scalars.
+ */
+typedef double scalar;
+#define atos(s)        atof(s)
+
 /*
  * This is the node structure for parse trees.
  */
@@ -38,7 +46,7 @@ typedef struct edon
            struct edon *right;
        } n;
 
-       double  numval;         /* for numbers */
+       scalar  numval;         /* for numbers */
 
        char    *string;        /* for string literals */
 
diff --git a/cupl.l b/cupl.l
index 9a7f1ed940284044c0d70868519b66aed263c49e..8504ff86410b58950046564d1ccc81ac09df3ebb 100644 (file)
--- a/cupl.l
+++ b/cupl.l
@@ -20,7 +20,7 @@ lvar;
 
 static lvar *idlist;
 
-static node *intern_number(double);
+static node *intern_number(char *);
 static node *intern_identifier(char *);
 static node *intern_string(char *);
 %}
@@ -83,8 +83,8 @@ WRITE         {return(WRITE);}
 "*DATA"                {return(DATA);}
 
 [A-Z][A-Z0-9]* {yylval.node = intern_identifier(yytext); return(IDENTIFIER);}
--?{N}E-?{D}    {yylval.node = intern_number(atof(yytext)); return(NUMBER);}
--?{N}          {yylval.node = intern_number(atof(yytext)); return(NUMBER);}
+-?{N}E-?{D}    {yylval.node = intern_number(yytext); return(NUMBER);}
+-?{N}          {yylval.node = intern_number(yytext); return(NUMBER);}
 '[^']*'                {yylval.node = intern_string(yytext); return(STRING);}
 
 "**"           {return(POWER);}
@@ -135,9 +135,10 @@ static node *intern_identifier(char *str)
     return(new);
 }
 
-static node *intern_number(double numval)
+static node *intern_number(char *str)
 {
     node       *new;
+    scalar      numval = atos(str);    /* see cupl.h */
 
     /* get a node */
     if ((new = (node *)malloc(sizeof(node))) == (node *)NULL)
index e9f9c2f57c5c57a893d273c9ccc254b2ea5e90bd..503bccfc17821afda8ee713739853d867c496128 100644 (file)
@@ -13,13 +13,13 @@ typedef struct rav
        struct 
        {
            int length;
-           double      *parts;
+           scalar      *parts;
        } vector;               /* a vector */
 
        struct 
        {
            int width, depth;
-           double      *parts;
+           scalar      *parts;
        } matrix;               /* a matrix */
 
        char    *string;