From a065ac322b9c171f6febc16cf0fb8b2ea1e5f87e Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 2 Nov 1994 22:09:53 +0000 Subject: [PATCH] Make the scalar type a free parameter of the implementation. --- cupl.h | 10 +++++++++- cupl.l | 9 +++++---- interpret.c | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cupl.h b/cupl.h index 6bdc971..728dc62 100644 --- 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 9a7f1ed..8504ff8 100644 --- 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) diff --git a/interpret.c b/interpret.c index e9f9c2f..503bccf 100644 --- a/interpret.c +++ b/interpret.c @@ -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; -- 2.43.0