diff options
author | Michael Hunteman <michael@huntm.net> | 2023-07-04 17:03:53 -0500 |
---|---|---|
committer | Michael Hunteman <michael@huntm.net> | 2023-07-06 17:23:45 -0500 |
commit | bfce8f0d0d828209ec0bec71371ee94a7ad62d3e (patch) | |
tree | bdf49ca788ca1ca030d5b1cccfd0c9dffeb3f69f /four/op.c |
Initial commit
Diffstat (limited to 'four/op.c')
-rw-r--r-- | four/op.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/four/op.c b/four/op.c new file mode 100644 index 0000000..f8e96ed --- /dev/null +++ b/four/op.c @@ -0,0 +1,42 @@ +#include <stdio.h> + +#define MAXVAL 100 +#define NUMBER '0' + +int sp = 0; +double val[MAXVAL]; + +void +push(double f) +{ + if (sp < MAXVAL) { + val[sp++] = f; + } else { + printf("error: stack full, can't push %g\n", f); + } +} + +double +pop(void) +{ + if (sp > 0) { + return val[--sp]; + } else { + printf("error: stack empty\n"); + return 0.0; + } +} + +double +peek() +{ + return val[sp - 1]; +} + +void +clear() +{ + while (sp) { + val[sp--] = 0; + } +} |