summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/countdown.nxs7
-rw-r--r--doc/main.nxs3
-rw-r--r--src/include/nxspp.h12
-rw-r--r--src/nxspp.c24
-rw-r--r--src/visitor.c18
5 files changed, 26 insertions, 38 deletions
diff --git a/doc/countdown.nxs b/doc/countdown.nxs
new file mode 100644
index 0000000..c28fc7f
--- /dev/null
+++ b/doc/countdown.nxs
@@ -0,0 +1,7 @@
+(bind countdown
+ (lambda (n)
+ (if (= n 0)
+ 0
+ ((lambda (continue)
+ (continue (- n 1))) countdown))))
+(countdown 10)
diff --git a/doc/main.nxs b/doc/main.nxs
index 76fc95f..381161a 100644
--- a/doc/main.nxs
+++ b/doc/main.nxs
@@ -1,5 +1,6 @@
(include "fib.nxs")
+
(bind factorial (lambda (n)
- (if (= n 0) 1 (* n (factorial (- n 1))))))
+ (if (= n 0) 1 (* n (factorial (print(- n 1)))))))
(fib 7)
(+ (factorial 5) 10)
diff --git a/src/include/nxspp.h b/src/include/nxspp.h
deleted file mode 100644
index d88ab57..0000000
--- a/src/include/nxspp.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef NXSPP_H
-#define NXSPP_H
-
-typedef struct {
- char *source;
- char c;
- int i;
-} npp_t;
-
-npp_t *init_npp(char *source);
-char *process_string(npp_t *p);
-#endif
diff --git a/src/nxspp.c b/src/nxspp.c
deleted file mode 100644
index 7888cbb..0000000
--- a/src/nxspp.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "./include/nxspp.h"
-#include "./include/macros.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-npp_t *init_npp(char *source) {
- npp_t *n = malloc(sizeof(npp_t));
- if (n == NULL)
- die("malloc on nxspp");
- n->source = source;
- n->i = 0;
- n->c = source[n->i];
- return n;
-}
-
-char *nxspp_collect_id(char *source, int i) {}
-
-void npp_move(npp_t *p) {
- if (p->c != '\0') {
- p->i++;
- p->c = p->source[p->i];
- }
-}
diff --git a/src/visitor.c b/src/visitor.c
index 25fb7cd..22f09ed 100644
--- a/src/visitor.c
+++ b/src/visitor.c
@@ -62,7 +62,7 @@ bool is_built_in(ast_t *e) {
/* I/O and other operating system stuff */
if (strcmp(cmp, "exit") == 0 || strcmp(cmp, "readin") == 0 ||
- strcmp(cmp, "read") == 0)
+ strcmp(cmp, "read") == 0 || strcmp(cmp, "print") == 0)
return true;
return false;
}
@@ -440,7 +440,23 @@ ast_t *eval_list(visitor_t *v, ast_t *e) {
exit(code);
} else
eval_error(v, e);
+ } else if (strcmp(function->string_value, "print") == 0) {
+ if (cmp != 1)
+ eval_error(v, e);
+
+ ast_t *arg1 = eval_expr(v, args->car);
+ if (arg1->type == AST_STRING) {
+ printf("%s\n", arg1->string_value);
+ } else if (arg1->type == AST_INT) {
+ printf("%d\n", arg1->int_value);
+ } else if (arg1->type == AST_FLOAT) {
+ printf("%f\n", arg1->float_value);
+ } else {
+ printf("print statement for this datatype not implemented.\n");
+ }
+ return arg1;
}
+
return NULL;
}