summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/nxspp.h12
-rw-r--r--src/nxspp.c24
-rw-r--r--src/visitor.c18
3 files changed, 17 insertions, 37 deletions
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;
}