Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pcalc.y
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ list:
;


junk: IBUILTIN str { (*($1->u.iptr))($2->u.str) ; }
junk: IBUILTIN str { (*($1->u.iptr.func_str))($2->u.str) ; }
| IBUILTIN { }
| IBUILTIN VAR { (*($1->u.iptr))($2->u.val) ; }
| IBUILTIN expr { (*($1->u.iptr))($2) ; }
| IBUILTIN VAR { (*($1->u.iptr.func_dbl))($2->u.val) ; }
| IBUILTIN expr { (*($1->u.iptr.func_dbl))($2) ; }
| STR { printf("%s", $1->name);}
| STRVAR { printf("%s", $1->u.str);}
;
Expand Down
23 changes: 11 additions & 12 deletions symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CONSTS consts[] =
typedef struct
{
char *name ;
long double (*func)();
long double (*func)(long double);
}
BUILTINS;

Expand Down Expand Up @@ -80,29 +80,28 @@ BUILTINS builtins[] =
typedef struct
{
char *name ;
int (*ifunc)() ;
IFUNC_UNION ifunc ;
}
IBUILTINS;

IBUILTINS ibuiltins[] =

{

{"date", ddate},
{"print", print},
{"echo", echo},
{"_echo", echo_nl},
{"date", {ddate}},
{"print", {.func_dbl = print}},
{"echo", {echo}},
{"_echo", {echo_nl}},

{"DATE", ddate},
{"PRINT", print},
{"ECHO", echo},
{"_ECHO", echo_nl},
{"DATE", {ddate}},
{"PRINT", {.func_dbl = print}},
{"ECHO", {echo}},
{"_ECHO", {echo_nl}},

{NULL, (void *) 0}
{NULL, (void *) 0}
} ;



void init_sym(void)

{
Expand Down
10 changes: 8 additions & 2 deletions symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

/* -------- Macros: ------------------------------------------------------ */

typedef union
{
int (*func_str)(const char*);
int (*func_dbl)(long double);
} IFUNC_UNION;

typedef struct Symbol { /* symbol table entry */
char *name ;
short type ; /* VAR, BLTIN, UNDEF */
Expand All @@ -13,8 +19,8 @@ typedef struct Symbol { /* symbol table entry */
int ival; /* if VAR */
long long lval; /* if VAR */
long double val; /* if VAR */
long double (*ptr)(); /* if BUILTIN */
int (*iptr)(); /* if IBUILTIN */
long double (*ptr)(long double); /* if BUILTIN */
IFUNC_UNION iptr; /* if IBUILTIN */
} u ;
struct Symbol *next ;
} Symbol ;
Expand Down