summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2010-05-09 09:30:29 +0000
committerPaul Buetow <paul@buetow.org>2010-05-09 09:30:29 +0000
commita90467d4be3bcf91cab299b4521bf5f762abb1d5 (patch)
tree5171d406e6be467807a914ce42923ac997d74858
added the scheme branch
-rw-r--r--COPYING31
-rw-r--r--INSTALL11
-rw-r--r--Makefile118
-rw-r--r--docs/header.txt31
-rw-r--r--docs/help.txt8
-rw-r--r--docs/pbsc.txt43
-rw-r--r--docs/stats.txt4
-rw-r--r--docs/synopses.txt4
-rw-r--r--docs/version.txt1
-rw-r--r--docs/vim-tips.txt2
-rw-r--r--examples/netsted.fype11
-rw-r--r--examples/reverse.fype7
-rw-r--r--src/argv.c181
-rw-r--r--src/argv.h51
-rw-r--r--src/build.h41
-rw-r--r--src/core/frame.c152
-rw-r--r--src/core/frame.h68
-rw-r--r--src/core/interpret.c379
-rw-r--r--src/core/interpret.h58
-rw-r--r--src/core/lambda.c98
-rw-r--r--src/core/lambda.h55
-rw-r--r--src/core/promise.c60
-rw-r--r--src/core/promise.h49
-rw-r--r--src/core/scanner.c297
-rw-r--r--src/core/scanner.h69
-rw-r--r--src/core/token.c135
-rw-r--r--src/core/token.h75
-rw-r--r--src/core/tools.c64
-rw-r--r--src/core/tools.h42
-rw-r--r--src/core/variable.c59
-rw-r--r--src/core/variable.h52
-rw-r--r--src/data/array.c327
-rw-r--r--src/data/array.h94
-rw-r--r--src/data/cons.c88
-rw-r--r--src/data/cons.h55
-rw-r--r--src/data/dat.c268
-rw-r--r--src/data/dat.h88
-rw-r--r--src/data/hash.c306
-rw-r--r--src/data/hash.h84
-rw-r--r--src/data/list.c531
-rw-r--r--src/data/list.h118
-rw-r--r--src/data/map.c289
-rw-r--r--src/data/map.h88
-rw-r--r--src/data/queue.c210
-rw-r--r--src/data/queue.h81
-rw-r--r--src/data/stack.c271
-rw-r--r--src/data/stack.h79
-rw-r--r--src/data/tree.c215
-rw-r--r--src/data/tree.h106
-rw-r--r--src/data/tupel.c53
-rw-r--r--src/data/tupel.h47
-rw-r--r--src/data/types.h64
-rw-r--r--src/defines.h108
-rw-r--r--src/fype.c83
-rw-r--r--src/fype.h57
-rw-r--r--src/main.c45
-rw-r--r--tags282
-rw-r--r--test.fype13
-rw-r--r--test.out116
59 files changed, 6422 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..d911f4d
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,31 @@
+File: ./COPYING
+A simple Fype interpreter
+
+WWW: http://fype.buetow.org
+AUTHOR: http://paul.buetow.org
+E-Mail: fype at dev.buetow.org
+
+The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+
+Redistribution and use in source and binary forms, with or without modi-
+fication, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of buetow.org nor the names of its contributors may
+ be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..a8b38a4
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,11 @@
+How to install fype:
+
+ make
+ sudo make install
+ make clean
+
+How to read the docu:
+
+ man pbsc
+
+Examples can be found in the ./examples directory.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..37568aa
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,118 @@
+# THIS MAKEFILE ONLY WORKS WITH (NET)BSD MAKE AKA PMAKE!
+
+BIN=fype
+SRCS!=find ./src -name '*.c'
+OBJS=$(SRCS:.c=.o)
+CC?=cc
+#CC=mingw32-gcc
+DEBUG=-g3 -ggdb3
+CFLAGS+=-c -Wall -std=c99 -pedantic $(DEBUG)
+LDADD+=
+HEADER?=docs/header.txt
+OSYSTEM!=uname
+PREFIX=/usr/local
+all: build $(OBJS) newline stats-tofile
+ @$(CC) -lm -o $(BIN) $(OBJS) $(LDADD)
+ @awk '$$2 == "BUILDNR" { printf("===> Fype build number % 13s :% 6s%d\n", \
+ "", "", $$3); exit(0); }' src/build.h
+ @echo "===> Fype binary size : `du -hs $(BIN)`"
+ @#echo "===> `./$(BIN) -v | sed 's/Build .*//'`"
+ @./fype -v > ./docs/version.txt
+ @./fype -h > ./docs/help.txt
+ @./fype -s > ./docs/synopses.txt
+ @echo
+$(OBJS):
+ $(CC) $(LDADD) $(CFLAGS) `echo $@ | sed 's/\.o/\.c/'` -o $@
+clean:
+ find ./ -name 1 -exec rm -f {} \;
+ find ./ -name '*.o' -exec rm -f {} \;
+ find ./ -name '*.bin' -exec rm -f {} \;
+ find . -name '*.core' -exec rm -f {} \;
+ if [ -f $(BIN) ]; then rm -f $(BIN); fi
+build: ctags
+ @awk '{ \
+ if ($$2 == "BUILDNR") print $$1,$$2,$$3+1; \
+ else if ($$2 ~ /OS_/) printf("%s OS_%s\n", $$1, \
+ toupper("$(OSYSTEM)")); \
+ else print }' \
+ src/build.h >.tmp && mv -f .tmp src/build.h
+printbuild:
+ @awk '$$2 == "BUILDNR" { printf("%d\n", \
+ $$3); exit(0); }' src/build.h
+ctags:
+ # Generating Source-Tags for Vim
+ ctags `find . -name '*.c'`
+style: astyle check
+astyle:
+ find ./src -name '*.[ch]' -exec sh -c 'astyle -s3 {}; rm -f {}.orig' \;
+check:
+ for f in `find ./src -name '*.[ch]'`; do awk -v f=$$f \
+ '{ if (length($$0) > 80) { \
+ printf "Max line length reached @ %s:%d => %d\n", \
+ f, NR, length($$0) } }' $$f; done
+touch:
+ find ./src -name '*.c' -exec touch {} \;
+stats:
+ @sh -c 'wc=`find ./src -name "*.[ch]" | xargs wc -l`; \
+ echo "===> Num of C source files : `echo \"$$wc\" | \
+ grep -E \"\\.(c|h)$$\" | wc -l`"; \
+ echo "===> Num of C source lines : `echo \"$$wc\" | \
+ tail -n 1 | sed s/total//`"'
+ @sh -c 'wc=`find ./examples -name "*.fype" | xargs wc -l`; \
+ echo "===> Num of Fype source examples : `echo \"$$wc\" | \
+ grep -E \"\\.fype$$\" | wc -l`"; \
+ echo "===> Num of Fype source lines : `echo \"$$wc\" | \
+ tail -n 1 | sed s/total//`"'
+stats-tofile:
+ make stats | tee ./docs/stats.txt
+testrun:
+ cat ./test.fype > ./test.out
+ ./$(BIN) -V ./test.fype | tee -a ./test.out
+tr: testrun
+test: all testrun
+t: test
+run:
+ ./$(BIN) ./test.fype
+core:
+ #gdb $(BIN) $(BIN).core
+ gdb $(BIN) core
+gdb:
+ gdb --args $(BIN) .//
+newline:
+ @echo
+examples: all
+ echo > ./examples/all-examples.txt
+ for i in ./examples/*.fype; do \
+ echo "===> Running $$i"; \
+ ./$(BIN) $$i; \
+ cat $$i >> ./examples/all-examples.txt; \
+ echo >> ./examples/all-examples.txt; \
+ done
+replace:
+ find ./src -name '*.[ch]' -exec sh -c 'sed -n "s/$(FROM)/$(INTO)/g; \
+ w .tmp" {} && mv -f .tmp {}' \;
+headers:
+ @find ./src -name '*.[ch]' -exec sh -c 'export FILE={}; \
+ make header' \;
+ @sh -c '> ./COPYING;export FILE=./COPYING; make header'
+ @# BSD sed does not support the -i (inplace) switch
+ @sed -n '1d;$$d;s/....//; w .tmp' ./COPYING && mv .tmp ./COPYING
+
+header:
+ @echo "===> Processing $(FILE)"
+ @sed -n '/*:/d; w .tmp' $(FILE)
+ @header=`sed 's/\(.*\)/ echo " \*: \1"/' $(HEADER)`; \
+ echo '/*:*' > $(FILE); eval "$$header" >> $(FILE); \
+ echo ' *:*/' >> $(FILE); cat .tmp >> $(FILE); rm -f .tmp
+tar: clean
+ sh -c 'build=`make printbuild`;cd ../;\
+ tar cvjf $(BIN)-$$build.tar.bz2 $(BIN)'
+install: all
+ cp ./$(BIN) $(PREFIX)/bin
+ cp ./docs/pod/fype.1.gz $(PREFIX)/man/man1
+deinstall:
+ rm $(PREFIX)/bin/$(BIN)
+ rm $(PREFIX)/man/man1/fype.1.gz
+uninstall: deinstall
+pod:
+ @cd ./docs/pod; make clean all
diff --git a/docs/header.txt b/docs/header.txt
new file mode 100644
index 0000000..83638b8
--- /dev/null
+++ b/docs/header.txt
@@ -0,0 +1,31 @@
+File: ${FILE}
+A simple Fype interpreter
+
+WWW: http://fype.buetow.org
+AUTHOR: http://paul.buetow.org
+E-Mail: fype at dev.buetow.org
+
+The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+
+Redistribution and use in source and binary forms, with or without modi-
+fication, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of buetow.org nor the names of its contributors may
+ be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/docs/help.txt b/docs/help.txt
new file mode 100644
index 0000000..0033293
--- /dev/null
+++ b/docs/help.txt
@@ -0,0 +1,8 @@
+Fype2 Alpha Build 10387
+(c) Paul C. Buetow (2005 - 2010) <fype@dev.buetow.org>
+ -e Executes given code string (see synopses)
+ -h Prints this help
+ -s Prints the synopsis
+ -v Prints the current version
+ -T Prints token list after scanning
+ -V Verbose mode: Print all possible output
diff --git a/docs/pbsc.txt b/docs/pbsc.txt
new file mode 100644
index 0000000..3a2726c
--- /dev/null
+++ b/docs/pbsc.txt
@@ -0,0 +1,43 @@
+Global Frame
+
+v?: Variables
+p?: Parameters
+b?: Boolean expression (Returns #t or #f)
+t?: Term
+f: Function
+l?: List
+
+(f p1 p2 ...)
+
+(define v1 t1)
+
+(lambda (v1 v2 ...) t1)
+
+(define foo (lambda (v1 v2 ...) t1))
+(define (foo (v1 v2 ...) t1))
+
+(if b1 t1 t2)
+(unless b1 t1 t2)
+(eq? t1 t2)
+(neq? t1 t2)
+(and b1 b2)
+(or b1 b2)
+(xor b1 b2)
+(not b1)
+
+(cond ((b1 t1)
+ (b2 t2)
+ ...
+ (else tn)))
+
+(let ((v1 t1)
+ (v2 t2)
+ ...)
+ t3)
+
+(cons t1 l1)
+(car l1)
+(cdr l1)
+(set-car l1 t1)
+(set-cdr l1 t1)
+(list p1 p2 ...)
diff --git a/docs/stats.txt b/docs/stats.txt
new file mode 100644
index 0000000..50cbda1
--- /dev/null
+++ b/docs/stats.txt
@@ -0,0 +1,4 @@
+===> Num of C source files : 44
+===> Num of C source lines : 5740
+===> Num of Fype source examples : 2
+===> Num of Fype source lines : 18
diff --git a/docs/synopses.txt b/docs/synopses.txt
new file mode 100644
index 0000000..c0842aa
--- /dev/null
+++ b/docs/synopses.txt
@@ -0,0 +1,4 @@
+Synopsis:
+./fype [-[hsvTV]] file.fy
+./fype -e "code string;"
+ (Hint: Try -h for details)
diff --git a/docs/version.txt b/docs/version.txt
new file mode 100644
index 0000000..d2c768b
--- /dev/null
+++ b/docs/version.txt
@@ -0,0 +1 @@
+Fype2 Alpha Build 10387
diff --git a/docs/vim-tips.txt b/docs/vim-tips.txt
new file mode 100644
index 0000000..035b019
--- /dev/null
+++ b/docs/vim-tips.txt
@@ -0,0 +1,2 @@
+line numbers: :se nu :se
+buffers: :ls :bd <NUM> :bd <FILENAME>
diff --git a/examples/netsted.fype b/examples/netsted.fype
new file mode 100644
index 0000000..2ddf89f
--- /dev/null
+++ b/examples/netsted.fype
@@ -0,0 +1,11 @@
+(def (test)
+ (say "This is test")
+ (def (test2)
+ (say "I am in test2" "And test3 will be defined next!")
+ (def (test3)
+ (say "Displaying all frames now:")
+ (show-frames))
+ (test3))
+ (test2))
+(test)
+
diff --git a/examples/reverse.fype b/examples/reverse.fype
new file mode 100644
index 0000000..a4384b6
--- /dev/null
+++ b/examples/reverse.fype
@@ -0,0 +1,7 @@
+(def (reverse x)
+ (def (my-reverse x y)
+ (if (null? x)
+ y
+ (my-reverse (cdr x) (cons (car x) y))))
+ (my-reverse x '()))
+(reverse (list 1 2 3))
diff --git a/src/argv.c b/src/argv.c
new file mode 100644
index 0000000..dc938d9
--- /dev/null
+++ b/src/argv.c
@@ -0,0 +1,181 @@
+/*:*
+ *: File: ./src/argv.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "argv.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "defines.h"
+#include "data/dat.h"
+
+#define ARGV_OSLEN 128
+
+char *BINARY;
+
+void
+argv_run(PBSc *p_fype, int i_argc, char **pc_argv) {
+ Dat *p_dat_string = dat_new();
+
+ BINARY = pc_argv[0];
+ char *c_tmp = STR_NEW(ARGV_OSLEN);
+ c_tmp[0] = '\0';
+
+ p_fype->p_tupel_argv->a = p_dat_string;
+ p_fype->p_tupel_argv->b = c_tmp;
+
+ if (i_argc <= 1) {
+ argv_synopsis(p_fype->p_tupel_argv);
+ exit(1);
+ }
+
+ for (int i = 1; i < i_argc; ++i) {
+ if (pc_argv[i][0] != '-' && pc_argv[i][0] != '/') {
+ dat_push(p_dat_string, pc_argv[i]);
+ continue;
+ }
+
+ int i_len = strlen(pc_argv[i]);
+ unsigned i_argc_left = i_argc - i + dat_size(p_dat_string);
+
+ for (int j = 1; j < i_len; ++j)
+ argv_switch(pc_argv[i][j], p_fype->p_tupel_argv, i_argc_left);
+ }
+}
+
+void
+argv_switch(char c_arg, Tupel *p_tupel_argv, unsigned i_argc_left) {
+ switch (c_arg) {
+ case 'e':
+ case 'T':
+ case 'V':
+ argv_addopt(c_arg, p_tupel_argv);
+ return;
+ case 'h':
+ argv_help();
+ exit(0);
+ case 's':
+ argv_synopsis(p_tupel_argv);
+ exit(0);
+ case 'v':
+ printf("%s %s %d\n", NAME, VERSION, BUILDNR);
+ exit(0);
+ }
+
+ char buf[2];
+ buf[0] = c_arg;
+ buf[1] = '\0';
+
+ EPRINTF("Error: No such option '%s'!\n", buf);
+ exit(1);
+}
+
+void
+argv_synopsis(Tupel *p_tupel_argv) {
+ printf("Synopsis:\n");
+ printf("%s ", BINARY);
+ printf("[-[hsvTV]] file.fy\n");
+ printf("%s ", BINARY);
+ printf("-e \"code string;\"\n");
+
+ if (!argv_checkopt('h', p_tupel_argv))
+ printf("\t(Hint: Try -h for details)\n");
+}
+
+void
+argv_help() {
+ printf("%s %s %d\n", NAME, VERSION, BUILDNR);
+ printf("%s\n", COPYRIGHT);
+ printf("\t-e\tExecutes given code string (see synopses)\n");
+ printf("\t-h\tPrints this help\n");
+ printf("\t-s\tPrints the synopsis\n");
+ printf("\t-v\tPrints the current version\n");
+ printf("\t-T\tPrints token list after scanning\n");
+ printf("\t-V\tVerbose mode: Print all possible output\n");
+ exit(0);
+}
+
+void
+argv_addopt(char c_opt, Tupel *p_tupel_argv) {
+ char *c_opts = (char *) p_tupel_argv->b;
+ int i_len = strlen(c_opts), i;
+
+ for (i = 0; i < i_len; ++i)
+ if (c_opts[i] == c_opt)
+ return;
+
+ c_opts[i] = c_opt;
+ c_opts[i+1] = '\0';
+}
+
+_Bool
+argv_checkopt(char c_opt, Tupel *p_tupel_argv) {
+ char *c_opts = (char *) p_tupel_argv->b;
+ int i_len = strlen(c_opts);
+
+ for (int i = 0; i < i_len; ++i)
+ if (c_opts[i] == c_opt)
+ return 1;
+
+ return 0;
+}
+
+_Bool
+argv_checkopts(char *c_opts, Tupel *p_tupel_argv) {
+ int i_len = strlen(c_opts);
+
+ for (int i = 0; i < i_len; ++i)
+ if (argv_checkopt(c_opts[i], p_tupel_argv))
+ return 1;
+
+ return 0;
+}
+
+void
+argv_check_argc(int i_required, unsigned i_argc_left, Tupel *p_tupel_argv) {
+ if ((unsigned) ++i_required > i_argc_left) {
+ argv_synopsis(p_tupel_argv);
+ EPRINTF("%d argument(s) missing!\n", i_required-i_argc_left);
+ exit(1);
+ }
+}
+
+void
+argv_tupel_delete(Tupel *p_tupel_argv) {
+ dat_delete(p_tupel_argv->a);
+ free(p_tupel_argv->b);
+ tupel_delete(p_tupel_argv);
+}
+
diff --git a/src/argv.h b/src/argv.h
new file mode 100644
index 0000000..a7575d2
--- /dev/null
+++ b/src/argv.h
@@ -0,0 +1,51 @@
+/*:*
+ *: File: ./src/argv.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef ARGV_H
+#define ARGV_H
+
+#include "data/tupel.h"
+#include "fype.h"
+
+void argv_run(PBSc *p_fype, int i_argc, char **pc_argv);
+void argv_switch(char c_arg, Tupel *p_tupel_argv, unsigned i_argc_left);
+void argv_synopsis(Tupel *p_tupel_argv);
+void argv_help();
+void argv_addopt(char c_opt, Tupel *p_tupel_argv);
+_Bool argv_checkopt(char c_opt, Tupel *p_tupel_argv);
+_Bool argv_checkopts(char *c_opts, Tupel *p_tupel_argv);
+void argv_check_argc(int i_required, unsigned i_argc_left, Tupel *p_tupel_argv);
+void argv_tupel_delete(Tupel *p_tupel_argv);
+
+#endif
diff --git a/src/build.h b/src/build.h
new file mode 100644
index 0000000..1e6006e
--- /dev/null
+++ b/src/build.h
@@ -0,0 +1,41 @@
+/*:*
+ *: File: ./src/build.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef BUILD_H
+#define BUILD_H
+
+#define BUILDNR 10388
+#define OS_LINUX
+
+#endif
diff --git a/src/core/frame.c b/src/core/frame.c
new file mode 100644
index 0000000..9143a0d
--- /dev/null
+++ b/src/core/frame.c
@@ -0,0 +1,152 @@
+/*:*
+ *: File: ./src/core/frame.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "frame.h"
+#include "lambda.h"
+#include "variable.h"
+
+unsigned _I_FRAME_ID_COUNT = 0;
+
+Symbol*
+symbol_new(SymbolType st, void *p_val) {
+ Symbol *p_symbol = malloc(sizeof(Symbol));
+
+ p_symbol->st = st;
+ p_symbol->p_val = p_val;
+
+ return (p_symbol);
+}
+
+void
+symbol_delete(Symbol *p_symbol) {
+ switch (p_symbol->st) {
+ case ST_LAMBDA:
+ lambda_delete(p_symbol->p_val);
+ break;
+ case ST_VARIABLE:
+ variable_delete(p_symbol->p_val);
+ break;
+ }
+
+ free(p_symbol);
+}
+
+void
+symbol_delete_cb(void *p_symbol) {
+ symbol_delete(p_symbol);
+}
+
+char*
+symbol_get_type_name(Symbol *p_symbol) {
+ switch (p_symbol->st) {
+ case ST_LAMBDA:
+ return ("ST_LAMBDA");
+ case ST_VARIABLE:
+ return ("ST_VARIABLE");
+ }
+
+ return ("ST_UNKNOWN");
+}
+
+Frame*
+frame_new(Frame *p_parent_frame) {
+ Frame *p_frame = malloc(sizeof(Frame));
+
+ p_frame->p_parent_frame = p_parent_frame;
+ p_frame->p_hash_symbols = hash_new(8);
+ p_frame->i_frame_id = _I_FRAME_ID_COUNT++;
+
+ return (p_frame);
+}
+
+void
+frame_delete(Frame *p_frame) {
+ Hash *p_hash_symbols = p_frame->p_hash_symbols;
+
+ hash_iterate(p_hash_symbols, symbol_delete_cb);
+ hash_delete(p_hash_symbols);
+}
+
+_Bool
+frame_add_symbol(Frame *p_frame, char *c_name, SymbolType st, void *p_val) {
+ Hash *p_hash_symbols = p_frame->p_hash_symbols;
+
+ if (hash_key_exists(p_hash_symbols, c_name))
+ return (false);
+
+
+ Symbol *p_symbol = symbol_new(st, p_val);
+ hash_insert(p_hash_symbols, c_name, p_symbol);
+
+ return (true);
+}
+
+Symbol*
+frame_get_symbol(Frame *p_frame, char *c_name) {
+ void *p_val = hash_get(p_frame->p_hash_symbols, c_name);
+
+ if (!p_val && p_frame->p_parent_frame)
+ return (frame_get_symbol(p_frame->p_parent_frame, c_name));
+
+ return (p_val);
+}
+
+void
+_symbol_print_cb(void *p_val, char *c_name) {
+ Symbol *p_symbol = p_val;
+ switch (p_symbol->st) {
+ case ST_LAMBDA:
+ lambda_print(p_symbol->p_val);
+ break;
+ case ST_VARIABLE:
+ variable_print(p_symbol->p_val);
+ break;
+ }
+}
+
+void
+_frame_print(Frame *p_frame, int i_frame_nr) {
+ printf("FRAME(id=%u) %d:\n", p_frame->i_frame_id, i_frame_nr);
+
+ Hash *p_hash_symbols = p_frame->p_hash_symbols;
+ hash_iterate_key(p_hash_symbols, _symbol_print_cb);
+
+ if (p_frame->p_parent_frame)
+ _frame_print(p_frame->p_parent_frame, i_frame_nr + 1);
+}
+
+void
+frame_print(Frame *p_frame) {
+ _frame_print(p_frame, 0);
+}
diff --git a/src/core/frame.h b/src/core/frame.h
new file mode 100644
index 0000000..d1e01f5
--- /dev/null
+++ b/src/core/frame.h
@@ -0,0 +1,68 @@
+/*:*
+ *: File: ./src/core/frame.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef FRAME_H
+#define FRAME_H
+
+#include "../defines.h"
+#include "../data/hash.h"
+
+typedef enum {
+ ST_LAMBDA,
+ ST_VARIABLE,
+} SymbolType;
+
+typedef struct {
+ SymbolType st;
+ void *p_val;
+} Symbol;
+
+typedef struct _Frame {
+ struct _Frame *p_parent_frame;
+ Hash *p_hash_symbols;
+ unsigned i_frame_id;
+} Frame;
+
+Symbol* symbol_new(SymbolType st, void *p_val);
+void symbol_delete(Symbol *p_symbol);
+void symbol_delete_cb(void *p_symbol);
+char* symbol_get_type_name(Symbol *p_symbol);
+
+Frame* frame_new(Frame *p_parent_frame);
+void frame_delete(Frame *p_frame);
+_Bool frame_add_symbol(Frame *p_frame, char *c_name, SymbolType st, void *p_val);
+Symbol *frame_get_symbol(Frame *p_frame, char *c_name);
+void frame_print(Frame *p_frame);
+
+#endif
diff --git a/src/core/interpret.c b/src/core/interpret.c
new file mode 100644
index 0000000..28239ef
--- /dev/null
+++ b/src/core/interpret.c
@@ -0,0 +1,379 @@
+/*:*
+ *: File: ./src/core/interpret.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "interpret.h"
+#include "promise.h"
+#include "variable.h"
+#include "tools.h"
+
+void _eval(Interpret *p_inter);
+
+Interpret*
+interpret_new(List *p_list_token) {
+ Interpret *p_inter = malloc(sizeof(Interpret));
+
+ p_inter->p_frame = frame_new(NULL);
+
+ p_inter->p_list_token = p_list_token;
+ p_inter->p_token = NULL;
+
+ p_inter->i_pcount = 0;
+
+ p_inter->b_is_lambda_interpretation = false;
+ p_inter->p_lambda = NULL;
+
+ return (p_inter);
+}
+
+Interpret*
+interpret_new_lambda(Interpret *p_inter, Lambda *p_lambda) {
+ Interpret *p_inter_up = malloc(sizeof(Interpret));
+ p_inter_up->p_frame = frame_new(p_lambda->p_frame);
+ p_inter_up->p_list_token = NULL;
+ p_inter_up->p_token = NULL;
+ p_inter_up->i_pcount = 0;
+
+ p_inter_up->b_is_lambda_interpretation = true;
+ p_inter_up->p_lambda = p_lambda;
+
+ return (p_inter_up);
+}
+
+void
+interpret_delete(Interpret *p_inter) {
+ frame_delete(p_inter->p_frame);
+ free(p_inter);
+}
+
+void
+interpret_run(PBSc *p_fype) {
+ Interpret *p_inter =
+ interpret_new(p_fype->p_list_token);
+
+ _eval(p_inter);
+
+ interpret_delete(p_inter);
+}
+
+void
+_def(Interpret *p_inter, Token *p_token, ListIterator *p_iter) {
+ Frame *p_frame = p_inter->p_frame;
+ _Bool b_success;
+
+ if (!listiterator_has_next(p_iter))
+ ERROR_EOB;
+
+ p_token = listiterator_next(p_iter);
+ char *c_name;
+
+ if (p_token->tt_cur == TT_IDENT) {
+ c_name = p_token->c_val;
+
+ ListElem *p_listelem = listiterator_current_elem(p_iter);
+
+ if (!listiterator_has_next(p_iter))
+ ERROR_EOB;
+
+ p_token = listiterator_next(p_iter);
+
+ switch (p_token->tt_cur) {
+ case TT_PARANT_L: {
+ tool_skip_block(p_iter, 0);
+ ListElem *p_listelem_end = listiterator_current_elem(p_iter);
+ Lambda *p_lambda = lambda_new(
+ c_name,
+ NULL,
+ p_listelem,
+ p_listelem_end,
+ p_inter->p_frame);
+ //printf("::1\n");
+ b_success = frame_add_symbol(p_frame, c_name, ST_LAMBDA, p_lambda);
+ }
+ break;
+ case TT_IDENT: {
+ Variable *p_variable = variable_new(
+ c_name,
+ p_token,
+ p_inter->p_frame);
+ b_success = frame_add_symbol(p_frame,
+ c_name, ST_VARIABLE, p_variable);
+ if (!listiterator_has_next(p_iter))
+ ERROR_EOB;
+ Token *p_token2 = listiterator_next(p_iter);
+ if (p_token2->tt_cur != TT_PARANT_R)
+ ERROR_INTERPRET("Expected ) or (", p_token);
+ }
+ break;
+ default:
+ ERROR_INTERPRET("Expected ( or identifier", p_token);
+ }
+
+ } else if (p_token->tt_cur == TT_PARANT_L) {
+ List *p_list_args = list_new();
+
+ if (!listiterator_has_next(p_iter))
+ ERROR_INTERPRET("Expected identifier", p_token);
+
+ p_token = listiterator_next(p_iter);
+ if (p_token->tt_cur != TT_IDENT)
+ ERROR_INTERPRET("Expected identifier", p_token);
+
+ c_name = p_token->c_val;
+ while (listiterator_has_next(p_iter)) {
+ p_token = listiterator_next(p_iter);
+
+ if (p_token->tt_cur != TT_IDENT) {
+ if (p_token->tt_cur != TT_PARANT_R)
+ ERROR_INTERPRET("Expected identifier or )", p_token);
+ break;
+
+ } else {
+ list_add_back(p_list_args, p_token->c_val);
+ }
+ }
+
+ ListElem *p_listelem = listiterator_next_elem(p_iter);
+ //printf("::2\n");
+ tool_skip_block(p_iter, 2);
+ ListElem *p_listelem_end = listiterator_current_elem(p_iter);
+
+ Lambda *p_lambda = lambda_new(
+ c_name,
+ p_list_args,
+ p_listelem,
+ p_listelem_end,
+ p_inter->p_frame);
+ b_success = frame_add_symbol(p_frame, c_name, ST_LAMBDA, p_lambda);
+ } else {
+ ERROR_INTERPRET("Expected identifier or (", p_token);
+ }
+
+ if (!b_success)
+ ERROR("Forbidden to redef symbol \"%s\" @ current frame", c_name);
+}
+
+void
+_say(Interpret *p_inter, Token *p_token, ListIterator *p_iter) {
+ while (listiterator_has_next(p_iter)) {
+ Token *p_token = listiterator_next(p_iter);
+ switch (p_token->tt_cur) {
+ case TT_IDENT:
+ case TT_INTEGER:
+ case TT_STRING:
+ printf("%s\n", p_token->c_val);
+ break;
+ case TT_PARANT_L:
+ ERROR("Not yet implemented");
+ break;
+ case TT_PARANT_R:
+ return;
+ NO_DEFAULT;
+ }
+ }
+}
+
+void
+_eval_lambda(Interpret *p_inter, Lambda *p_lambda, ListIterator *p_iter) {
+ Interpret *p_inter_local = interpret_new_lambda(p_inter, p_lambda);
+ Frame *p_frame_local = p_inter_local->p_frame;
+ ListIterator *p_iter_args = NULL;
+
+
+ if (p_lambda->p_list_args)
+ p_iter_args = listiterator_new(p_lambda->p_list_args);
+
+ Token *p_token = listiterator_current(p_iter);
+
+ if (p_iter_args) {
+ while (listiterator_has_next(p_iter_args)) {
+ char *c_name = listiterator_next(p_iter_args);
+
+ if (!listiterator_has_next(p_iter))
+ ERROR_EOB;
+ ListElem *p_listelem = listiterator_current_elem(p_iter);
+ p_token = listiterator_next(p_iter);
+
+ switch (p_token->tt_cur) {
+ case TT_PARANT_L: {
+ //printf("::3\n");
+ tool_skip_block(p_iter, 1 );
+ ListElem *p_listelem_end = listiterator_current_elem(p_iter);
+ Lambda *p_lambda_ = lambda_new(
+ c_name,
+ NULL,
+ p_listelem,
+ p_listelem_end,
+ p_frame_local);
+ if (!frame_add_symbol(p_frame_local,
+ c_name,
+ ST_LAMBDA,
+ p_lambda_)) {
+ printf("Illegal reuse of parameter '%s' @ function '%s'",
+ c_name, p_lambda->c_name);
+ ERROR_INTERPRET(". Error binding local lambda", p_token);
+ }
+ }
+ break;
+ case TT_PARANT_R:
+ ERROR_INTERPRET("Didn't expect ) here", p_token);
+ break;
+ default: {
+ Variable *p_variable = variable_new(c_name,
+ p_token,
+ p_frame_local);
+ if (!frame_add_symbol(p_frame_local,
+ c_name,
+ ST_VARIABLE,
+ p_variable)) {
+ printf("Illegal reuse of parameter '%s' @ function '%s'\n",
+ c_name, p_lambda->c_name);
+ frame_print(p_frame_local);
+ ERROR_INTERPRET("Fatal", p_token);
+ }
+ }
+ break;
+ }
+ }
+
+ listiterator_delete(p_iter_args);
+ }
+
+ if (!listiterator_has_next(p_iter))
+ ERROR_EOB;
+
+ _eval(p_inter_local);
+ interpret_delete(p_inter_local);
+}
+
+void
+_eval_symbol(Interpret *p_inter, Symbol *p_symbol, ListIterator *p_iter) {
+ switch (p_symbol->st) {
+ case ST_LAMBDA: {
+ _eval_lambda(p_inter, p_symbol->p_val, p_iter);
+ //printf("::EVAL_LAMBDA_END\n");
+ }
+ break;
+ case ST_VARIABLE:
+ break;
+ }
+}
+
+Token*
+_parant(Interpret *p_inter, Token *p_token) {
+ //printf("::PARANT<%d>: %s\n", p_inter->i_pcount, p_token->c_val);
+ if (p_token->tt_cur == TT_PARANT_L) {
+ ++p_inter->i_pcount;
+
+ } else if (p_token->tt_cur == TT_PARANT_R) {
+ if (--p_inter->i_pcount == 0)
+ return (NULL);
+
+ else if (p_inter->i_pcount < 0)
+ ERROR_INTERPRET("Too many closing )'s",
+ p_token);
+ }
+
+ return (p_token);
+}
+
+void
+_run_func(Interpret *p_inter, Token *p_token, ListIterator *p_iter) {
+ Frame *p_frame = p_inter->p_frame;
+ Symbol *p_symbol = NULL;
+
+ if (listiterator_has_next(p_iter)) {
+ if (! (p_token = _parant(p_inter, listiterator_next(p_iter))) )
+ return;
+
+ //printf("::Interpreting: %s\n", p_token->c_val);
+
+ if (token_is(p_token, "def")) {
+
+ _def(p_inter, p_token, p_iter);
+
+ } else if (token_is(p_token, "say")) {
+ _say(p_inter, p_token, p_iter);
+
+ } else if (token_is(p_token, "noop")) {
+
+ } else if ( (p_symbol = frame_get_symbol(p_frame, p_token->c_val)) != NULL ) {
+ _eval_symbol(p_inter, p_symbol, p_iter);
+
+ } else if (token_is(p_token, "show-frames")) {
+ frame_print(p_inter->p_frame);
+
+ } else if (token_is(p_token, "beep")) {
+ printf("BEEP\n");
+
+ } else {
+ printf("No symbol '%s' defined @ any frame:\n", p_token->c_val);
+ frame_print(p_frame);
+ ERROR_INTERPRET("Error.", p_token);
+ }
+ }
+}
+
+void
+_eval(Interpret *p_inter) {
+ ListIterator *p_iter = NULL;
+ ListElem *p_listelem_end = NULL;
+
+ if (!p_inter->b_is_lambda_interpretation) {
+ p_iter = listiterator_new(p_inter->p_list_token);
+ } else {
+ p_iter = listiterator_new_from_elem(p_inter->p_lambda->p_listelem);
+ p_listelem_end = p_inter->p_lambda->p_listelem_end;
+ }
+
+ while (listiterator_has_next(p_iter)) {
+ Token *p_token = _parant(p_inter, listiterator_next(p_iter));
+ if (!p_token)
+ break;
+
+ if (p_listelem_end && listiterator_current_elem_equals(
+ p_iter,
+ p_listelem_end))
+ break;
+
+ switch (p_token->tt_cur) {
+ case TT_PARANT_L:
+ _run_func(p_inter, p_token, p_iter);
+ break;
+ case TT_PARANT_R:
+ break;
+ NO_DEFAULT;
+ }
+ }
+ listiterator_delete(p_iter);
+}
diff --git a/src/core/interpret.h b/src/core/interpret.h
new file mode 100644
index 0000000..6d3a4a5
--- /dev/null
+++ b/src/core/interpret.h
@@ -0,0 +1,58 @@
+/*:*
+ *: File: ./src/core/interpret.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef INTERPRET_H
+#define INTERPRET_H
+
+#include "frame.h"
+#include "token.h"
+#include "lambda.h"
+#include "../data/list.h"
+#include "../fype.h"
+
+typedef struct _Interpret {
+ List *p_list_token;
+ Frame *p_frame;
+ Token *p_token;
+ int i_pcount;
+ _Bool b_is_lambda_interpretation;
+ Lambda *p_lambda;
+} Interpret;
+
+Interpret* interpret_new(List *p_list_token);
+Interpret* interpret_new_lambda(Interpret *p_inter, Lambda *p_lambda);
+void interpret_delete(Interpret *p_inter);
+void interpret_run(PBSc *p_fype);
+
+#endif /* INTERPRET_H */
diff --git a/src/core/lambda.c b/src/core/lambda.c
new file mode 100644
index 0000000..c6ad9a2
--- /dev/null
+++ b/src/core/lambda.c
@@ -0,0 +1,98 @@
+/*:*
+ *: File: ./src/core/lambda.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "lambda.h"
+#include "token.h"
+
+Lambda*
+lambda_new(char *c_name, List *p_list_args, ListElem *p_listelem, ListElem *p_listelem_end, Frame *p_frame) {
+ Lambda *p_lambda = malloc(sizeof(Lambda));
+
+ p_lambda->c_name = c_name;
+ p_lambda->p_list_args = p_list_args;
+ p_lambda->p_listelem = p_listelem;
+ p_lambda->p_listelem_end = p_listelem_end;;
+ p_lambda->p_frame = p_frame;
+
+ return (p_lambda);
+}
+
+void
+lambda_delete(Lambda *p_lambda) {
+ if (p_lambda->p_list_args)
+ list_delete(p_lambda->p_list_args);
+ free(p_lambda);
+}
+
+void
+lambda_print(Lambda *p_lambda) {
+ printf("+ST_LAMBDA(name=%s;args=", p_lambda->c_name);
+
+ if (p_lambda->p_list_args) {
+ unsigned i_count = p_lambda->p_list_args->i_size;
+ ListIterator *p_iter = listiterator_new(p_lambda->p_list_args);
+
+ while (listiterator_has_next(p_iter)) {
+ char *c_name = listiterator_next(p_iter);
+ if (--i_count == 0)
+ printf("%s", c_name);
+ else
+ printf("%s ", c_name);
+ }
+
+ listiterator_delete(p_iter);
+ }
+ printf(")\n( ");
+
+ ListIterator *p_iter = listiterator_new_from_elem(p_lambda->p_listelem);
+ Token *p_token = listiterator_current(p_iter);
+ ListElem *p_listelem_end = p_lambda->p_listelem_end;
+
+
+ while (listiterator_has_next(p_iter)) {
+ p_token = listiterator_next(p_iter);
+ printf("%s ", p_token->c_val);
+
+ if (listiterator_current_elem_equals(p_iter, p_listelem_end))
+ goto LAMBDA_PRINT_END;
+ }
+
+ ERROR_EOB;
+
+LAMBDA_PRINT_END:
+
+ printf("\n");
+ listiterator_delete(p_iter);
+}
+
diff --git a/src/core/lambda.h b/src/core/lambda.h
new file mode 100644
index 0000000..8377c30
--- /dev/null
+++ b/src/core/lambda.h
@@ -0,0 +1,55 @@
+/*:*
+ *: File: ./src/core/lambda.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef LAMBDA_H
+#define LAMBDA_H
+
+#include "../defines.h"
+#include "../data/list.h"
+#include "frame.h"
+
+typedef struct _Lambda {
+ char *c_name;
+ List *p_list_args;
+ ListElem *p_listelem; // Body code starts here
+ ListElem *p_listelem_end; // Body code ends here
+ Frame *p_frame;
+} Lambda;
+
+Lambda* lambda_new(char *c_name, List *p_list_args, ListElem *p_listelem, ListElem *p_listelem_end, Frame *p_frame);
+void lambda_delete(Lambda *p_lambda);
+void lambda_print(Lambda *p_lambda);
+//void lambda_eval(Lambda *p_pambda, ListIterator *p_iter);
+
+#endif
diff --git a/src/core/promise.c b/src/core/promise.c
new file mode 100644
index 0000000..fa50e78
--- /dev/null
+++ b/src/core/promise.c
@@ -0,0 +1,60 @@
+/*:*
+ *: File: ./src/core/promise.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "promise.h"
+
+#define _ERROR(m,t) \
+ ERROR(\
+ "%s: Promise error in %s line %d pos %d near '%s'", m, \
+ t->c_filename, \
+ t->i_line_nr, \
+ t->i_pos_nr, \
+ t->c_val \
+ )
+
+Promise*
+promise_new(Token *p_token_lambda, ListElem *p_elem_start) {
+ Promise *p_promise = malloc(sizeof(Promise));
+
+ p_promise->p_token_lambda = p_token_lambda;
+ p_promise->p_elem_start = p_elem_start;
+
+ return (p_promise);
+}
+
+void
+promise_delete(Promise *p_promise) {
+ free(p_promise);
+}
+
diff --git a/src/core/promise.h b/src/core/promise.h
new file mode 100644
index 0000000..76cd162
--- /dev/null
+++ b/src/core/promise.h
@@ -0,0 +1,49 @@
+/*:*
+ *: File: ./src/core/promise.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef PROMISE_H
+#define PROMISE_H
+
+#include "../data/list.h"
+#include "token.h"
+
+typedef struct {
+ ListElem *p_elem_start;
+ Token *p_token_lambda;
+} Promise;
+
+Promise* promise_new(Token *p_token_lambda, ListElem *p_elem_start);
+void promise_delete(Promise *p_promise);
+
+#endif /* PROMISE_H */
diff --git a/src/core/scanner.c b/src/core/scanner.c
new file mode 100644
index 0000000..a2b2b10
--- /dev/null
+++ b/src/core/scanner.c
@@ -0,0 +1,297 @@
+/*:*
+ *: File: ./src/core/scanner.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "scanner.h"
+
+#include <ctype.h>
+#include <string.h>
+
+const char _TOKEN_ENDS[] = "()";
+int _CODESTR_INDEX = 0;
+
+Scanner*
+scanner_new(List *p_list_token, Tupel *p_tupel_argv) {
+ Scanner *p_scanner = malloc(sizeof(Scanner));
+
+ Dat *p_dat_string = p_tupel_argv->a;
+
+ if (dat_empty(p_dat_string))
+ ERROR("No source given");
+
+ if (argv_checkopts("e", p_tupel_argv)) {
+ p_scanner->c_codestring = dat_pop(p_dat_string);
+ p_scanner->c_filename = NULL;
+ p_scanner->fp = NULL;
+
+ } else {
+ p_scanner->c_codestring = NULL;
+ p_scanner->c_filename = dat_pop(p_dat_string);
+ p_scanner->fp = fopen(p_scanner->c_filename, "r");
+
+ if (!p_scanner->fp)
+ ERROR("Could not open '%s' for reading!", p_scanner->c_filename);
+ }
+
+ p_scanner->p_list_token = p_list_token;
+
+ p_scanner->i_current_line_nr = 1;
+ p_scanner->i_current_pos_nr = 0;
+
+ p_scanner->i_num_tokenends = strlen(_TOKEN_ENDS);
+ p_scanner->tt_last = TT_IDENT;
+
+ return p_scanner;
+}
+
+void
+scanner_delete(Scanner *p_scanner) {
+ if (p_scanner->fp)
+ fclose(p_scanner->fp);
+ free(p_scanner);
+}
+
+_Bool
+_scanner_has_next_char(Scanner *p_scanner) {
+ if (p_scanner->fp)
+ return !feof(p_scanner->fp);
+
+ return p_scanner->c_codestring[_CODESTR_INDEX] != 0;
+}
+
+char
+_scanner_get_next_char(Scanner *p_scanner) {
+ if (p_scanner->fp)
+ return fgetc(p_scanner->fp);
+
+ return (p_scanner->c_codestring[_CODESTR_INDEX++]);
+}
+
+void
+scanner_run(PBSc *p_fype) {
+ Scanner *p_scanner = scanner_new(p_fype->p_list_token,
+ p_fype->p_tupel_argv);
+
+ int i_token_len = 0;
+ char *c_token = malloc(sizeof(char));
+
+ c_token[0] = 0;
+
+ while ( _scanner_has_next_char(p_scanner) ) {
+ char c = _scanner_get_next_char(p_scanner);
+ ++p_scanner->i_current_pos_nr;
+
+ switch (c) {
+ case '#':
+ {
+ c = _scanner_get_next_char(p_scanner);
+ ++p_scanner->i_current_pos_nr;
+ _Bool b_multi_comment = c == '*';
+
+ do {
+ c = _scanner_get_next_char(p_scanner);
+ ++p_scanner->i_current_pos_nr;
+ if (c == '\n') {
+ ++p_scanner->i_current_line_nr;
+ p_scanner->i_current_pos_nr = 0;
+
+ if (!b_multi_comment)
+ break;
+
+ } else if (b_multi_comment && c == '*' &&
+ _scanner_has_next_char(p_scanner)) {
+ if ( (c = _scanner_get_next_char(p_scanner)) == '#')
+ break;
+
+ else if (c == '\n')
+ ++p_scanner->i_current_line_nr;
+ }
+
+ } while ( _scanner_has_next_char(p_scanner) );
+ }
+
+ break;
+
+ case '"':
+ if (i_token_len) {
+ TokenType tt_cur = scanner_get_tt_cur(c_token);
+ scanner_add_token(p_scanner, &c_token, &i_token_len, tt_cur);
+ }
+ {
+ int i_num_nl = 0;
+ do {
+ c = _scanner_get_next_char(p_scanner);
+ if ( c == '\n' ) {
+ ++i_num_nl;
+ p_scanner->i_current_pos_nr = 0;
+
+ i_token_len += 2;
+ c_token = realloc(c_token, sizeof(char) * (i_token_len + 1));
+ c_token[i_token_len-2] = '\\';
+ c_token[i_token_len-1] = 'n';
+ c_token[i_token_len] = 0;
+
+ } else if (c == '"') {
+ if (i_token_len && c_token[i_token_len-1] == '\\') {
+ c_token[i_token_len-1] = '"';
+
+ } else {
+ break;
+ }
+
+ } else {
+ ++i_token_len;
+ c_token = realloc(c_token, sizeof(char) * (i_token_len + 1));
+ c_token[i_token_len-1] = c;
+ c_token[i_token_len] = 0;
+ }
+
+ } while ( _scanner_has_next_char(p_scanner) );
+
+ scanner_add_token(p_scanner, &c_token, &i_token_len, TT_STRING);
+
+ if (i_num_nl)
+ p_scanner->i_current_line_nr += i_num_nl;
+ }
+
+ break;
+
+ case '\n':
+ case '\t':
+ case ' ':
+ if (i_token_len) {
+ TokenType tt_cur = scanner_get_tt_cur(c_token);
+ scanner_add_token(p_scanner, &c_token, &i_token_len, tt_cur);
+ }
+
+ if (c == '\n') {
+ ++p_scanner->i_current_line_nr;
+ p_scanner->i_current_pos_nr = 0;
+ }
+
+ break;
+
+ case '(':
+ case '.':
+ {
+ if (i_token_len) {
+ TokenType tt_cur = scanner_get_tt_cur(c_token);
+ scanner_add_token(p_scanner, &c_token, &i_token_len, tt_cur);
+ }
+ ++i_token_len;
+ c_token = realloc(c_token, sizeof(char) * i_token_len + 1);
+ c_token[i_token_len-1] = c;
+ c_token[i_token_len] = 0;
+ TokenType tt_cur = scanner_get_tt_cur(c_token);
+ scanner_add_token(p_scanner, &c_token, &i_token_len, tt_cur);
+ }
+ break;
+
+ default:
+ if (i_token_len) {
+ TokenType tt_cur = scanner_get_tt_cur(c_token);
+
+ for (int i = 0; i < p_scanner->i_num_tokenends; ++i) {
+ if (_TOKEN_ENDS[i] == c) {
+ scanner_add_token(p_scanner, &c_token,
+ &i_token_len, tt_cur);
+ break;
+ }
+ }
+ }
+
+ ++i_token_len;
+ c_token = realloc(c_token, sizeof(char) * i_token_len + 1);
+ c_token[i_token_len-1] = c;
+ c_token[i_token_len] = 0;
+ }
+ }
+
+ if (argv_checkopts("e", p_fype->p_tupel_argv) && i_token_len) {
+ TokenType tt_cur = scanner_get_tt_cur(c_token);
+ scanner_add_token(p_scanner, &c_token, &i_token_len, tt_cur);
+ }
+
+ char *c_filename = scanner_get_filename(p_scanner);
+ scanner_delete(p_scanner);
+
+ if (argv_checkopts("TV", p_fype->p_tupel_argv))
+ list_iterate(p_fype->p_list_token, token_print_cb);
+
+ char *c_basename = NULL;
+ if (c_filename) {
+ int i_len = strlen(c_filename) - 3;
+ c_basename = calloc(i_len+1, sizeof(char));
+ strncpy(c_basename, c_filename, i_len);
+ c_basename[i_len] = 0;
+
+ } else {
+ char *c_basename = calloc(1, sizeof(char));
+ c_basename[0] = 0;
+ }
+
+ p_fype->c_basename = c_basename;
+}
+
+void
+scanner_add_token(Scanner *p_scanner, char **cc_token, int *p_token_len,
+ TokenType tt_cur) {
+
+ List *p_list_token = scanner_get_list_token(p_scanner);
+ Token *p_token = token_new(*cc_token, tt_cur,
+ p_scanner->i_current_line_nr,
+ p_scanner->i_current_pos_nr,
+ p_scanner->c_filename);
+
+ list_add_back(p_list_token, p_token);
+
+ *cc_token = malloc(sizeof(char));
+ (*cc_token)[0] = 0;
+ *p_token_len = 0;
+
+ p_scanner->tt_last = tt_cur;
+}
+
+TokenType
+scanner_get_tt_cur(char *c_token) {
+ if (isdigit(c_token[0]))
+ return TT_INTEGER;
+
+ return (get_tt(c_token));
+}
+
+void
+scanner_cleanup_list_token_cb(void *p_void) {
+ Token *p_token = p_void;
+ token_delete(p_token);
+}
diff --git a/src/core/scanner.h b/src/core/scanner.h
new file mode 100644
index 0000000..b15707b
--- /dev/null
+++ b/src/core/scanner.h
@@ -0,0 +1,69 @@
+/*:*
+ *: File: ./src/core/scanner.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef SCANNER_H
+#define SCANNER_H
+
+#include <stdio.h>
+#include <ctype.h>
+
+#include "token.h"
+#include "../fype.h"
+#include "../data/dat.h"
+
+#define scanner_get_list_token(s) s->p_list_token
+#define scanner_get_fp(s) s->fp
+#define scanner_get_filename(s) s->c_filename
+#define scanner_get_codestring(s) s->c_codestring
+
+typedef struct {
+ int i_current_line_nr;
+ int i_current_pos_nr;
+ int i_num_tokenends;
+ char *c_filename;
+ char *c_codestring;
+ FILE *fp;
+ List *p_list_token;
+ TokenType tt_last;
+} Scanner;
+
+void scanner_run(PBSc *p_fype);
+Scanner *scanner_new(List *p_list_token, Tupel *p_tupel_argv);
+void scanner_delete(Scanner *p_scanner);
+void scanner_add_token(Scanner *p_scanner, char **cc_token, int *p_token_len,
+ TokenType tt_cur);
+TokenType scanner_get_tt_cur(char *c_token);
+void scanner_cleanup_list_token_cb(void *p_void);
+
+#endif
diff --git a/src/core/token.c b/src/core/token.c
new file mode 100644
index 0000000..a0a6ad0
--- /dev/null
+++ b/src/core/token.c
@@ -0,0 +1,135 @@
+/*:*
+ *: File: ./src/core/token.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "token.h"
+
+#define CHECK(...) if (!strcmp(c_token, __VA_ARGS__)) return
+#define CASE(t,r) case t: return r;
+
+long TOKEN_ID_COUNTER = 0;
+
+TokenType
+get_tt(char *c_token) {
+ CHECK("(") TT_PARANT_L;
+ CHECK(")") TT_PARANT_R;
+ CHECK("'") TT_SQUOTE;
+ CHECK(".") TT_DOT;
+
+ return TT_IDENT;
+}
+
+char*
+tt_get_name(TokenType tt_cur) {
+ switch (tt_cur) {
+ CASE(TT_PARANT_L,"TT_PARANT_L")
+ CASE(TT_PARANT_R,"TT_PARANT_R")
+ CASE(TT_INTEGER,"TT_INTEGER")
+ CASE(TT_DOUBLE,"TT_DOUBLE")
+ CASE(TT_STRING,"TT_STRING")
+ CASE(TT_DOT,"TT_DOT")
+ CASE(TT_SQUOTE,"TT_SQUOTE")
+ CASE(TT_IDENT,"TT_IDENT")
+ }
+
+ return "TT_IDENT";
+}
+
+Token*
+token_new(char *c_val, TokenType tt_cur, int i_line_nr,
+ int i_pos_nr, char *c_filename) {
+ Token *p_token = token_new_dummy();
+
+ p_token->c_val = c_val;
+ p_token->tt_cur = tt_cur;
+ p_token->i_line_nr = i_line_nr;
+ p_token->i_pos_nr = i_pos_nr;
+ p_token->c_filename = c_filename;
+
+ return (p_token);
+}
+
+Token*
+token_new_dummy() {
+ Token *p_token = malloc(sizeof(Token));
+
+ p_token->c_val = NULL;
+ p_token->tt_cur = TT_IDENT;
+ p_token->i_line_nr = -1;
+ p_token->i_pos_nr = -1;
+ p_token->c_filename = NULL;
+ p_token->u_token_id = TOKEN_ID_COUNTER++;
+
+ return (p_token);
+}
+
+void
+token_delete_cb(void *p_void) {
+ token_delete(p_void);
+}
+
+void
+token_delete(Token *p_token) {
+}
+
+_Bool
+token_is(Token *p_token, char *c_str) {
+ if (p_token->tt_cur == TT_IDENT && strcmp(p_token->c_val, c_str) == 0)
+ return true;
+
+ return false;
+}
+
+void
+token_print(Token *p_token) {
+ printf("(id=%05u, line=%05d, pos=%04d, type=%s, val=%s)",
+ p_token->u_token_id,
+ p_token->i_line_nr,
+ p_token->i_pos_nr,
+ tt_get_name(p_token->tt_cur),
+ p_token->c_val);
+}
+
+void
+token_print_ln(Token *p_token) {
+ token_print(p_token);
+ printf("\n");
+}
+
+void
+token_print_cb(void *p_void) {
+ Token *p_token = p_void;
+ printf("Token ");
+ token_print(p_token);
+ printf("\n");
+}
diff --git a/src/core/token.h b/src/core/token.h
new file mode 100644
index 0000000..8f1ab53
--- /dev/null
+++ b/src/core/token.h
@@ -0,0 +1,75 @@
+/*:*
+ *: File: ./src/core/token.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef TOKEN_H
+#define TOKEN_H
+
+#include "../defines.h"
+#include "../data/array.h"
+
+typedef enum {
+ TT_IDENT,
+ TT_PARANT_L,
+ TT_PARANT_R,
+ TT_INTEGER,
+ TT_DOUBLE,
+ TT_STRING,
+ TT_SQUOTE,
+ TT_DOT
+} TokenType;
+
+typedef struct {
+ TokenType tt_cur;
+ char *c_val;
+ int i_line_nr;
+ int i_pos_nr;
+ char *c_filename;
+ unsigned int u_token_id;
+} Token;
+
+Token* token_new(char *c_val, TokenType tt_cur, int i_line_nr,
+ int i_pos_nr, char *c_filename);
+Token* token_new_dummy();
+void token_delete(Token *p_token);
+void token_delete_cb(void *p_token);
+void* token_copy_cb(void *p_token);
+char* tt_get_name(TokenType tt_cur);
+void token_print_cb(void *p_void);
+void token_print(Token *p_token);
+void token_print_ln(Token *p_token);
+void token_print_val(Token *p_token);
+_Bool token_is(Token *p_token, char *c_str);
+TokenType get_tt(char *c_token);
+
+#endif
diff --git a/src/core/tools.c b/src/core/tools.c
new file mode 100644
index 0000000..6b6dbab
--- /dev/null
+++ b/src/core/tools.c
@@ -0,0 +1,64 @@
+/*:*
+ *: File: ./src/core/tools.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "tools.h"
+#include "token.h"
+#include "../defines.h"
+
+void
+tool_skip_block(ListIterator *p_iter, int i_offset) {
+ Token *p_token = listiterator_current(p_iter);
+
+ do {
+ if (p_token->tt_cur == TT_PARANT_R && --i_offset == 0) {
+ //printf("::DoneSkip<%d>: %s\n", i_offset, p_token->c_val);
+ return;
+
+ } else if (p_token->tt_cur == TT_PARANT_L) {
+ ++i_offset;
+
+ } else if (i_offset < 0) {
+ ERROR_INTERPRET("Fatal Error", p_token);
+ }
+
+ //printf("::Skipping<%d>: %s\n", i_offset, p_token->c_val);
+ p_token = listiterator_next(p_iter);
+ } while (listiterator_has_next(p_iter));
+
+ if (p_token->tt_cur == TT_PARANT_R)
+ return;
+
+ ERROR_EOB;
+}
+
diff --git a/src/core/tools.h b/src/core/tools.h
new file mode 100644
index 0000000..19d9fa6
--- /dev/null
+++ b/src/core/tools.h
@@ -0,0 +1,42 @@
+/*:*
+ *: File: ./src/core/tools.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef TOOLS_H
+#define TOOLS_H
+
+#include "../fype.h"
+
+void tool_skip_block(ListIterator *p_iter, int i_offset);
+
+#endif /* TOOLS_H */
diff --git a/src/core/variable.c b/src/core/variable.c
new file mode 100644
index 0000000..2b924a5
--- /dev/null
+++ b/src/core/variable.c
@@ -0,0 +1,59 @@
+/*:*
+ *: File: ./src/core/variable.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "variable.h"
+#include "token.h"
+
+Variable*
+variable_new(char *c_name, Token *p_token,Frame *p_frame) {
+ Variable *p_variable = malloc(sizeof(Variable));
+
+ p_variable->c_name = c_name;
+ p_variable->p_token = p_token;
+ p_variable->p_frame = p_frame;
+
+ return (p_variable);
+}
+
+void
+variable_delete(Variable *p_variable) {
+ free(p_variable);
+}
+
+void
+variable_print(Variable *p_variable) {
+ printf("+ST_VARIABLE(name=%s,value=%s)\n",
+ p_variable->c_name,
+ p_variable->p_token->c_val);
+}
diff --git a/src/core/variable.h b/src/core/variable.h
new file mode 100644
index 0000000..7a7d27c
--- /dev/null
+++ b/src/core/variable.h
@@ -0,0 +1,52 @@
+/*:*
+ *: File: ./src/core/variable.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef VARIABLE_H
+#define VARIABLE_H
+
+#include "../defines.h"
+#include "frame.h"
+#include "token.h"
+
+typedef struct _Variable {
+ char *c_name;
+ Token *p_token;
+ Frame *p_frame;
+} Variable;
+
+Variable* variable_new(char *c_name, Token *p_token,Frame *p_frame);
+void variable_delete(Variable *p_variable);
+void variable_print(Variable *p_variable);
+
+#endif
diff --git a/src/data/array.c b/src/data/array.c
new file mode 100644
index 0000000..f50e998
--- /dev/null
+++ b/src/data/array.c
@@ -0,0 +1,327 @@
+/*:*
+ *: File: ./src/data/array.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "array.h"
+
+Array*
+array_new() {
+ Array *p_array = malloc(sizeof(Array));
+
+ p_array->i_size = 0;
+ p_array->pp_ae = NULL;
+ array_set_used(p_array, 0);
+
+ return (p_array);
+}
+
+Array*
+array_new_size(int i_size) {
+ Array *p_array = array_new();
+
+ array_resize(p_array, i_size);
+
+ return (p_array);
+}
+
+void
+_unshift_cb(void *p_array, void *p_void) {
+ array_unshift(p_array, p_void);
+}
+
+Array*
+array_new_copy(Array *p_array) {
+ Array *p_array_cpy = array_new_size(array_get_size(p_array));
+ array_iterate2(p_array, _unshift_cb, p_array_cpy);
+
+ return (p_array_cpy);
+}
+
+void
+array_delete(Array *p_array) {
+ if (!p_array)
+ return;
+
+ if (p_array->i_size)
+ for (int i = p_array->i_size - 1; i >= 0; --i)
+ arrayelement_delete(p_array->pp_ae[i]);
+
+ if (p_array->pp_ae)
+ free(p_array->pp_ae);
+
+ free(p_array);
+}
+
+void
+array_delete_iterate(Array *p_array, void (*func)(void *)) {
+ if (!p_array)
+ return;
+
+ array_iterate(p_array, func);
+
+ if (p_array->i_size)
+ for (int i = p_array->i_size - 1; i >= 0; --i)
+ arrayelement_delete(p_array->pp_ae[i]);
+
+ if (p_array->pp_ae)
+ free(p_array->pp_ae);
+
+ free(p_array);
+}
+
+void
+array_set(Array *p_array, int i_index, void *p_val) {
+ if (p_array->i_size > i_index) {
+ p_array->pp_ae[i_index]->p_val = p_val;
+
+ } else {
+ array_resize(p_array, i_index + 1);
+ p_array->pp_ae[i_index]->p_val = p_val;
+ }
+
+ if (p_array->i_used < i_index)
+ array_set_used(p_array, i_index);
+}
+
+void
+array_set_used(Array *p_array, int i_used) {
+ p_array->i_used = i_used;
+}
+
+
+void
+array_insert(Array *p_array, int i_index, void *p_val) {
+ if (p_array->i_size <= i_index) {
+ array_set(p_array, i_index, p_val);
+
+ } else {
+ array_resize(p_array, p_array->i_size + 1);
+
+ ArrayElement *p_ae = p_array->pp_ae[p_array->i_size-1];
+ int i;
+ for (i = p_array->i_size - 1; i > i_index; --i)
+ p_array->pp_ae[i] = p_array->pp_ae[i-1];
+
+ p_array->pp_ae[i] = p_ae;
+ p_ae->p_val = p_val;
+ }
+
+ if (p_array->i_used < i_index)
+ array_set_used(p_array, i_index);
+}
+
+void*
+array_remove(Array *p_array, int i_index) {
+ if (p_array->i_size <= i_index)
+ return (NULL);
+
+ ArrayElement *p_ae = p_array->pp_ae[i_index];
+ void *p_ret = p_ae->p_val;
+ int i;
+
+ for (i = i_index+1; i < p_array->i_size; ++i)
+ p_array->pp_ae[i-1] = p_array->pp_ae[i];
+
+ p_array->pp_ae[i-1] = p_ae;
+
+ array_resize(p_array, p_array->i_size - 1);
+ return (p_ret);
+}
+
+void
+array_print_int(Array *p_array) {
+ printf("Array:");
+ for (int i = 0; i < p_array->i_size; ++i)
+ printf(" (%d,%d)", i, (int) array_get(p_array, i));
+ printf("\n");
+}
+
+void
+array_resize(Array *p_array, int i_size) {
+ if (i_size == p_array->i_size)
+ return;
+
+ if (i_size < p_array->i_size)
+ for (int i = p_array->i_size - 1; i >= i_size; --i)
+ arrayelement_delete(p_array->pp_ae[i]);
+
+ if (i_size == 0) {
+ free(p_array->pp_ae);
+ p_array->pp_ae = NULL;
+
+ } else if (p_array->pp_ae != NULL) {
+ p_array->pp_ae = realloc(p_array->pp_ae,
+ sizeof(ArrayElement) * i_size);
+
+ } else {
+ p_array->pp_ae = malloc(sizeof(ArrayElement) * i_size);
+ }
+
+ if (i_size > p_array->i_size)
+ for (int i = p_array->i_size; i < i_size; ++i)
+ p_array->pp_ae[i] = arrayelement_new(NULL);
+
+ p_array->i_size = i_size;
+ if (p_array->i_used > i_size)
+ array_set_used(p_array, i_size);
+}
+
+void*
+array_get(Array *p_array, int i_index) {
+ if (p_array->i_size > i_index)
+ return (p_array->pp_ae[i_index]->p_val);
+
+ return (NULL);
+}
+
+_Bool
+array_defined(Array *p_array, int i_index) {
+ if (i_index >= p_array->i_size)
+ return (false);
+
+ return (p_array->pp_ae[i_index]->p_val != NULL);
+}
+
+void
+array_splice(Array *p_array, int i_index, Array *p_array2) {
+ if (i_index >= array_get_size(p_array))
+ return;
+
+ array_remove(p_array, i_index);
+
+ int i_size1= array_get_size(p_array);
+ int i_size2 = array_get_size(p_array2);
+ int i_size = i_size1 + i_size2;
+
+ array_resize(p_array, i_size);
+
+ for (int i = i_size1 - 1; i >= i_index; --i)
+ p_array->pp_ae[i+i_size2]->p_val = p_array->pp_ae[i]->p_val;
+
+ for (int i = 0; i < i_size2; ++i)
+ p_array->pp_ae[i+i_index]->p_val = p_array2->pp_ae[i]->p_val;
+
+}
+
+void
+array_unshift(Array *p_array, void *p_void) {
+ int i_used = array_get_used(p_array);
+ array_set(p_array, i_used, p_void);
+ array_set_used(p_array, 1+i_used);
+}
+
+void
+array_push(Array *p_array, void *p_void) {
+ int i_size = array_get_size(p_array);
+ array_resize(p_array, ++i_size);
+
+ for (int i = i_size - 1; i > 0; --i)
+ p_array->pp_ae[i]->p_val = p_array->pp_ae[i-1]->p_val;
+
+ array_set(p_array, 0, p_void);
+}
+
+void
+array_append(Array *p_array, Array *p_array_append) {
+ int i_size = array_get_size(p_array) + array_get_size(p_array_append);
+ array_resize(p_array, i_size);
+ array_iterate2(p_array_append, _unshift_cb, p_array);
+}
+
+void
+array_iterate(Array *p_array, void (*func)(void *)) {
+ if (!p_array)
+ return;
+
+ for (int i = 0; i < array_get_used(p_array); ++i)
+ (*func) (array_get(p_array, i));
+}
+
+void
+array_iterate2(Array *p_array, void (*func)(void *, void *), void *p_void) {
+ if (!p_array)
+ return;
+
+ for (int i = 0; i < array_get_used(p_array); ++i)
+ (*func) (array_get(p_array, i), p_void);
+}
+
+ArrayElement*
+arrayelement_new(void *p_val) {
+ ArrayElement *p_ae = malloc(sizeof(ArrayElement));
+
+ p_ae->p_val = p_val;
+
+ return (p_ae);
+}
+
+void
+arrayelement_delete(ArrayElement *p_ae) {
+ if (!p_ae)
+ return;
+
+ free(p_ae);
+}
+
+ArrayIterator*
+arrayiterator_new(Array *p_array) {
+ if (!p_array)
+ return (NULL);
+
+ ArrayIterator *p_arrayiterator = malloc(sizeof(ArrayIterator));
+ p_arrayiterator->p_array = p_array;
+ p_arrayiterator->i_cur_pos = 0;
+
+ return (p_arrayiterator);
+}
+
+void
+arrayiterator_delete(ArrayIterator *p_arrayiterator) {
+ if (p_arrayiterator)
+ free(p_arrayiterator);
+}
+
+_Bool
+arrayiterator_has_next(ArrayIterator *p_arrayiterator) {
+ //printf("[%d]", p_arrayiterator->p_array->i_used);
+ return (p_arrayiterator->i_cur_pos <
+ array_get_used(p_arrayiterator->p_array));
+}
+
+void*
+arrayiterator_next(ArrayIterator *p_arrayiterator) {
+ if (!arrayiterator_has_next(p_arrayiterator))
+ return (NULL);
+
+ return (array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++));
+}
diff --git a/src/data/array.h b/src/data/array.h
new file mode 100644
index 0000000..6800061
--- /dev/null
+++ b/src/data/array.h
@@ -0,0 +1,94 @@
+/*:*
+ *: File: ./src/data/array.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef ARRAY_H
+#define ARRAY_H
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "../defines.h"
+
+#define array_get_size(a) a->i_size
+#define array_get_used(a) a->i_used
+#define array_get_ind(a) (a->i_used - 1)
+#define array_empty(a) a->i_size == 0
+#define array_clear(a) array_resize(a, 0)
+#define array_get_first(a) array_get(a, 0)
+#define array_get_last(a) array_get(a, array_get_size(a)-1)
+
+typedef struct {
+ void *p_val;
+} ArrayElement;
+
+typedef struct {
+ ArrayElement **pp_ae;
+ int i_used;
+ int i_size;
+} Array;
+
+typedef struct {
+ Array *p_array;
+ int i_cur_pos;
+} ArrayIterator;
+
+Array *array_new();
+Array *array_new_size(int i_size);
+Array *array_new_copy(Array *p_array);
+void array_delete(Array *p_array);
+void array_delete_iterate(Array *p_array, void (*func)(void*));
+void array_set(Array *p_array, int i_index, void *p_val);
+void array_insert(Array *p_array, int i_index, void *p_val);
+void *array_remove(Array *p_array, int i_index);
+void *array_get(Array *p_array, int i_index);
+void array_resize(Array *p_array, int i_size);
+_Bool array_defined(Array *p_array, int i_index);
+void array_print_int(Array *p_array);
+void array_splice(Array *p_array, int i_index, Array *p_array2);
+void array_push(Array *p_array, void *p_void);
+void array_append(Array *p_array, Array *p_array_append);
+void array_unshift(Array *p_array, void *p_void);
+void array_iterate(Array *p_array, void (*func)(void *));
+void array_iterate2(Array *p_array, void (*func)(void *, void *),
+ void *p_void);
+void array_set_used(Array *p_array, int i_used);
+
+ArrayElement *arrayelement_new(void *p_val);
+void arrayelement_delete(ArrayElement *p_ae);
+
+ArrayIterator *arrayiterator_new(Array *p_array);
+void arrayiterator_delete(ArrayIterator *p_arrayiterator);
+_Bool arrayiterator_has_next(ArrayIterator *p_arrayiterator);
+void *arrayiterator_next(ArrayIterator *p_arrayiterator);
+#endif
diff --git a/src/data/cons.c b/src/data/cons.c
new file mode 100644
index 0000000..7331167
--- /dev/null
+++ b/src/data/cons.c
@@ -0,0 +1,88 @@
+/*:*
+ *: File: ./src/data/cons.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "cons.h"
+
+Cons*
+cons_new(void *p_val) {
+ Cons *p_cons = malloc(sizeof(Cons));
+
+ p_cons->p_val = p_val;
+ p_cons->p_succ = NULL;
+
+ return (p_cons);
+}
+
+void
+cons_delete(Cons *p_cons) {
+ free(p_cons);
+}
+
+void
+cons_delete_cb(void *p_cons) {
+ cons_delete(p_cons);
+}
+
+void
+cons_iterate(Cons *p_cons, void (*func)(void *)) {
+ if (p_cons != NULL && p_cons->p_val != NULL) {
+ (*func) (p_cons->p_val);
+ cons_iterate(p_cons->p_succ, func);
+ }
+}
+
+void*
+cons_car(Cons *p_cons) {
+ return (p_cons->p_val);
+}
+
+Cons*
+cons_cdr(Cons *p_cons) {
+ return (p_cons->p_succ);
+}
+
+Cons*
+cons_cons(Cons *p_cons, void *p_val) {
+ if (p_cons->p_val == NULL) {
+ p_cons->p_val = p_val;
+ return (p_cons);
+
+ } else if (p_val == NULL) {
+ return (p_cons);
+ }
+
+ Cons *p_new = cons_new(p_val);
+ p_new->p_succ = p_cons;
+ return (p_new);
+}
diff --git a/src/data/cons.h b/src/data/cons.h
new file mode 100644
index 0000000..130415b
--- /dev/null
+++ b/src/data/cons.h
@@ -0,0 +1,55 @@
+/*:*
+ *: File: ./src/data/cons.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef CONS_H
+#define CONS_H
+
+#include <stdlib.h>
+
+#include "../defines.h"
+
+typedef struct Cons_ {
+ void *p_val;
+ struct Cons_ *p_succ;
+} Cons;
+
+Cons *cons_new(void *p_val);
+void cons_delete(Cons *p_cons);
+void cons_delete_cb(void *p_cons);
+void cons_iterate(Cons *p_cons, void (*func)(void *));
+void *cons_car(Cons *p_cons);
+Cons *cons_cdr(Cons *p_cons);
+Cons *cons_cons(Cons *p_cons, void *p_val);
+
+#endif
diff --git a/src/data/dat.c b/src/data/dat.c
new file mode 100644
index 0000000..b448cdc
--- /dev/null
+++ b/src/data/dat.c
@@ -0,0 +1,268 @@
+/*:*
+ *: File: ./src/data/dat.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "dat.h"
+
+#include <stdlib.h>
+#include "../defines.h"
+
+Dat*
+dat_new() {
+ Dat *p_dat = (Dat *) malloc(sizeof(Dat));
+
+ p_dat->p_first = 0;
+ p_dat->p_last = 0;
+ p_dat->i_size = 0;
+
+ return (p_dat);
+}
+
+DatElem*
+datelem_new() {
+ return (datelem_new_t(TYPE_UNKNOWN));
+}
+
+DatElem*
+datelem_new_t(TYPE type) {
+ DatElem *p_elem = (DatElem *) malloc(sizeof(DatElem));
+
+ p_elem->p_next = 0;
+ p_elem->p_val = 0;
+ p_elem->type = type;
+
+ return (p_elem);
+}
+
+_Bool
+dat_empty(Dat *p_dat) {
+ if (p_dat == NULL)
+ return (false);
+
+ return (p_dat->i_size == 0);
+}
+
+void
+dat_push(Dat *p_dat, void *p_val) {
+ dat_push_t(p_dat, p_val, TYPE_UNKNOWN);
+}
+
+void
+dat_push_t(Dat *p_dat, void *p_val, TYPE type) {
+ DatElem *p_elem = datelem_new_t(type);
+ p_elem->p_val = p_val;
+
+ if (0 == p_dat->i_size++)
+ p_dat->p_first = p_elem;
+ else
+ p_dat->p_last->p_next = p_elem;
+
+ p_dat->p_last = p_elem;
+}
+
+void*
+dat_pop(Dat *p_dat) {
+ TYPE type;
+ return (dat_pop_t(p_dat, &type));
+}
+
+void*
+dat_pop_t(Dat *p_dat, TYPE *p_type) {
+ if (dat_empty(p_dat))
+ return (NULL);
+
+ DatElem *p_elem = p_dat->p_first;
+ p_dat->p_first = p_elem->p_next;
+
+ --p_dat->i_size;
+
+ void *p_ret = p_elem->p_val;
+ *p_type = p_elem->type;
+ free(p_elem);
+ return (p_ret);
+}
+
+void
+dat_clear(Dat *p_dat) {
+ for (;!dat_empty(p_dat); dat_pop(p_dat));
+}
+
+void
+dat_delete(Dat *p_dat) {
+ dat_clear(p_dat);
+ free(p_dat);
+}
+
+unsigned
+dat_size(Dat *p_dat) {
+ return (p_dat->i_size);
+}
+
+void
+dat_iterate(Dat *p_dat, void (*func)(void *)) {
+ DatElem *p_elem = p_dat->p_first;
+ while (p_elem) {
+ if (p_elem->p_val)
+ (*func) (p_elem->p_val);
+
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+dat_iterate_t(Dat *p_dat, void (*func)(void *, TYPE)) {
+ DatElem *p_elem = p_dat->p_first;
+ while (p_elem) {
+ if (p_elem->p_val)
+ (*func) (p_elem->p_val, p_elem->type);
+
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+dat_iterate_tl(Dat *p_dat, void (*func)(void *, TYPE, _Bool)) {
+ DatElem *p_elem = p_dat->p_first;
+ while (p_elem) {
+ if (p_elem->p_val)
+ (*func) (p_elem->p_val, p_elem->type, p_elem->p_next == NULL);
+
+ p_elem = p_elem->p_next;
+ }
+}
+
+void*
+dat_first(Dat *p_dat) {
+ if (dat_empty(p_dat))
+ return (NULL);
+
+ return (p_dat->p_first->p_val);
+}
+
+void*
+dat_second(Dat *p_dat) {
+ if (2 > dat_size(p_dat))
+ return (NULL);
+
+ return (p_dat->p_first->p_next->p_val);
+}
+
+void*
+dat_last(Dat *p_dat) {
+ if (dat_empty(p_dat))
+ return (NULL);
+
+ return (p_dat->p_last->p_val);
+}
+
+void*
+dat_first_t(Dat *p_dat, TYPE *p_type) {
+ if (dat_empty(p_dat))
+ return (NULL);
+
+ *p_type = p_dat->p_first->type;
+ return (p_dat->p_first->p_val);
+}
+
+void*
+dat_second_t(Dat *p_dat, TYPE *p_type) {
+ if (2 > dat_size(p_dat))
+ return (NULL);
+
+ *p_type = p_dat->p_first->p_next->type;
+ return (p_dat->p_first->p_next->p_val);
+}
+
+void*
+dat_last_t(Dat *p_dat, TYPE *p_type) {
+ if (dat_empty(p_dat))
+ return (NULL);
+
+ *p_type = p_dat->p_last->type;
+ return (p_dat->p_last->p_val);
+}
+
+DatIter*
+datiter_new(Dat *p_dat) {
+ DatIter *p_iter =
+ (DatIter *) malloc(sizeof(DatIter));
+
+ p_iter->p_current = NULL;
+ p_iter->p_next = p_dat->p_first;
+ p_iter->i_left = dat_size(p_dat);
+ p_iter->p_dat = p_dat;
+
+ return (p_iter);
+}
+
+void
+datiter_delete(DatIter *p_iter) {
+ free(p_iter);
+}
+
+void
+datiter_skip(DatIter *p_iter, unsigned i_num) {
+ for (int i = 0; i < i_num; ++i)
+ datiter_next(p_iter);
+}
+
+void*
+datiter_next(DatIter *p_iter) {
+ TYPE type;
+ return (datiter_next_t(p_iter, &type));
+}
+
+void*
+datiter_next_t(DatIter *p_iter, TYPE *p_type) {
+ if (p_iter->p_next == NULL)
+ return (NULL);
+
+ void *p_ret = p_iter->p_next->p_val;
+ *p_type = p_iter->p_next->type;
+ p_iter->p_current = p_iter->p_next;
+ p_iter->p_next = p_iter->p_next->p_next;
+ --p_iter->i_left;
+
+ return (p_ret);
+}
+
+unsigned
+datiter_left(DatIter *p_iter) {
+ return (p_iter->i_left);
+}
+
+Dat*
+datiter_dat(DatIter *p_iter) {
+ return (p_iter->p_dat);
+}
+
diff --git a/src/data/dat.h b/src/data/dat.h
new file mode 100644
index 0000000..dcc7928
--- /dev/null
+++ b/src/data/dat.h
@@ -0,0 +1,88 @@
+/*:*
+ *: File: ./src/data/dat.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef DAT_H
+#define DAT_H
+
+#include "types.h"
+
+typedef struct DatElem_ {
+ struct DatElem_ *p_next;
+ void *p_val;
+ TYPE type;
+} DatElem;
+
+typedef struct {
+ DatElem *p_first;
+ DatElem *p_last;
+ unsigned i_size;
+} Dat;
+
+typedef struct {
+ unsigned i_left;
+ Dat *p_dat;
+ DatElem *p_current;
+ DatElem *p_next;
+} DatIter;
+
+Dat *dat_new();
+DatElem *datelem_new();
+DatElem *datelem_new_t(TYPE type);
+_Bool dat_empty(Dat *p_dat);
+void dat_push(Dat *p_dat, void *p_val);
+void dat_push_t(Dat *p_dat, void *p_val, TYPE type);
+void *dat_pop(Dat *p_dat);
+void *dat_pop_t(Dat *p_dat, TYPE *p_type);
+void dat_clear(Dat *p_dat);
+void dat_delete(Dat *p_dat);
+unsigned dat_size(Dat *p_dat);
+void dat_iterate(Dat *p_dat, void (*func)(void *));
+void dat_iterate_t(Dat *p_dat, void (*func)(void *, TYPE));
+void dat_iterate_tl(Dat *p_dat, void (*func)(void *, TYPE, _Bool));
+void *dat_first(Dat *p_dat);
+void *dat_second(Dat *p_dat);
+void *dat_last(Dat *p_dat);
+void *dat_first_t(Dat *p_dat, TYPE *p_type);
+void *dat_second_t(Dat *p_dat, TYPE *p_type);
+void *dat_last_t(Dat *p_dat, TYPE *p_type);
+
+DatIter *datiter_new(Dat *p_dat);
+void datiter_delete(DatIter *p_iter);
+void datiter_skip(DatIter *p_iter, unsigned i_num);
+void *datiter_next(DatIter *p_iter);
+void *datiter_next_t(DatIter *p_iter, TYPE *p_type);
+unsigned datiter_left(DatIter *p_iter);
+Dat *datiter_dat(DatIter *p_iter);
+
+#endif
diff --git a/src/data/hash.c b/src/data/hash.c
new file mode 100644
index 0000000..e196840
--- /dev/null
+++ b/src/data/hash.c
@@ -0,0 +1,306 @@
+/*:*
+ *: File: ./src/data/hash.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "hash.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+Hash*
+hash_new(unsigned i_size) {
+ Hash *p_hash = (Hash *) malloc(sizeof(Hash));
+
+ p_hash->i_size = i_size;
+ p_hash->i_cur_size = 0;
+ p_hash->p_elems = (HashElem *) calloc(i_size, sizeof(HashElem));
+
+ /*Set all positions as "free" */
+ for (int i = 0; i < i_size; ++i)
+ p_hash->p_elems[i].flag = 'f';
+
+ return (p_hash);
+}
+
+void
+hash_delete(Hash *p_hash) {
+ if (p_hash->p_elems) {
+ free(p_hash->p_elems);
+ p_hash->p_elems = 0;
+ }
+
+ free(p_hash);
+}
+
+RETCODE
+hash_insert_ht(Hash *p_hash, char *c_key, void *p_val, TYPE type) {
+ if (p_hash->i_cur_size == p_hash->i_size)
+ hash_size(p_hash, p_hash->i_size *2);
+
+ int i_addr = hash_getaddr(p_hash, c_key, FREE_ADDR);
+
+ if (i_addr == RET_ERROR )
+ return (RET_NO_SPACE);
+
+ strncpy(p_hash->p_elems[i_addr].c_key, c_key, HASH_MKEYLEN);
+
+ p_hash->p_elems[i_addr].flag = 'o';
+ p_hash->p_elems[i_addr].type = type;
+ p_hash->p_elems[i_addr].p_val = p_val;
+ p_hash->i_cur_size++;
+
+ return (RET_OK);
+}
+
+RETCODE
+hash_insert(Hash *p_hash, char *c_key, void *p_val) {
+ return (hash_insert_ht(p_hash, c_key, p_val, TYPE_VOIDP));
+}
+
+void*
+hash_remove(Hash *p_hash, char *c_key) {
+ if (p_hash->i_cur_size < p_hash->i_size / 3)
+ hash_size(p_hash, p_hash->i_size / 2);
+
+ int i_addr = hash_getaddr(p_hash, c_key, OCC_ADDR);
+
+ if (i_addr == -1 )
+ return (NULL);
+
+ void *p_val = p_hash->p_elems[i_addr].p_val;
+ p_hash->p_elems[i_addr].flag = 'm';
+ p_hash->p_elems[i_addr].p_val = 0;
+ --p_hash->i_cur_size;
+
+ return (p_val);
+}
+
+void*
+hash_get_ht(Hash *p_hash, char *c_key, TYPE *p_type) {
+ int i_addr;
+ return (hash_get_ht_addr(p_hash, c_key, p_type, &i_addr));
+}
+
+void*
+hash_get_ht_addr(Hash *p_hash, char *c_key, TYPE *p_type, int *p_addr) {
+ int i_addr = *p_addr = hash_getaddr(p_hash, c_key, OCC_ADDR);
+
+ if (i_addr == -1 )
+ return (NULL);
+
+ *p_type = p_hash->p_elems[i_addr].type;
+ return (p_hash->p_elems[i_addr].p_val);
+}
+
+void*
+hash_get(Hash *p_hash, char *c_key) {
+ TYPE type;
+ return (hash_get_ht(p_hash, c_key, &type));
+}
+
+int
+hash_getaddr(Hash *p_hash, char *c_key, HASH_OP OP) {
+ int i_len = strlen(c_key);
+ int i_addr = 0;
+
+ if (i_len > HASH_MKEYLEN) {
+ ERROR(": Key length %d is greater than HASH_MKEYLEN = %d!",
+ i_len, HASH_MKEYLEN);
+ //i_len = HASH_MKEYLEN;
+ }
+
+ for (int i= 0; i < i_len; ++i)
+ i_addr = (i_addr *p_hash->i_size + (int) c_key[i]) % p_hash->i_size;
+
+ switch (OP) {
+ case FREE_ADDR:
+ if (!hash_addrisfree(p_hash,i_addr))
+ return (i_addr);
+ break;
+
+ case OCC_ADDR:
+ if (!hash_addrisocc(p_hash,i_addr, c_key))
+ return (i_addr);
+ break;
+
+ default:
+ return (RET_ERROR);
+ }
+
+ return (hash_nextaddr(p_hash, p_hash->i_size, c_key, i_addr, OP));
+}
+
+RETCODE
+hash_addrisfree(Hash *p_hash, int i_addr) {
+ if (p_hash->p_elems[i_addr].flag == 'f' ||
+ p_hash->p_elems[i_addr].flag == 'm')
+ return (RET_OK);
+
+ return (RET_ERROR);
+}
+
+RETCODE
+hash_addrisocc(Hash *p_hash, int i_addr, char *c_key) {
+ if (p_hash->p_elems[i_addr].flag == 'o' &&
+ !strcmp(p_hash->p_elems[i_addr].c_key, c_key))
+ return (RET_OK);
+
+ return (RET_ERROR);
+}
+
+int
+hash_nextaddr(Hash *p_hash, int i_max_tries, char *c_key, int i_addr,
+ HASH_OP OP) {
+ if ( --i_max_tries < 0 )
+ return (RET_ERROR);
+
+ i_addr = (i_addr + 1) % p_hash->i_size;
+
+ switch (OP) {
+ case FREE_ADDR:
+ if (!hash_addrisfree(p_hash,i_addr))
+ return (i_addr);
+ break;
+
+ case OCC_ADDR:
+ if (!hash_addrisocc(p_hash,i_addr, c_key))
+ return (i_addr);
+ break;
+ }
+
+ return (hash_nextaddr(p_hash, i_max_tries, c_key, i_addr, OP));
+}
+
+void
+hash_print(Hash *p_hash) {
+ printf("hash_print [size:%d,cur:%d] syntax "
+ " (flag[,key][=TYPE[<val>]]):\n -> ",
+ p_hash->i_size,p_hash->i_cur_size);
+
+ for (int i = 0; i < p_hash->i_size; ++i) {
+ switch (p_hash->p_elems[i].flag) {
+ case 'f':
+ printf("(f");
+ break;
+ case 'm':
+ printf("(m,%s=", p_hash->p_elems[i].c_key);
+ hash_print_addrval(p_hash, i);
+ break;
+ case 'o':
+ printf("(o,%s=", p_hash->p_elems[i].c_key);
+ hash_print_addrval(p_hash, i);
+ break;
+ }
+ printf(") ");
+ }
+
+ printf("\n");
+
+}
+
+void
+hash_print_addrval(Hash *p_hash, int i_addr) {
+ switch (p_hash->p_elems[i_addr].type) {
+ case TYPE_NUMBER: {
+ double d_val = *(double *) p_hash->p_elems[i_addr].p_val;
+
+ if ( (int) d_val == d_val )
+ printf("TYPE_NUMBER<%.0f>",d_val);
+ else
+ printf("TYPE_NUMBER<%f>",d_val);
+ }
+ break;
+
+ case TYPE_STRING:
+ printf("TYPE_STRING<%s>", (char *) p_hash->p_elems[i_addr].p_val);
+ break;
+
+ case TYPE_VOIDP:
+ printf("TYPE_VOIDP");
+ break;
+
+ default:
+ printf("UNKNOWN");
+ break;
+ }
+}
+
+RETCODE
+hash_size(Hash *p_hash, int i_size) {
+ if (i_size < p_hash->i_cur_size) {
+ ERROR("The new hash has not enough elements"
+ "to contain the old hash!");
+ }
+
+ HashElem *p_old_elems = p_hash->p_elems;
+ unsigned i_old_size = p_hash->i_size;
+
+ p_hash->p_elems = (HashElem *) calloc(i_size, sizeof(HashElem));
+ p_hash->i_size = i_size;
+ p_hash->i_cur_size = 0;
+
+ /*Set all positions as "free" */
+ for (int i = 0; i < i_size; ++i)
+ p_hash->p_elems[i].flag = 'f';
+
+ for (int i = 0; i < i_old_size; ++i)
+ if (p_old_elems[i].flag == 'o')
+ hash_insert_ht(p_hash, p_old_elems[i].c_key,
+ p_old_elems[i].p_val, p_old_elems[i].type);
+
+ free(p_old_elems);
+ return (RET_OK);
+}
+
+void
+hash_iterate(Hash *p_hash, void (*func)(void *)) {
+ for (int i = 0; i < p_hash->i_size; ++i)
+ if (p_hash->p_elems[i].flag == 'o')
+ (*func) (p_hash->p_elems[i].p_val);
+}
+
+void
+hash_iterate_key(Hash *p_hash, void (*func)(void *, char *)) {
+ for (int i = 0; i < p_hash->i_size; ++i)
+ if (p_hash->p_elems[i].flag == 'o')
+ (*func) (p_hash->p_elems[i].p_val, p_hash->p_elems[i].c_key);
+}
+
+_Bool
+hash_key_exists(Hash *p_hash, char *c_key) {
+ if (hash_get(p_hash, c_key))
+ return (true);
+
+ return (false);
+}
diff --git a/src/data/hash.h b/src/data/hash.h
new file mode 100644
index 0000000..8bf0a49
--- /dev/null
+++ b/src/data/hash.h
@@ -0,0 +1,84 @@
+/*:*
+ *: File: ./src/data/hash.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef HASH_H
+#define HASH_H
+
+#include "../defines.h"
+#include "types.h"
+
+typedef enum HASH_OP_ {
+ FREE_ADDR,
+ OCC_ADDR
+} HASH_OP;
+
+typedef struct {
+ char c_key[HASH_MKEYLEN];
+ char flag;
+ TYPE type;
+ void *p_val;
+} HashElem;
+
+typedef struct {
+ HashElem *p_elems;
+ unsigned i_size;
+ unsigned i_cur_size;
+} Hash;
+
+Hash*hash_new(unsigned i_size);
+void hash_delete(Hash *p_hash);
+RETCODE hash_insert(Hash *p_hash, char *c_key, void *p_val);
+RETCODE hash_insert_ht(Hash *p_hash, char *c_key, void *p_val, TYPE type);
+void* hash_get(Hash *p_hash, char *c_key);
+void* hash_get_ht(Hash *p_hash, char *c_key, TYPE *p_type);
+void* hash_get_ht_addr(Hash *p_hash, char *c_key, TYPE *p_type, int *p_addr);
+void* hash_remove(Hash *p_hash, char *c_key);
+void hash_print(Hash *p_hash);
+void hash_print_addrval(Hash *p_hash, int i_addr);
+RETCODE hash_size(Hash *p_hash, int i_size);
+
+int hash_getaddr(Hash *p_hash, char *c_key, HASH_OP OP);
+RETCODE hash_addrisfree(Hash *p_hash, int i_addr);
+RETCODE hash_addrisocc(Hash *p_hash, int i_addr, char *c_key);
+int hash_nextaddr(Hash *p_hash, int i_max_tries,
+ char *c_key, int i_addr,
+ HASH_OP OP);
+void hash_iterate(Hash *p_hash, void (*func)(void *));
+void hash_iterate_key(Hash *p_hash, void (*func)(void *, char *));
+_Bool hash_key_exists(Hash *p_hash, char *c_key);
+
+#define hash_get_cur_size(hash) hash->i_cur_size
+#define hash_get_size(hash) hash->i_size
+
+#endif
diff --git a/src/data/list.c b/src/data/list.c
new file mode 100644
index 0000000..e641133
--- /dev/null
+++ b/src/data/list.c
@@ -0,0 +1,531 @@
+/*:*
+ *: File: ./src/data/list.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "list.h"
+
+List*
+list_new() {
+ List *p_list = malloc(sizeof(List));
+
+ p_list->p_first = NULL;
+ p_list->p_last = NULL;
+ p_list->i_size = 0;
+
+ return (p_list);
+}
+
+void
+_list_copy_cb(void *p_void1, void *p_cpy) {
+ ListElem *p_elem = p_void1;
+ list_add_back(p_cpy, p_elem->p_val);
+}
+
+List*
+list_copy(List *p_list) {
+ List *p_list_cpy = list_new();
+ list_iterate2(p_list, _list_copy_cb, p_list_cpy);
+ return (p_list_cpy);
+}
+
+List*
+list_copy2(List *p_list, void* (*func)(void *)) {
+ List *p_list_cpy = list_new();
+ ListIterator *p_iter = listiterator_new(p_list);
+
+ while (listiterator_has_next(p_iter))
+ list_add_back(p_list_cpy, (*func) (listiterator_next(p_iter)));
+
+ listiterator_delete(p_iter);
+
+ return (p_list_cpy);
+}
+
+ListElem*
+listelem_new() {
+ ListElem *p_elem = malloc(sizeof(ListElem));
+
+ p_elem->p_next = NULL;
+ p_elem->p_prev = NULL;
+ p_elem->p_val = NULL;
+
+ return (p_elem);
+}
+
+_Bool
+list_empty(List *p_list) {
+ return (p_list->i_size == 0);
+}
+
+void
+list_concat_front(List *p_list1, List *p_list2) {
+ if (!p_list1 || !p_list2 || !p_list2->p_last)
+ return;
+
+ ListElem *p_first = p_list1->p_first;
+
+ if (!p_first) {
+ p_list1->p_first = p_list2->p_first;
+ p_list1->p_last = p_list2->p_last;
+
+ } else {
+ p_list2->p_last->p_next = p_list1->p_first;
+ p_list1->p_first->p_prev = p_list2->p_last;
+ p_list1->p_first = p_list2->p_first;
+ }
+
+ p_list1->i_size += p_list2->i_size;
+ p_list2->i_size = 0;
+ p_list2->p_first = NULL;
+ p_list2->p_last = NULL;
+}
+
+void
+list_concat_back(List *p_list1, List *p_list2) {
+ if (!p_list1 || !p_list2 || !p_list2->p_first)
+ return;
+
+ ListElem *p_last = p_list1->p_last;
+
+ if (!p_last) {
+ p_list1->p_first = p_list2->p_first;
+ p_list1->p_last = p_list2->p_last;
+
+ } else {
+ p_last->p_next = p_list2->p_first;
+ p_list2->p_first->p_prev = p_last;
+ p_list1->p_last = p_list2->p_last;
+ }
+
+ p_list1->i_size += p_list2->i_size;
+ p_list2->i_size = 0;
+ p_list2->p_first = NULL;
+ p_list2->p_last = NULL;
+
+}
+
+void
+list_add_front(List *p_list, void *p_val) {
+ ListElem *p_elem = listelem_new();
+
+ p_elem->p_val = p_val;
+ if (p_list->p_first == NULL) {
+ p_list->p_first = p_elem;
+ p_list->p_last = p_elem;
+
+ } else {
+ p_elem->p_next = p_list->p_first;
+ p_list->p_first->p_prev = p_elem;
+ p_list->p_first = p_elem;
+ }
+
+ ++p_list->i_size;
+}
+
+void
+list_add_back(List *p_list, void *p_val) {
+ ListElem *p_elem = listelem_new();
+
+ p_elem->p_val = p_val;
+ if (p_list->p_last == NULL) {
+ p_list->p_first = p_elem;
+ p_list->p_last = p_elem;
+
+ } else {
+ p_elem->p_prev = p_list->p_last;
+ p_list->p_last->p_next = p_elem;
+ p_list->p_last = p_elem;
+ }
+
+ ++p_list->i_size;
+}
+
+void*
+list_remove_front(List *p_list) {
+ if (list_empty(p_list))
+ return (NULL);
+
+ ListElem *p_elem = p_list->p_first;
+ p_list->p_first = p_elem->p_next;
+
+ if (p_list->p_first)
+ p_list->p_first->p_prev = NULL;
+
+ void *p_val = p_elem->p_val;
+ free(p_elem);
+
+ --p_list->i_size;
+
+ return (p_val);
+}
+
+void*
+list_remove_back(List *p_list) {
+ if (list_empty(p_list))
+ return (NULL);
+
+ ListElem *p_elem = p_list->p_last;
+ p_list->p_last = p_elem->p_prev;
+ p_list->p_last->p_next = NULL;
+
+ void *p_val = p_elem->p_val;
+ free(p_elem);
+
+ --p_list->i_size;
+
+ return (p_val);
+}
+
+void
+list_clear(List *p_list) {
+ for (;!list_empty(p_list); list_remove_front(p_list));
+}
+
+void
+list_clear_and_free_vals(List *p_list) {
+ void *p_void = NULL;
+ for (;!list_empty(p_list); p_void = list_remove_front(p_list))
+ if (p_void)
+ free(p_void);
+}
+
+void
+list_delete(List *p_list) {
+ list_clear(p_list);
+ free(p_list);
+}
+
+void
+list_delete_cb(void *p_list) {
+ list_delete(p_list);
+}
+
+void
+list_delete_and_free_vals(List *p_list) {
+ list_clear_and_free_vals(p_list);
+ free(p_list);
+}
+
+unsigned
+list_size(List *p_list) {
+ return (p_list->i_size);
+}
+
+void
+list_iterate(List *p_list, void (*func)(void *)) {
+ ListElem *p_elem = p_list->p_first;
+
+ while (p_elem) {
+ (*func) (p_elem->p_val);
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+list_iterate2(List *p_list, void (*func)(void *, void *), void *p_void) {
+ ListElem *p_elem = p_list->p_first;
+
+ while (p_elem) {
+ (*func) (p_elem->p_val, p_void);
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+list_iterate2_ptr(List *p_list, void (*func)(void *, void *), void *p_void) {
+ ListElem *p_elem = p_list->p_first;
+
+ while (p_elem) {
+ (*func) (&p_elem->p_val, p_void);
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+list_iterate3(List *p_list,
+ void (*func)(void *, void *, void *),
+ void *p_void1, void *p_void2) {
+ ListElem *p_elem = p_list->p_first;
+
+ while (p_elem) {
+ (*func) (p_elem->p_val, p_void1, p_void2);
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+list_iterate3_ptr(List *p_list,
+ void (*func)(void *, void *, void *),
+ void *p_void1, void *p_void2) {
+ ListElem *p_elem = p_list->p_first;
+
+ while (p_elem) {
+ (*func) (&p_elem->p_val, p_void1, p_void2);
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+list_remove_elem(List *p_list, ListElem *p_elem_remove) {
+ ListElem *p_elem = p_list->p_first;
+
+ if (p_elem == p_elem_remove) {
+ p_list->p_first = p_elem->p_next;
+ p_list->p_first->p_prev = NULL;
+ --p_list->i_size;
+ return;
+ }
+
+ while ((p_elem = p_elem->p_next)) {
+ if (p_elem == p_elem_remove) {
+ ListElem *p_prev = p_elem->p_prev;
+ ListElem *p_next = p_elem->p_next;
+
+ if (p_next) {
+ p_prev->p_next = p_next;
+ p_next->p_prev = p_prev;
+
+ } else {
+ p_prev->p_next = NULL;
+ p_list->p_last = p_prev;
+ }
+
+ --p_list->i_size;
+ free(p_elem_remove);
+ return;
+ }
+ }
+}
+
+ListIterator*
+listiterator_new(List *p_list) {
+ if (!p_list)
+ return (NULL);
+
+ ListIterator *p_iter = malloc(sizeof(ListIterator));
+
+ p_iter->p_cur = p_list->p_first;
+ p_iter->b_reverse = false;
+ p_iter->func = NULL;
+
+ return (p_iter);
+}
+
+ListIterator*
+listiterator_new_from_elem(ListElem *p_listelem) {
+ if (!p_listelem)
+ return (NULL);
+
+ ListIterator *p_iter = malloc(sizeof(ListIterator));
+
+ p_iter->p_cur = p_listelem;
+ p_iter->b_reverse = false;
+ p_iter->func = NULL;
+
+ return (p_iter);
+}
+
+ListIterator*
+listiterator_new_from_elem_reverse(ListElem *p_listelem) {
+ ListIterator *p_iter = listiterator_new_from_elem(p_listelem);
+
+ if (!p_iter)
+ return (NULL);
+
+ p_iter->b_reverse = true;
+
+ return (p_iter);
+}
+
+ListIterator*
+listiterator_new_reverse(List *p_list) {
+ if (!p_list)
+ return (NULL);
+
+ ListIterator *p_iter = listiterator_new(p_list);
+
+ p_iter->p_cur = p_list->p_last;
+ p_iter->b_reverse = true;
+
+ return (p_iter);
+}
+
+void
+listiterator_delete(ListIterator *p_iter) {
+ if (p_iter)
+ free(p_iter);
+}
+
+void*
+listiterator_next(ListIterator *p_iter) {
+ if (p_iter->p_cur) {
+ void *p_ret = p_iter->p_cur->p_val;
+
+ if (p_iter->b_reverse)
+ p_iter->p_cur = p_iter->p_cur->p_prev;
+
+ else
+ p_iter->p_cur = p_iter->p_cur->p_next;
+
+ if (p_iter->func)
+ return ((*p_iter->func) (p_ret));
+
+ else
+ return (p_ret);
+ }
+
+ return (NULL);
+}
+
+void*
+listiterator_prev(ListIterator *p_iter) {
+ if (p_iter->p_cur) {
+ void *p_ret = p_iter->p_cur->p_val;
+
+ if (!p_iter->b_reverse)
+ p_iter->p_cur = p_iter->p_cur->p_prev;
+
+ else
+ p_iter->p_cur = p_iter->p_cur->p_next;
+
+ if (p_iter->func)
+ return ((*p_iter->func) (p_ret));
+
+ else
+ return (p_ret);
+ }
+
+ return (NULL);
+}
+
+void*
+listiterator_current(ListIterator *p_iter) {
+ if (p_iter->p_cur)
+ return (p_iter->p_cur->p_val);
+
+ return (NULL);
+}
+
+ListElem*
+listiterator_current_elem(ListIterator *p_iter) {
+ if (p_iter->p_cur)
+ return (p_iter->p_cur);
+
+ return (NULL);
+}
+
+ListElem*
+listiterator_prev_elem(ListIterator *p_iter) {
+ if (p_iter->p_cur) {
+ if (!p_iter->b_reverse)
+ return (p_iter->p_cur->p_prev);
+
+ else
+ return (p_iter->p_cur->p_next);
+ }
+
+ return (NULL);
+}
+
+void*
+listiterator_end(ListIterator *p_iter) {
+ void *p_ret = NULL;
+
+ while (listiterator_has_next(p_iter))
+ p_ret = listiterator_next(p_iter);
+
+ return (p_ret);
+}
+
+_Bool
+listiterator_current_elem_equals(ListIterator *p_iter, ListElem *p_listelem) {
+ if (!p_iter || !p_listelem)
+ return (false);
+
+ ListElem *p_listelem_current = listiterator_current_elem(p_iter);
+
+ if (!p_listelem_current)
+ return (false);
+
+ else if (p_listelem_current->p_next != p_listelem->p_next)
+ return (false);
+
+ else if (p_listelem_current->p_prev != p_listelem->p_prev)
+ return (false);
+
+ else if (p_listelem_current->p_val != p_listelem->p_val)
+ return (false);
+
+ return (true);
+}
+
+ListElem*
+listiterator_next_elem(ListIterator *p_iter) {
+ if (p_iter->p_cur) {
+ ListElem *p_ret = p_iter->p_cur;
+
+ p_iter->p_cur = p_iter->b_reverse ?
+ p_iter->p_cur->p_prev : p_iter->p_cur->p_next;
+
+ return (p_ret);
+ }
+
+ return (NULL);
+}
+
+_Bool
+listiterator_has_next(ListIterator *p_iter) {
+ return (p_iter->p_cur != NULL ? true : false);
+}
+
+
+ListIteratorState*
+listiterator_get_state(ListIterator *p_iter) {
+ ListIteratorState *p_state = malloc(sizeof(ListIteratorState));
+
+ p_state->p_cur = p_iter->p_cur;
+ p_state->b_reverse = p_iter->b_reverse;
+
+ return (p_state);
+}
+
+void
+listiterator_set_state(ListIterator *p_iter, ListIteratorState *p_state) {
+ p_iter->p_cur = p_state->p_cur;
+ p_iter->b_reverse = p_state->b_reverse;
+}
+
+void
+listiteratorstate_delete(ListIteratorState *p_state) {
+ free(p_state);
+}
diff --git a/src/data/list.h b/src/data/list.h
new file mode 100644
index 0000000..fb6a9b8
--- /dev/null
+++ b/src/data/list.h
@@ -0,0 +1,118 @@
+/*:*
+ *: File: ./src/data/list.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef LIST_H
+#define LIST_H
+
+#include <stdlib.h>
+
+#include "../defines.h"
+
+#define list_first(l) l->p_first->p_val
+#define list_last(l) l->p_last->p_val
+#define listiterator_set_callback(i,cb) i->func = cb
+
+typedef struct ListElem_ {
+ struct ListElem_ *p_next;
+ struct ListElem_ *p_prev;
+ void *p_val;
+} ListElem;
+
+typedef struct {
+ ListElem *p_first;
+ ListElem *p_last;
+ unsigned i_size;
+} List;
+
+typedef struct {
+ ListElem *p_cur;
+ _Bool b_reverse;
+ void* (*func)(void *);
+} ListIterator;
+
+typedef struct {
+ ListElem *p_cur;
+ _Bool b_reverse;
+} ListIteratorState;
+
+List *list_new();
+List *list_copy(List *p_list);
+List *list_copy2(List *p_list, void* (*func)(void *));
+ListElem *listelem_new();
+_Bool list_empty(List *p_list);
+void list_concat_front(List *p_list1, List *p_list2);
+void list_concat_back(List *p_list1, List *p_list2);
+void list_add_front(List *p_list, void *p_val);
+void list_add_back(List *p_list, void *p_val);
+void *list_remove_front(List *p_list);
+void *list_remove_back(List *p_list);
+void list_clear(List *p_list);
+void list_clear_and_free_vals(List *p_list);
+void list_delete(List *p_list);
+void list_delete_cb(void *p_list);
+void list_delete_and_free_vals(List *p_list);
+unsigned list_size(List *p_list);
+void list_iterate(List *p_list, void (*func)(void *));
+void list_iterate2_ptr(List *p_list,
+ void (*func)(void *, void *),
+ void *p_void);
+void list_iterate2(List *p_list,
+ void (*func)(void *, void *),
+ void *p_void);
+void list_iterate3(List *p_list,
+ void (*func)(void *, void *, void *),
+ void *p_void1, void *p_void2);
+void list_iterate3_ptr(List *p_list,
+ void (*func)(void *, void *, void *),
+ void *p_void1, void *p_void2);
+ListIterator* listiterator_new(List *p_list);
+ListIterator* listiterator_new_from_elem(ListElem *p_listelem);
+ListIterator* listiterator_new_from_elem_reverse(ListElem *p_listelem);
+ListIterator* listiterator_new_reverse(List *p_list);
+void listiterator_delete(ListIterator *p_iter);
+void* listiterator_next(ListIterator *p_iter);
+void* listiterator_prev(ListIterator *p_iter);
+void* listiterator_current(ListIterator *p_iter);
+ListElem* listiterator_current_elem(ListIterator *p_iter);
+ListElem* listiterator_prev_elem(ListIterator *p_iter);
+void* listiterator_end(ListIterator *p_iter);
+_Bool listiterator_has_next(ListIterator *p_iter);
+_Bool listiterator_current_elem_equals(ListIterator *p_iter, ListElem *p_listelem);
+ListElem* listiterator_next_elem(ListIterator *p_iter);
+void list_remove_elem(List *p_list, ListElem *p_elem_remove);
+ListIteratorState* listiterator_get_state(ListIterator *p_iter);
+void listiterator_set_state(ListIterator *p_iter, ListIteratorState *p_state);
+void listiteratorstate_delete(ListIteratorState *p_state);
+
+#endif
diff --git a/src/data/map.c b/src/data/map.c
new file mode 100644
index 0000000..3c95dc2
--- /dev/null
+++ b/src/data/map.c
@@ -0,0 +1,289 @@
+/*:*
+ *: File: ./src/data/map.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "map.h"
+
+Map*
+map_new(int i_max_size) {
+ return (map_new_named(i_max_size, "noname"));
+}
+
+Map*
+map_new_named(int i_max_size, char *c_name) {
+ Map *p_map = malloc(sizeof(Map));
+
+ p_map->c_name = c_name;
+ p_map->pc_keys = calloc(i_max_size, sizeof(char*));
+ p_map->pp_vals = calloc(i_max_size, sizeof(void*));
+
+ for (int i = 0; i < i_max_size; ++i) {
+ p_map->pc_keys[i] = NULL;
+ p_map->pp_vals[i] = NULL;
+ }
+
+ p_map->i_size = 0;
+ p_map->i_max_size = i_max_size;
+
+ return (p_map);
+}
+
+_Bool
+map_empty(Map *p_map) {
+ return (p_map->i_size == 0);
+}
+
+_Bool
+map_full(Map *p_map) {
+ return (p_map->i_size == p_map->i_max_size);
+}
+
+int
+map_next_free_addr(Map *p_map) {
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] == NULL)
+ return (i);
+
+ ERROR("No free space left in the map (%s)", p_map->c_name);
+
+ // This point should not be reached!
+ return (0);
+}
+
+_Bool
+map_insert(Map *p_map, char *c_key, void *p_val) {
+ int i_free_addr = map_next_free_addr(p_map);
+ int i_len = strlen(c_key);
+
+ p_map->pc_keys[i_free_addr] = STR_NEW(i_len+1);
+ strncpy(p_map->pc_keys[i_free_addr], c_key, i_len);
+ p_map->pp_vals[i_free_addr] = p_val;
+
+ ++p_map->i_size;
+ return (true);
+}
+
+_Bool
+map_insert2(Map *p_map, char *c_key1, char *c_key2, void *p_val) {
+ char c_key[HASH_MKEYLEN];
+ sprintf(c_key, "%s%s%s", c_key1, SEP, c_key2);
+ return (map_insert(p_map, c_key, p_val));
+}
+
+_Bool
+map_insert_if_not_exists(Map *p_map, char *c_key, void *p_val) {
+ void *p_void = map_get(p_map, c_key);
+
+ if (p_void)
+ return (false);
+
+ return (map_insert(p_map, c_key, p_val));
+
+ return (true);
+}
+
+void
+map_remove(Map *p_map, char *c_key) {
+ if (map_empty(p_map))
+ return;
+
+ int i_index = map_get_addr(p_map, c_key);
+ if (i_index < 0)
+ return;
+
+ free(p_map->pc_keys[i_index]);
+ p_map->pc_keys[i_index] = NULL;
+ p_map->pp_vals[i_index] = NULL;
+ --p_map->i_size;
+}
+
+void*
+map_get(Map *p_map, char *c_key) {
+ if (map_empty(p_map))
+ return (NULL);
+
+ int i_index = map_get_addr(p_map, c_key);
+ return (i_index >= 0 ? p_map->pp_vals[i_index] : NULL);
+}
+
+void*
+map_get2(Map *p_map, char *c_key1, char *c_key2) {
+ char c_key[HASH_MKEYLEN];
+ sprintf(c_key, "%s%s%s", c_key1, SEP, c_key2);
+ return (map_get(p_map, c_key));
+}
+
+
+_Bool
+map_exists(Map *p_map, char *c_key) {
+ if (map_empty(p_map))
+ return (false);
+
+ int i_index = map_get_addr(p_map, c_key);
+ return (i_index >= 0 ? true : false);
+}
+
+_Bool
+map_exists2(Map *p_map, char *c_key1, char *c_key2) {
+ if (map_empty(p_map))
+ return (false);
+
+ char c_key[HASH_MKEYLEN];
+ sprintf(c_key, "%s%s%s:", c_key1, SEP, c_key2);
+
+ int i_index = map_get_addr(p_map, c_key);
+ return i_index >= 0 ? true : false;
+}
+
+char*
+map_get_key(Map *p_map, void *p_val) {
+ if (map_empty(p_map))
+ return (NULL);
+
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if ((unsigned) p_map->pp_vals[i] == (unsigned) p_val)
+ return (p_map->pc_keys[i]);
+
+ return (NULL);
+}
+
+int
+map_get_addr(Map *p_map, char *c_key) {
+ if (map_empty(p_map))
+ return (-1);
+
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] != NULL && strcmp(p_map->pc_keys[i], c_key) == 0)
+ return (i);
+
+ return (-1);
+}
+
+void
+map_clear(Map *p_map) {
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] != NULL) {
+ free(p_map->pc_keys[i]);
+ p_map->pc_keys[i] = NULL;
+ p_map->pp_vals[i] = NULL;
+ }
+
+ p_map->i_size = 0;
+}
+
+void
+map_clear_and_free_vals(Map *p_map) {
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] != NULL) {
+ free(p_map->pc_keys[i]);
+
+ if (p_map->pp_vals[i])
+ free(p_map->pp_vals[i]);
+
+ p_map->pc_keys[i] = NULL;
+ p_map->pp_vals[i] = NULL;
+ }
+
+ p_map->i_size = 0;
+}
+
+void
+map_delete(Map *p_map) {
+ map_clear(p_map);
+ free(p_map);
+}
+
+void
+map_delete_and_free_vals(Map *p_map) {
+ map_clear_and_free_vals(p_map);
+ free(p_map);
+}
+
+void
+map_print(Map *p_map) {
+ printf("Map<size=%d, max_size=%d>:",
+ map_get_size(p_map), map_get_max_size(p_map));
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] != NULL)
+ printf("(%d,%s)", i, p_map->pc_keys[i]);
+ puts("");
+}
+
+void
+map_iterate(Map *p_map, void (*func) (void *)) {
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] != NULL)
+ (*func) (p_map->pp_vals[i]);
+}
+
+void
+map_iterate_keys(Map *p_map, void (*func) (void *, char *)) {
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] != NULL)
+ (*func) (p_map->pp_vals[i], p_map->pc_keys[i]);
+}
+
+void
+map_iterate2(Map *p_map, void (*func) (void *, void *), void *p_void) {
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] != NULL)
+ (*func) (p_map->pp_vals[i], p_void);
+}
+
+void
+map_iterate2_keys(Map *p_map,
+ void (*func) (void *, void *, char *),
+ void *p_void) {
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] != NULL)
+ (*func) (p_map->pp_vals[i], p_void, p_map->pc_keys[i]);
+}
+
+void
+map_iterate3(Map *p_map,
+ void (*func) (void *, void *, void *),
+ void *p_void1, void *p_void2) {
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] != NULL)
+ (*func) (p_map->pp_vals[i], p_void1, p_void2);
+}
+
+void
+map_iterate3_keys(Map *p_map,
+ void (*func) (void *, void *, void *, char *),
+ void *p_void1, void *p_void2) {
+ for (int i = 0; i < p_map->i_max_size; ++i)
+ if (p_map->pc_keys[i] != NULL)
+ (*func) (p_map->pp_vals[i], p_void1, p_void2, p_map->pc_keys[i]);
+}
+
diff --git a/src/data/map.h b/src/data/map.h
new file mode 100644
index 0000000..c01dbe1
--- /dev/null
+++ b/src/data/map.h
@@ -0,0 +1,88 @@
+/*:*
+ *: File: ./src/data/map.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef MAP_H
+#define MAP_H
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "../defines.h"
+#define SEP "::"
+
+typedef struct {
+ char *c_name;
+ char **pc_keys;
+ void **pp_vals;
+ int i_size;
+ int i_max_size;
+} Map;
+
+Map *map_new(int i_max_size);
+Map *map_new_named(int i_max_size, char *c_name);
+_Bool map_empty(Map *p_map);
+_Bool map_full(Map *p_map);
+int map_next_free_addr(Map *p_map);
+_Bool map_insert(Map *p_map, char *c_key, void *p_val);
+_Bool map_insert2(Map *p_map, char *c_key1, char *c_key2, void *p_val);
+_Bool map_insert_if_not_exists(Map *p_map, char *c_key, void *p_val);
+void map_remove(Map *p_map, char *c_key);
+void *map_get(Map *p_map, char *c_key);
+void *map_get2(Map *p_map, char *c_key1, char *c_key2);
+_Bool map_exists(Map *p_map, char *c_key);
+_Bool map_exists2(Map *p_map, char *c_key1, char *c_key2);
+char *map_get_key(Map *p_map, void *p_val);
+int map_get_addr(Map *p_map, char *c_key);
+void map_clear(Map *p_map);
+void map_clear_and_free_vals(Map *p_map);
+void map_delete(Map *p_map);
+void map_delete_and_free_vals(Map *p_map);
+void map_print(Map *p_map);
+void map_iterate(Map *p_map, void (*func) (void *));
+void map_iterate_keys(Map *p_map, void (*func) (void *, char *));
+void map_iterate2(Map *p_map, void (*func) (void *, void *), void *p_void);
+void map_iterate2_keys(Map *p_map,
+ void (*func) (void *, void *, char *),
+ void *p_void);
+void map_iterate3(Map *p_map,
+ void (*func) (void *, void *, void *),
+ void *p_void1, void *p_void2);
+void map_iterate3_keys(Map *p_map,
+ void (*func) (void *, void *, void *, char *),
+ void *p_void1, void *p_void2);
+
+#define map_get_size(map) map->i_size
+#define map_get_max_size(map) map->i_max_size
+
+#endif
diff --git a/src/data/queue.c b/src/data/queue.c
new file mode 100644
index 0000000..63987a0
--- /dev/null
+++ b/src/data/queue.c
@@ -0,0 +1,210 @@
+/*:*
+ *: File: ./src/data/queue.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "queue.h"
+
+#include <stdlib.h>
+
+Queue*
+queue_new() {
+ Queue *p_queue = (Queue *) malloc(sizeof(Queue));
+
+ p_queue->p_first = 0;
+ p_queue->p_last = 0;
+ p_queue->i_size = 0;
+
+ return p_queue;
+}
+
+QueueElem*
+queueelem_new() {
+ return queueelem_new_t(TYPE_UNKNOWN);
+}
+
+QueueElem*
+queueelem_new_t(TYPE type) {
+ QueueElem *p_elem = (QueueElem *) malloc(sizeof(QueueElem));
+
+ p_elem->p_next = 0;
+ p_elem->p_val = 0;
+ p_elem->type = type;
+
+ return p_elem;
+}
+
+_Bool
+queue_empty(Queue *p_queue) {
+ if (p_queue == NULL)
+ return 0;
+
+ return p_queue->i_size == 0;
+}
+
+void
+queue_push(Queue *p_queue, void *p_val) {
+ queue_push_t(p_queue, p_val, TYPE_UNKNOWN);
+}
+
+void
+queue_push_t(Queue *p_queue, void *p_val, TYPE type) {
+ QueueElem *p_elem = queueelem_new_t(type);
+ p_elem->p_val = p_val;
+
+ if (0 == p_queue->i_size++)
+ p_queue->p_first = p_elem;
+ else
+ p_queue->p_last->p_next = p_elem;
+
+ p_queue->p_last = p_elem;
+}
+
+void*
+queue_pop(Queue *p_queue) {
+ TYPE type;
+ return queue_pop_t(p_queue, &type);
+}
+
+void*
+queue_pop_t(Queue *p_queue, TYPE *p_type) {
+ if (queue_empty(p_queue))
+ return 0;
+
+ QueueElem *p_elem = p_queue->p_first;
+ p_queue->p_first = p_elem->p_next;
+
+ --p_queue->i_size;
+
+ void *p_ret = p_elem->p_val;
+ *p_type = p_elem->type;
+ free(p_elem);
+ return p_ret;
+}
+
+void
+queue_clear(Queue *p_queue) {
+ for (;!queue_empty(p_queue); queue_pop(p_queue));
+}
+
+void
+queue_delete(Queue *p_queue) {
+ queue_clear(p_queue);
+ free(p_queue);
+}
+
+unsigned
+queue_size(Queue *p_queue) {
+ return p_queue->i_size;
+}
+
+void
+queue_iterate(Queue *p_queue, void (*func)(void *)) {
+ QueueElem *p_elem = p_queue->p_first;
+ while (p_elem) {
+ if (p_elem->p_val)
+ (*func) (p_elem->p_val);
+
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+queue_iterate_t(Queue *p_queue, void (*func)(void *, TYPE)) {
+ QueueElem *p_elem = p_queue->p_first;
+ while (p_elem) {
+ if (p_elem->p_val)
+ (*func) (p_elem->p_val, p_elem->type);
+
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+queue_iterate_tl(Queue *p_queue, void (*func)(void *, TYPE, _Bool)) {
+ QueueElem *p_elem = p_queue->p_first;
+ while (p_elem) {
+ if (p_elem->p_val)
+ (*func) (p_elem->p_val, p_elem->type, p_elem->p_next == NULL);
+
+ p_elem = p_elem->p_next;
+ }
+}
+
+QueueIter*
+queueiter_new(Queue *p_queue) {
+ QueueIter *p_iter =
+ (QueueIter *) malloc(sizeof(QueueIter));
+
+ p_iter->p_current = NULL;
+ p_iter->p_next = p_queue->p_first;
+ p_iter->i_left = queue_size(p_queue);
+ p_iter->p_queue = p_queue;
+
+ return p_iter;
+}
+
+void
+queueiter_delete(QueueIter *p_iter) {
+ free(p_iter);
+}
+
+void*
+queueiter_next(QueueIter *p_iter) {
+ TYPE type;
+ return queueiter_next_t(p_iter, &type);
+}
+
+void*
+queueiter_next_t(QueueIter *p_iter, TYPE *p_type) {
+ if (p_iter->p_next == NULL)
+ return NULL;
+
+ void *p_ret = p_iter->p_next->p_val;
+ *p_type = p_iter->p_next->type;
+ p_iter->p_current = p_iter->p_next;
+ p_iter->p_next = p_iter->p_next->p_next;
+ --p_iter->i_left;
+
+ return p_ret;
+}
+
+unsigned
+queueiter_left(QueueIter *p_iter) {
+ return p_iter->i_left;
+}
+
+Queue*
+queueiter_queue(QueueIter *p_iter) {
+ return p_iter->p_queue;
+}
+
diff --git a/src/data/queue.h b/src/data/queue.h
new file mode 100644
index 0000000..227ce29
--- /dev/null
+++ b/src/data/queue.h
@@ -0,0 +1,81 @@
+/*:*
+ *: File: ./src/data/queue.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef QUEUE_H
+#define QUEUE_H
+
+#include "types.h"
+
+typedef struct QueueElem_ {
+ struct QueueElem_ *p_next;
+ void *p_val;
+ TYPE type;
+} QueueElem;
+
+typedef struct {
+ QueueElem *p_first;
+ QueueElem *p_last;
+ unsigned i_size;
+} Queue;
+
+typedef struct {
+ unsigned i_left;
+ Queue *p_queue;
+ QueueElem *p_current;
+ QueueElem *p_next;
+} QueueIter;
+
+Queue *queue_new();
+QueueElem *queueelem_new();
+QueueElem *queueelem_new_t(TYPE type);
+_Bool queue_empty(Queue *p_queue);
+void queue_push(Queue *p_queue, void *p_val);
+void queue_push_t(Queue *p_queue, void *p_val, TYPE type);
+void *queue_pop(Queue *p_queue);
+void *queue_pop_t(Queue *p_queue, TYPE *p_type);
+void queue_clear(Queue *p_queue);
+void queue_delete(Queue *p_queue);
+unsigned queue_size(Queue *p_queue);
+void queue_iterate(Queue *p_queue, void (*func)(void *));
+void queue_iterate_t(Queue *p_queue, void (*func)(void *, TYPE));
+void queue_iterate_tl(Queue *p_queue, void (*func)(void *, TYPE, _Bool));
+
+QueueIter *queueiter_new(Queue *p_queue);
+void queueiter_delete(QueueIter *p_iter);
+void *queueiter_next(QueueIter *p_iter);
+void *queueiter_next_t(QueueIter *p_iter, TYPE *p_type);
+unsigned queueiter_left(QueueIter *p_iter);
+Queue *queueiter_queue(QueueIter *p_iter);
+
+#endif
diff --git a/src/data/stack.c b/src/data/stack.c
new file mode 100644
index 0000000..e6a60a4
--- /dev/null
+++ b/src/data/stack.c
@@ -0,0 +1,271 @@
+/*:*
+ *: File: ./src/data/stack.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "stack.h"
+
+#include "../defines.h"
+
+Stack*
+stack_new() {
+ Stack *p_stack = (Stack *) malloc(sizeof(Stack));
+
+ p_stack->p_first = p_stack->p_last = NULL;
+ p_stack->i_size = 0;
+
+ return (p_stack);
+}
+
+StackElem*
+stackelem_new() {
+ StackElem *p_elem = (StackElem *) malloc(sizeof(StackElem));
+
+ p_elem->p_next = NULL;
+ p_elem->p_val = NULL;
+
+ return (p_elem);
+}
+
+_Bool
+stack_empty(Stack *p_stack) {
+ return (p_stack->i_size == 0);
+}
+
+void
+stack_push(Stack *p_stack, void *p_val) {
+ StackElem *p_elem = stackelem_new();
+
+ p_elem->p_val = p_val;
+ p_elem->p_next = p_stack->p_first;
+ p_stack->p_first = p_elem;
+
+ if (p_stack->p_last == NULL)
+ p_stack->p_last = p_stack->p_first;
+
+ ++p_stack->i_size;
+}
+
+void*
+stack_pop(Stack *p_stack) {
+ if (stack_empty(p_stack))
+ return (NULL);
+
+ StackElem *p_elem = p_stack->p_first;
+ p_stack->p_first = p_elem->p_next;
+
+ void *p_val = p_elem->p_val;
+ free(p_elem);
+ --p_stack->i_size;
+
+ if (p_stack->i_size == 0)
+ p_stack->p_last = NULL;
+
+ return (p_val);
+}
+
+void*
+stack_top(Stack *p_stack) {
+ if (stack_empty(p_stack))
+ return (NULL);
+
+ return (p_stack->p_first->p_val);
+}
+
+void
+stack_clear(Stack *p_stack) {
+ for (;!stack_empty(p_stack); stack_pop(p_stack));
+}
+
+void
+stack_delete(Stack *p_stack) {
+ stack_clear(p_stack);
+ free(p_stack);
+}
+
+void
+stack_delete_and_free(Stack *p_stack) {
+ for (;!stack_empty(p_stack); free(stack_pop(p_stack)));
+ stack_delete(p_stack);
+}
+
+unsigned
+stack_size(Stack *p_stack) {
+ if (!p_stack)
+ return (0);
+
+ return (p_stack->i_size);
+}
+
+void
+stack_merge(Stack *p_stack, Stack *p_stack_merge) {
+ if (stack_empty(p_stack_merge))
+ return;
+
+ if (stack_empty(p_stack)) {
+ p_stack->p_first = p_stack_merge->p_first;
+ p_stack->p_last = p_stack_merge->p_last;
+ p_stack->i_size = p_stack_merge->i_size;
+
+ } else {
+ StackElem *p_old_first = p_stack->p_first;
+
+ p_stack->p_first = p_stack_merge->p_first;
+ p_stack_merge->p_last->p_next = p_old_first;
+ p_stack->i_size += p_stack_merge->i_size;
+ }
+
+ p_stack_merge->p_first = p_stack_merge->p_last = NULL;
+ p_stack_merge->i_size = 0;
+}
+
+void
+stack_concat(Stack *p_stack, Stack *p_stack_concat) {
+ if (stack_empty(p_stack_concat))
+ return;
+
+ Stack *p_stack_tmp = stack_new();
+
+ StackIterator *p_iter = stackiterator_new(p_stack_concat);
+
+ while (stackiterator_has_next(p_iter))
+ stack_push(p_stack_tmp, stackiterator_next(p_iter));
+
+ stackiterator_delete(p_iter);
+
+ while (!stack_empty(p_stack_tmp))
+ stack_push(p_stack, stack_pop(p_stack_tmp));
+
+ stack_delete(p_stack_tmp);
+}
+
+void
+stack_iterate(Stack *p_stack, void (*func)(void *p_void)) {
+ if (!p_stack)
+ return;
+
+ StackElem *p_elem = p_stack->p_first;
+
+ while (p_elem) {
+ (*func)(p_elem->p_val);
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+stack_iterate2(Stack *p_stack, void (*func)(void *p_void, void *p_void2),
+ void *p_void_arg) {
+ if (!p_stack)
+ return;
+
+ StackElem *p_elem = p_stack->p_first;
+
+ while (p_elem) {
+ (*func)(p_elem->p_val, p_void_arg);
+ p_elem = p_elem->p_next;
+ }
+}
+
+void
+stack_iterate_level(Stack *p_stack, void (*func)(void *p_void,
+ int i_level)) {
+ if (!p_stack)
+ return;
+
+ StackElem *p_elem = p_stack->p_first;
+
+ int i_level = 0;
+ while (p_elem) {
+ (*func)(p_elem->p_val, i_level++);
+ p_elem = p_elem->p_next;
+ }
+}
+
+StackIterator*
+stackiterator_new(Stack *p_stack) {
+ StackIterator *p_iter = malloc(sizeof(StackIterator));
+
+ p_iter->p_current = p_stack->p_first;
+ p_iter->p_prev = NULL;
+
+ return (p_iter);
+}
+
+void
+stackiterator_delete(StackIterator *p_iter) {
+ free(p_iter);
+}
+
+void*
+stackiterator_next(StackIterator *p_iter) {
+ if (!p_iter)
+ return (NULL);
+
+ StackElem *p_elem = p_iter->p_current;
+
+ if (!p_elem)
+ return (NULL);
+
+ p_iter->p_prev = p_iter->p_current;
+ p_iter->p_current = p_elem->p_next;
+
+ return (p_elem->p_val);
+}
+
+_Bool
+stackiterator_has_next(StackIterator *p_iter) {
+ return (p_iter->p_current ? true : false);
+}
+
+_Bool
+stackiterator_remove_prev(StackIterator *p_iter) {
+ StackElem *p_prev = p_iter->p_prev;
+
+ if (p_prev == NULL)
+ return (false);
+
+ StackElem *p_next = p_prev->p_next;
+
+ if (p_next == NULL)
+ return (false);
+
+ p_prev->p_val = p_next->p_val;
+ p_prev->p_next = p_next->p_next;
+
+
+ free(p_next);
+
+ p_iter->p_current = p_prev;
+ p_iter->p_prev = NULL;
+
+ return (true);
+}
diff --git a/src/data/stack.h b/src/data/stack.h
new file mode 100644
index 0000000..395dd32
--- /dev/null
+++ b/src/data/stack.h
@@ -0,0 +1,79 @@
+/*:*
+ *: File: ./src/data/stack.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef STACK_H
+#define STACK_H
+
+#include <stdlib.h>
+
+typedef struct StackElem_ {
+ struct StackElem_ *p_next;
+ void *p_val;
+} StackElem;
+
+typedef struct {
+ StackElem *p_first;
+ StackElem *p_last; // Only needed for stack_merge
+ unsigned i_size;
+} Stack;
+
+typedef struct {
+ StackElem *p_current;
+ StackElem *p_prev;
+} StackIterator;
+
+Stack *stack_new();
+StackElem *stackelem_new();
+_Bool stack_empty(Stack *p_stack);
+void stack_iterate(Stack *p_stack, void (*func)(void *p_void));
+void stack_iterate2(Stack *p_stack, void (*func)(void *p_void, void *p_void2),
+ void *p_void_arg);
+void stack_iterate_level(Stack *p_stack, void (*func)(void *p_void,
+ int i_level));
+void stack_push(Stack *p_stack, void *p_val);
+void *stack_pop(Stack *p_stack);
+void *stack_top(Stack *p_stack);
+void stack_clear(Stack *p_stack);
+void stack_delete(Stack *p_stack);
+void stack_delete_and_free(Stack *p_stack);
+unsigned stack_size(Stack *p_stack);
+void stack_merge(Stack *p_stack, Stack *p_stack_merge);
+void stack_concat(Stack *p_stack, Stack *p_stack_concat);
+StackIterator* stackiterator_new(Stack *p_stack);
+void stackiterator_delete(StackIterator *p_iter);
+_Bool stackiterator_has_next(StackIterator *p_iter);
+void* stackiterator_next(StackIterator *p_iter);
+_Bool stackiterator_remove_prev(StackIterator *p_iter);
+
+#endif
diff --git a/src/data/tree.c b/src/data/tree.c
new file mode 100644
index 0000000..c55dcf1
--- /dev/null
+++ b/src/data/tree.c
@@ -0,0 +1,215 @@
+/*:*
+ *: File: ./src/data/tree.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "tree.h"
+
+Tree*
+tree_new() {
+ Tree *p_tree = malloc(sizeof(Tree));
+
+ p_tree->p_treenode_root = NULL;
+
+ return p_tree;
+}
+
+
+void
+tree_delete(Tree *p_tree) {
+ if (!p_tree)
+ return;
+
+ if (p_tree->p_treenode_root)
+ treenode_delete(p_tree->p_treenode_root);
+
+ free(p_tree);
+}
+
+void _tree_print(TreeNode *p_treenode, int i_indent);
+
+void _indent(int i_indent) {
+ for (int i = 0; i < i_indent; ++i)
+ if (i % TREE_PRINT_INDENT)
+ printf(" ");
+ else
+ printf("|");
+}
+
+void
+_tree_print_cb2(void *p_void, void *p_indent) {
+ _tree_print(p_void, (int) p_indent);
+}
+
+void
+_tree_print_cb(void *p_void, void *p_indent) {
+ TreeNode *ptn = p_void;
+ _indent((int) p_indent);
+
+ printf(" %d", (int) treenode_get_val(ptn));
+}
+
+void
+_tree_print(TreeNode *p_treenode, int i_indent) {
+ //TokenType tt = (TokenType)treenode_get_val(p_treenode);
+
+ //_indent(i_indent);
+ //printf("%s:", tt_get_name(tt));
+
+ array_iterate2(p_treenode->p_array_childs, _tree_print_cb, (void*) 0);
+
+ printf("\nTree ");
+
+ array_iterate2(p_treenode->p_array_childs,
+ _tree_print_cb2,
+ (void*) (i_indent + TREE_PRINT_INDENT));
+}
+
+void
+tree_print(Tree *p_tree) {
+ if (!p_tree)
+ return;
+
+ printf("\nTree ");
+ _tree_print(tree_get_root(p_tree), 0);
+ printf("\n");
+}
+
+TreeNode*
+treenode_new(void *p_val) {
+ return treenode_new2(p_val, NULL);
+}
+
+TreeNode*
+treenode_new2(void *p_val, void *p_val2) {
+ TreeNode *p_treenode = malloc(sizeof(TreeNode));
+
+ p_treenode->tnt = IS_LEAF;
+ p_treenode->p_array_childs = array_new();
+ p_treenode->p_val = p_val;
+ p_treenode->p_val2 = p_val2;
+
+ return p_treenode;
+}
+
+void
+treenode_delete(TreeNode *p_treenode) {
+ if (!p_treenode)
+ return;
+
+ int i_size = array_get_size(p_treenode->p_array_childs);
+
+ for (int i = 0; i < i_size; ++i)
+ treenode_delete(array_get(p_treenode->p_array_childs, i));
+
+ array_delete(p_treenode->p_array_childs);
+
+ free(p_treenode);
+}
+
+void
+treenode_insert_left(TreeNode *p_treenode, TreeNode *p_treenode2) {
+ array_unshift(p_treenode->p_array_childs, p_treenode2);
+}
+
+void
+treenode_insert_right(TreeNode *p_treenode, TreeNode *p_treenode2) {
+ array_push(p_treenode->p_array_childs, p_treenode2);
+}
+
+TreeIteratorState*
+treeiteratorstate_new(TreeNode *ptn) {
+ TreeIteratorState *p_state = malloc(sizeof(TreeIteratorState));
+
+ p_state->ptn = ptn;
+ p_state->i_pos = 0;
+
+ return p_state;
+}
+
+void
+treeiteratorstate_delete(TreeIteratorState *p_state) {
+ free(p_state);
+}
+
+TreeIterator*
+treeiterator_new(Tree *p_tree) {
+ TreeIterator *p_iter = malloc(sizeof(TreeIterator));
+
+ p_iter->p_stack = stack_new();
+ p_iter->p_state = treeiteratorstate_new(tree_get_root(p_tree));
+
+ return p_iter;
+}
+
+void
+treeiterator_delete(TreeIterator *p_iter) {
+ while (!stack_empty(p_iter->p_stack))
+ treeiteratorstate_delete(stack_pop(p_iter->p_stack));
+
+ stack_delete(p_iter->p_stack);
+
+ if (p_iter->p_state)
+ treeiteratorstate_delete(p_iter->p_state);
+}
+
+_Bool
+treeiterator_has_next(TreeIterator *p_iter) {
+ return p_iter->p_state != NULL;
+}
+
+TreeNode*
+treeiterator_next(TreeIterator *p_iter) {
+ if (!treeiterator_has_next(p_iter))
+ return NULL;
+
+ TreeNode *ptn = p_iter->p_state->ptn;
+
+ Array *p_array_childs = treenode_get_childs(ptn);
+ int i_num_childs = array_get_size(p_array_childs);
+
+ if (p_iter->p_state->i_pos >= i_num_childs) {
+ treeiteratorstate_delete(p_iter->p_state);
+
+ p_iter->p_state =
+ stack_empty(p_iter->p_stack) ? NULL : stack_pop(p_iter->p_stack);
+
+ return ptn;
+ }
+
+ TreeNode *ptn_next = array_get(p_array_childs, p_iter->p_state->i_pos++);
+ stack_push(p_iter->p_stack, p_iter->p_state);
+ p_iter->p_state = treeiteratorstate_new(ptn_next);
+
+ return ptn;
+}
+
diff --git a/src/data/tree.h b/src/data/tree.h
new file mode 100644
index 0000000..ce9ecc4
--- /dev/null
+++ b/src/data/tree.h
@@ -0,0 +1,106 @@
+/*:*
+ *: File: ./src/data/tree.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef TREE_H
+#define TREE_H
+
+#include "../defines.h"
+#include "array.h"
+#include "stack.h"
+
+#ifdef PBSC
+#include "../core/token.h"
+#endif
+
+#define TREE_PRINT_INDENT 3
+
+#define tree_get_root(t) t->p_treenode_root
+#define tree_set_root(t,tn) t->p_treenode_root = tn
+#define treenode_get_num_childs(tn) array_get_size(tn->p_array_childs)
+#define treenode_get_tnt(tn) tn->tnt
+#define treenode_get_val(tn) tn->p_val
+#define treenode_get_val2(tn) tn->p_val2
+#define treenode_set_tnt(tn,t) tn->tnt = t
+#define treenode_set_val(tn,v) tn->p_val = v
+#define treenode_set_val2(tn,v) tn->p_val2 = v
+#define treenode_insert_child treenode_insert_right
+#define treenode_get_childs(tn) tn->p_array_childs
+#define treenode_get_child(tn,i) array_get(tn->p_array_childs,i)
+#define treenode_get_first_child(tn) array_get_first(tn->p_array_childs)
+#define treenode_get_last_child(tn) array_get_last(tn->p_array_childs)
+
+typedef enum {
+ IS_NOTLEAF,
+ IS_LEAF,
+} TreeNodeType;
+
+typedef struct {
+ TreeNodeType tnt;
+ Array *p_array_childs;
+ void *p_val;
+ void *p_val2;
+} TreeNode;
+
+typedef struct {
+ TreeNode *p_treenode_root;
+} Tree;
+
+typedef struct {
+ TreeNode *ptn;
+ int i_pos;
+} TreeIteratorState;
+
+typedef struct {
+ Stack *p_stack;
+ TreeIteratorState *p_state;
+} TreeIterator;
+
+Tree* tree_new();
+void tree_delete(Tree *p_tree);
+void tree_print(Tree *p_tree);
+TreeNode* treenode_new(void *p_val);
+TreeNode* treenode_new2(void *p_val, void *p_val2);
+void treenode_delete(TreeNode *p_treenode);
+void treenode_insert_left(TreeNode *p_treenode, TreeNode *p_treenode2);
+void treenode_insert_right(TreeNode *p_treenode, TreeNode *p_treenode2);
+
+TreeIteratorState* treeiteratorstate_new(TreeNode *ptn);
+void treeiteratorstate_delete(TreeIteratorState *p_state);
+
+TreeIterator* treeiterator_new(Tree *p_tree);
+void treeiterator_delete(TreeIterator *p_iter);
+_Bool treeiterator_has_next(TreeIterator *p_iter);
+TreeNode* treeiterator_next(TreeIterator *p_iter);
+
+#endif
diff --git a/src/data/tupel.c b/src/data/tupel.c
new file mode 100644
index 0000000..68c0247
--- /dev/null
+++ b/src/data/tupel.c
@@ -0,0 +1,53 @@
+/*:*
+ *: File: ./src/data/tupel.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "tupel.h"
+
+#include <stdlib.h>
+
+Tupel*
+tupel_new() {
+ Tupel *p_tupel = (Tupel *) malloc(sizeof(Tupel));
+
+ p_tupel->a = NULL;
+ p_tupel->b = NULL;
+ p_tupel->c = NULL;
+
+ return p_tupel;
+}
+
+void
+tupel_delete(Tupel *p_tupel) {
+ free(p_tupel);
+}
diff --git a/src/data/tupel.h b/src/data/tupel.h
new file mode 100644
index 0000000..e5d0fe7
--- /dev/null
+++ b/src/data/tupel.h
@@ -0,0 +1,47 @@
+/*:*
+ *: File: ./src/data/tupel.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef TUPEL_H
+#define TUPEL_H
+
+typedef struct {
+ void *a;
+ void *b;
+ void *c;
+} Tupel;
+
+Tupel *tupel_new();
+void tupel_delete(Tupel *p_tupel);
+
+#endif
diff --git a/src/data/types.h b/src/data/types.h
new file mode 100644
index 0000000..2899dfe
--- /dev/null
+++ b/src/data/types.h
@@ -0,0 +1,64 @@
+/*:*
+ *: File: ./src/data/types.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef TYPES_H
+#define TYPES_H
+
+typedef enum {
+ TYPE_UNKNOWN,
+ TYPE_NUMBER,
+ TYPE_STRING,
+ TYPE_VOIDP,
+ TYPE_SYMVAR,
+ TYPE_VARIABLE,
+ TYPE_REGEXPR,
+ TYPE_OPERATOR,
+ TYPE_STACK,
+ TYPE_TUPEL,
+ TYPE_HASH,
+ TYPE_DAT,
+ TYPE_ARG_DAT,
+ TYPE_ARGS_DAT,
+ TYPE_STATEMENT_DAT,
+ TYPE_CODE_DAT
+} TYPE;
+
+typedef enum {
+ RET_OK,
+ RET_ERROR = -1,
+ RET_NO_SPACE = -2,
+ RET_OCCUPIED = -3
+} RETCODE;
+
+#endif
diff --git a/src/defines.h b/src/defines.h
new file mode 100644
index 0000000..9484784
--- /dev/null
+++ b/src/defines.h
@@ -0,0 +1,108 @@
+/*:*
+ *: File: ./src/defines.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#ifndef DEFINES_H
+#define DEFINES_H
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "build.h"
+
+#define COPYRIGHT "(c) Paul C. Buetow (2005 - 2010) <fype@dev.buetow.org>"
+#define FYPE
+#define GRAMMAR_MAP_SIZES 128
+#define ARRAY_SIZE 16
+#define HASH_MAXOCC 5
+#define HASH_MKEYLEN 32
+#define HASH_SCALE 10
+#define NAME "Fype2"
+#define LINKER "cc"
+#define SCANNER_BUFSIZE 512
+#define URL "<http://fype.buetow.org>"
+#define VERSION "Alpha Build"
+
+#ifndef false
+#define false (_Bool)0
+#endif
+
+#ifndef true
+#define true (_Bool)1
+#endif
+
+#define UNLESS(x) if (!x)
+// Makes the compiler always happy (end of switch statements) :)
+#define NO_DEFAULT default: if (0)
+
+#define EPRINTF(...) fprintf(stdout, __VA_ARGS__)
+#define ERROR(...) { fprintf(stdout, __VA_ARGS__); \
+ fprintf(stdout, " (%s @ %s line %d)\n", NAME, __FILE__, __LINE__); \
+ exit(1); }
+#define DPRINTF(...) printf("DEBUG("); printf(__VA_ARGS__); printf(")\n");
+
+//#define DEBUG_GC
+//#define DEBUG_TOKEN_REFCOUNT
+//#define DEBUG_FUNCTION_PROCESS
+//#define DEBUG_TRACK
+//#define DEBUG_BLOCK_GET
+//#define DEBUG_EXPRESSION_GET
+
+#ifdef DEBUG_TRACK
+#define TRACK \
+ DPRINTF("Track: %s:%s:%d", \
+ __FILE__, __FUNCTION__, __LINE__); \
+ if (p_interpret && p_interpret->p_token) \
+ DPRINTF("Token: %s", token_get_val(p_interpret->p_token));
+#else
+#define TRACK
+#endif /* DEBUG_TRACK */
+
+#define STR_NEW(len) (char *) calloc(len, sizeof(char))
+#define STR_RESIZE(str, len) (char *) realloc(str, len *sizeof(char))
+#define STRLST(str) str[strlen(str)-1]
+
+#define ERROR_INTERPRET(m,t) \
+ ERROR(\
+ "%s: Interpret error in %s line %d pos %d near '%s'", m, \
+ t->c_filename, \
+ t->i_line_nr, \
+ t->i_pos_nr, \
+ t->c_val \
+ )
+#define ERROR_EOB ERROR_INTERPRET("Unexpected end of block", p_token)
+
+
+#endif
diff --git a/src/fype.c b/src/fype.c
new file mode 100644
index 0000000..cc22c03
--- /dev/null
+++ b/src/fype.c
@@ -0,0 +1,83 @@
+/*:*
+ *: File: ./src/fype.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "fype.h"
+
+#include "argv.h"
+#include "core/scanner.h"
+#include "core/token.h"
+#include "core/interpret.h"
+
+PBSc*
+fype_new() {
+ PBSc *p_fype = malloc(sizeof(PBSc));
+
+ p_fype->p_hash_syms = hash_new(512);
+ p_fype->p_list_token = list_new();
+ p_fype->p_tupel_argv = tupel_new();
+ p_fype->c_basename = NULL;
+
+ return (p_fype);
+}
+
+void
+fype_delete(PBSc *p_fype) {
+ argv_tupel_delete(p_fype->p_tupel_argv);
+
+ hash_delete(p_fype->p_hash_syms);
+
+ list_iterate(p_fype->p_list_token, token_delete_cb);
+ list_delete(p_fype->p_list_token);
+
+ if (p_fype->c_basename)
+ free(p_fype->c_basename);
+}
+
+int
+fype_run(int i_argc, char **pc_argv) {
+ PBSc *p_fype = fype_new();
+
+ // argv: Maintains command line options
+ argv_run(p_fype, i_argc, pc_argv);
+
+ // scanner: Fills the list of tokens
+ scanner_run(p_fype);
+
+ // interpret: Interprets the list of tokens
+ interpret_run(p_fype);
+
+ fype_delete(p_fype);
+
+ return (0);
+}
diff --git a/src/fype.h b/src/fype.h
new file mode 100644
index 0000000..9f5b432
--- /dev/null
+++ b/src/fype.h
@@ -0,0 +1,57 @@
+/*:*
+ *: File: ./src/fype.h
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "argv.h"
+#include "data/hash.h"
+#include "data/list.h"
+#include "data/tupel.h"
+
+#ifndef FYPE_H
+#define FYPE_H
+
+typedef struct {
+ Tupel *p_tupel_argv; // Contains command line options
+ List *p_list_token; // Initial list of tokens
+ Hash *p_hash_syms; // Symbol table
+ char *c_basename;
+} PBSc;
+
+PBSc *fype_new();
+void fype_delete(PBSc *p_fype);
+int fype_run(int i_argc, char **pc_argv);
+
+#endif /* FYPE_H */
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..ac48bd1
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,45 @@
+/*:*
+ *: File: ./src/main.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "fype.h"
+#include "./data/list.h"
+
+int
+main(int i_argc, char **pc_argv) {
+ return (fype_run(i_argc, pc_argv));
+}
+
diff --git a/tags b/tags
new file mode 100644
index 0000000..6a1e484
--- /dev/null
+++ b/tags
@@ -0,0 +1,282 @@
+!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
+!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
+!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
+!_TAG_PROGRAM_NAME Exuberant Ctags //
+!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
+!_TAG_PROGRAM_VERSION 5.7 //
+ARGV_OSLEN ./src/argv.c 44;" d file:
+BINARY ./src/argv.c /^char *BINARY;$/;" v
+CASE ./src/core/token.c 38;" d file:
+CHECK ./src/core/token.c 37;" d file:
+TOKEN_ID_COUNTER ./src/core/token.c /^long TOKEN_ID_COUNTER = 0;$/;" v
+_CODESTR_INDEX ./src/core/scanner.c /^int _CODESTR_INDEX = 0;$/;" v
+_ERROR ./src/core/promise.c 37;" d file:
+_I_FRAME_ID_COUNT ./src/core/frame.c /^unsigned _I_FRAME_ID_COUNT = 0;$/;" v
+_TOKEN_ENDS ./src/core/scanner.c /^const char _TOKEN_ENDS[] = "()";$/;" v
+_def ./src/core/interpret.c /^_def(Interpret *p_inter, Token *p_token, ListIterator *p_iter) {$/;" f
+_eval ./src/core/interpret.c /^_eval(Interpret *p_inter) {$/;" f
+_eval_lambda ./src/core/interpret.c /^_eval_lambda(Interpret *p_inter, Lambda *p_lambda, ListIterator *p_iter) {$/;" f
+_eval_symbol ./src/core/interpret.c /^_eval_symbol(Interpret *p_inter, Symbol *p_symbol, ListIterator *p_iter) {$/;" f
+_frame_print ./src/core/frame.c /^_frame_print(Frame *p_frame, int i_frame_nr) {$/;" f
+_indent ./src/data/tree.c /^void _indent(int i_indent) {$/;" f
+_list_copy_cb ./src/data/list.c /^_list_copy_cb(void *p_void1, void *p_cpy) {$/;" f
+_parant ./src/core/interpret.c /^_parant(Interpret *p_inter, Token *p_token) {$/;" f
+_run_func ./src/core/interpret.c /^_run_func(Interpret *p_inter, Token *p_token, ListIterator *p_iter) {$/;" f
+_say ./src/core/interpret.c /^_say(Interpret *p_inter, Token *p_token, ListIterator *p_iter) {$/;" f
+_scanner_get_next_char ./src/core/scanner.c /^_scanner_get_next_char(Scanner *p_scanner) {$/;" f
+_scanner_has_next_char ./src/core/scanner.c /^_scanner_has_next_char(Scanner *p_scanner) {$/;" f
+_symbol_print_cb ./src/core/frame.c /^_symbol_print_cb(void *p_val, char *c_name) {$/;" f
+_tree_print ./src/data/tree.c /^_tree_print(TreeNode *p_treenode, int i_indent) {$/;" f
+_tree_print_cb ./src/data/tree.c /^_tree_print_cb(void *p_void, void *p_indent) {$/;" f
+_tree_print_cb2 ./src/data/tree.c /^_tree_print_cb2(void *p_void, void *p_indent) {$/;" f
+_unshift_cb ./src/data/array.c /^_unshift_cb(void *p_array, void *p_void) {$/;" f
+argv_addopt ./src/argv.c /^argv_addopt(char c_opt, Tupel *p_tupel_argv) {$/;" f
+argv_check_argc ./src/argv.c /^argv_check_argc(int i_required, unsigned i_argc_left, Tupel *p_tupel_argv) {$/;" f
+argv_checkopt ./src/argv.c /^argv_checkopt(char c_opt, Tupel *p_tupel_argv) {$/;" f
+argv_checkopts ./src/argv.c /^argv_checkopts(char *c_opts, Tupel *p_tupel_argv) {$/;" f
+argv_help ./src/argv.c /^argv_help() {$/;" f
+argv_run ./src/argv.c /^argv_run(PBSc *p_fype, int i_argc, char **pc_argv) {$/;" f
+argv_switch ./src/argv.c /^argv_switch(char c_arg, Tupel *p_tupel_argv, unsigned i_argc_left) {$/;" f
+argv_synopsis ./src/argv.c /^argv_synopsis(Tupel *p_tupel_argv) {$/;" f
+argv_tupel_delete ./src/argv.c /^argv_tupel_delete(Tupel *p_tupel_argv) {$/;" f
+array_append ./src/data/array.c /^array_append(Array *p_array, Array *p_array_append) {$/;" f
+array_defined ./src/data/array.c /^array_defined(Array *p_array, int i_index) {$/;" f
+array_delete ./src/data/array.c /^array_delete(Array *p_array) {$/;" f
+array_delete_iterate ./src/data/array.c /^array_delete_iterate(Array *p_array, void (*func)(void *)) {$/;" f
+array_get ./src/data/array.c /^array_get(Array *p_array, int i_index) {$/;" f
+array_insert ./src/data/array.c /^array_insert(Array *p_array, int i_index, void *p_val) {$/;" f
+array_iterate ./src/data/array.c /^array_iterate(Array *p_array, void (*func)(void *)) {$/;" f
+array_iterate2 ./src/data/array.c /^array_iterate2(Array *p_array, void (*func)(void *, void *), void *p_void) {$/;" f
+array_new ./src/data/array.c /^array_new() {$/;" f
+array_new_copy ./src/data/array.c /^array_new_copy(Array *p_array) {$/;" f
+array_new_size ./src/data/array.c /^array_new_size(int i_size) {$/;" f
+array_print_int ./src/data/array.c /^array_print_int(Array *p_array) {$/;" f
+array_push ./src/data/array.c /^array_push(Array *p_array, void *p_void) {$/;" f
+array_remove ./src/data/array.c /^array_remove(Array *p_array, int i_index) {$/;" f
+array_resize ./src/data/array.c /^array_resize(Array *p_array, int i_size) {$/;" f
+array_set ./src/data/array.c /^array_set(Array *p_array, int i_index, void *p_val) {$/;" f
+array_set_used ./src/data/array.c /^array_set_used(Array *p_array, int i_used) {$/;" f
+array_splice ./src/data/array.c /^array_splice(Array *p_array, int i_index, Array *p_array2) {$/;" f
+array_unshift ./src/data/array.c /^array_unshift(Array *p_array, void *p_void) {$/;" f
+arrayelement_delete ./src/data/array.c /^arrayelement_delete(ArrayElement *p_ae) {$/;" f
+arrayelement_new ./src/data/array.c /^arrayelement_new(void *p_val) {$/;" f
+arrayiterator_delete ./src/data/array.c /^arrayiterator_delete(ArrayIterator *p_arrayiterator) {$/;" f
+arrayiterator_has_next ./src/data/array.c /^arrayiterator_has_next(ArrayIterator *p_arrayiterator) {$/;" f
+arrayiterator_new ./src/data/array.c /^arrayiterator_new(Array *p_array) {$/;" f
+arrayiterator_next ./src/data/array.c /^arrayiterator_next(ArrayIterator *p_arrayiterator) {$/;" f
+cons_car ./src/data/cons.c /^cons_car(Cons *p_cons) {$/;" f
+cons_cdr ./src/data/cons.c /^cons_cdr(Cons *p_cons) {$/;" f
+cons_cons ./src/data/cons.c /^cons_cons(Cons *p_cons, void *p_val) {$/;" f
+cons_delete ./src/data/cons.c /^cons_delete(Cons *p_cons) {$/;" f
+cons_delete_cb ./src/data/cons.c /^cons_delete_cb(void *p_cons) {$/;" f
+cons_iterate ./src/data/cons.c /^cons_iterate(Cons *p_cons, void (*func)(void *)) {$/;" f
+cons_new ./src/data/cons.c /^cons_new(void *p_val) {$/;" f
+dat_clear ./src/data/dat.c /^dat_clear(Dat *p_dat) {$/;" f
+dat_delete ./src/data/dat.c /^dat_delete(Dat *p_dat) {$/;" f
+dat_empty ./src/data/dat.c /^dat_empty(Dat *p_dat) {$/;" f
+dat_first ./src/data/dat.c /^dat_first(Dat *p_dat) {$/;" f
+dat_first_t ./src/data/dat.c /^dat_first_t(Dat *p_dat, TYPE *p_type) {$/;" f
+dat_iterate ./src/data/dat.c /^dat_iterate(Dat *p_dat, void (*func)(void *)) {$/;" f
+dat_iterate_t ./src/data/dat.c /^dat_iterate_t(Dat *p_dat, void (*func)(void *, TYPE)) {$/;" f
+dat_iterate_tl ./src/data/dat.c /^dat_iterate_tl(Dat *p_dat, void (*func)(void *, TYPE, _Bool)) {$/;" f
+dat_last ./src/data/dat.c /^dat_last(Dat *p_dat) {$/;" f
+dat_last_t ./src/data/dat.c /^dat_last_t(Dat *p_dat, TYPE *p_type) {$/;" f
+dat_new ./src/data/dat.c /^dat_new() {$/;" f
+dat_pop ./src/data/dat.c /^dat_pop(Dat *p_dat) {$/;" f
+dat_pop_t ./src/data/dat.c /^dat_pop_t(Dat *p_dat, TYPE *p_type) {$/;" f
+dat_push ./src/data/dat.c /^dat_push(Dat *p_dat, void *p_val) {$/;" f
+dat_push_t ./src/data/dat.c /^dat_push_t(Dat *p_dat, void *p_val, TYPE type) {$/;" f
+dat_second ./src/data/dat.c /^dat_second(Dat *p_dat) {$/;" f
+dat_second_t ./src/data/dat.c /^dat_second_t(Dat *p_dat, TYPE *p_type) {$/;" f
+dat_size ./src/data/dat.c /^dat_size(Dat *p_dat) {$/;" f
+datelem_new ./src/data/dat.c /^datelem_new() {$/;" f
+datelem_new_t ./src/data/dat.c /^datelem_new_t(TYPE type) {$/;" f
+datiter_dat ./src/data/dat.c /^datiter_dat(DatIter *p_iter) {$/;" f
+datiter_delete ./src/data/dat.c /^datiter_delete(DatIter *p_iter) {$/;" f
+datiter_left ./src/data/dat.c /^datiter_left(DatIter *p_iter) {$/;" f
+datiter_new ./src/data/dat.c /^datiter_new(Dat *p_dat) {$/;" f
+datiter_next ./src/data/dat.c /^datiter_next(DatIter *p_iter) {$/;" f
+datiter_next_t ./src/data/dat.c /^datiter_next_t(DatIter *p_iter, TYPE *p_type) {$/;" f
+datiter_skip ./src/data/dat.c /^datiter_skip(DatIter *p_iter, unsigned i_num) {$/;" f
+frame_add_symbol ./src/core/frame.c /^frame_add_symbol(Frame *p_frame, char *c_name, SymbolType st, void *p_val) {$/;" f
+frame_delete ./src/core/frame.c /^frame_delete(Frame *p_frame) {$/;" f
+frame_get_symbol ./src/core/frame.c /^frame_get_symbol(Frame *p_frame, char *c_name) {$/;" f
+frame_new ./src/core/frame.c /^frame_new(Frame *p_parent_frame) {$/;" f
+frame_print ./src/core/frame.c /^frame_print(Frame *p_frame) {$/;" f
+fype_delete ./src/fype.c /^fype_delete(PBSc *p_fype) {$/;" f
+fype_new ./src/fype.c /^fype_new() {$/;" f
+fype_run ./src/fype.c /^fype_run(int i_argc, char **pc_argv) {$/;" f
+get_tt ./src/core/token.c /^get_tt(char *c_token) {$/;" f
+hash_addrisfree ./src/data/hash.c /^hash_addrisfree(Hash *p_hash, int i_addr) {$/;" f
+hash_addrisocc ./src/data/hash.c /^hash_addrisocc(Hash *p_hash, int i_addr, char *c_key) {$/;" f
+hash_delete ./src/data/hash.c /^hash_delete(Hash *p_hash) {$/;" f
+hash_get ./src/data/hash.c /^hash_get(Hash *p_hash, char *c_key) {$/;" f
+hash_get_ht ./src/data/hash.c /^hash_get_ht(Hash *p_hash, char *c_key, TYPE *p_type) {$/;" f
+hash_get_ht_addr ./src/data/hash.c /^hash_get_ht_addr(Hash *p_hash, char *c_key, TYPE *p_type, int *p_addr) {$/;" f
+hash_getaddr ./src/data/hash.c /^hash_getaddr(Hash *p_hash, char *c_key, HASH_OP OP) {$/;" f
+hash_insert ./src/data/hash.c /^hash_insert(Hash *p_hash, char *c_key, void *p_val) {$/;" f
+hash_insert_ht ./src/data/hash.c /^hash_insert_ht(Hash *p_hash, char *c_key, void *p_val, TYPE type) {$/;" f
+hash_iterate ./src/data/hash.c /^hash_iterate(Hash *p_hash, void (*func)(void *)) {$/;" f
+hash_iterate_key ./src/data/hash.c /^hash_iterate_key(Hash *p_hash, void (*func)(void *, char *)) {$/;" f
+hash_key_exists ./src/data/hash.c /^hash_key_exists(Hash *p_hash, char *c_key) {$/;" f
+hash_new ./src/data/hash.c /^hash_new(unsigned i_size) {$/;" f
+hash_nextaddr ./src/data/hash.c /^hash_nextaddr(Hash *p_hash, int i_max_tries, char *c_key, int i_addr,$/;" f
+hash_print ./src/data/hash.c /^hash_print(Hash *p_hash) {$/;" f
+hash_print_addrval ./src/data/hash.c /^hash_print_addrval(Hash *p_hash, int i_addr) {$/;" f
+hash_remove ./src/data/hash.c /^hash_remove(Hash *p_hash, char *c_key) {$/;" f
+hash_size ./src/data/hash.c /^hash_size(Hash *p_hash, int i_size) {$/;" f
+interpret_delete ./src/core/interpret.c /^interpret_delete(Interpret *p_inter) {$/;" f
+interpret_new ./src/core/interpret.c /^interpret_new(List *p_list_token) {$/;" f
+interpret_new_lambda ./src/core/interpret.c /^interpret_new_lambda(Interpret *p_inter, Lambda *p_lambda) {$/;" f
+interpret_run ./src/core/interpret.c /^interpret_run(PBSc *p_fype) {$/;" f
+lambda_delete ./src/core/lambda.c /^lambda_delete(Lambda *p_lambda) {$/;" f
+lambda_new ./src/core/lambda.c /^lambda_new(char *c_name, List *p_list_args, ListElem *p_listelem, ListElem *p_listelem_end, Frame *p_frame) {$/;" f
+lambda_print ./src/core/lambda.c /^lambda_print(Lambda *p_lambda) {$/;" f
+list_add_back ./src/data/list.c /^list_add_back(List *p_list, void *p_val) {$/;" f
+list_add_front ./src/data/list.c /^list_add_front(List *p_list, void *p_val) {$/;" f
+list_clear ./src/data/list.c /^list_clear(List *p_list) {$/;" f
+list_clear_and_free_vals ./src/data/list.c /^list_clear_and_free_vals(List *p_list) {$/;" f
+list_concat_back ./src/data/list.c /^list_concat_back(List *p_list1, List *p_list2) {$/;" f
+list_concat_front ./src/data/list.c /^list_concat_front(List *p_list1, List *p_list2) {$/;" f
+list_copy ./src/data/list.c /^list_copy(List *p_list) {$/;" f
+list_copy2 ./src/data/list.c /^list_copy2(List *p_list, void* (*func)(void *)) {$/;" f
+list_delete ./src/data/list.c /^list_delete(List *p_list) {$/;" f
+list_delete_and_free_vals ./src/data/list.c /^list_delete_and_free_vals(List *p_list) {$/;" f
+list_delete_cb ./src/data/list.c /^list_delete_cb(void *p_list) {$/;" f
+list_empty ./src/data/list.c /^list_empty(List *p_list) {$/;" f
+list_iterate ./src/data/list.c /^list_iterate(List *p_list, void (*func)(void *)) {$/;" f
+list_iterate2 ./src/data/list.c /^list_iterate2(List *p_list, void (*func)(void *, void *), void *p_void) {$/;" f
+list_iterate2_ptr ./src/data/list.c /^list_iterate2_ptr(List *p_list, void (*func)(void *, void *), void *p_void) {$/;" f
+list_iterate3 ./src/data/list.c /^list_iterate3(List *p_list,$/;" f
+list_iterate3_ptr ./src/data/list.c /^list_iterate3_ptr(List *p_list,$/;" f
+list_new ./src/data/list.c /^list_new() {$/;" f
+list_remove_back ./src/data/list.c /^list_remove_back(List *p_list) {$/;" f
+list_remove_elem ./src/data/list.c /^list_remove_elem(List *p_list, ListElem *p_elem_remove) {$/;" f
+list_remove_front ./src/data/list.c /^list_remove_front(List *p_list) {$/;" f
+list_size ./src/data/list.c /^list_size(List *p_list) {$/;" f
+listelem_new ./src/data/list.c /^listelem_new() {$/;" f
+listiterator_current ./src/data/list.c /^listiterator_current(ListIterator *p_iter) {$/;" f
+listiterator_current_elem ./src/data/list.c /^listiterator_current_elem(ListIterator *p_iter) {$/;" f
+listiterator_current_elem_equals ./src/data/list.c /^listiterator_current_elem_equals(ListIterator *p_iter, ListElem *p_listelem) {$/;" f
+listiterator_delete ./src/data/list.c /^listiterator_delete(ListIterator *p_iter) {$/;" f
+listiterator_end ./src/data/list.c /^listiterator_end(ListIterator *p_iter) {$/;" f
+listiterator_get_state ./src/data/list.c /^listiterator_get_state(ListIterator *p_iter) {$/;" f
+listiterator_has_next ./src/data/list.c /^listiterator_has_next(ListIterator *p_iter) {$/;" f
+listiterator_new ./src/data/list.c /^listiterator_new(List *p_list) {$/;" f
+listiterator_new_from_elem ./src/data/list.c /^listiterator_new_from_elem(ListElem *p_listelem) {$/;" f
+listiterator_new_from_elem_reverse ./src/data/list.c /^listiterator_new_from_elem_reverse(ListElem *p_listelem) {$/;" f
+listiterator_new_reverse ./src/data/list.c /^listiterator_new_reverse(List *p_list) {$/;" f
+listiterator_next ./src/data/list.c /^listiterator_next(ListIterator *p_iter) {$/;" f
+listiterator_next_elem ./src/data/list.c /^listiterator_next_elem(ListIterator *p_iter) {$/;" f
+listiterator_prev ./src/data/list.c /^listiterator_prev(ListIterator *p_iter) {$/;" f
+listiterator_prev_elem ./src/data/list.c /^listiterator_prev_elem(ListIterator *p_iter) {$/;" f
+listiterator_set_state ./src/data/list.c /^listiterator_set_state(ListIterator *p_iter, ListIteratorState *p_state) {$/;" f
+listiteratorstate_delete ./src/data/list.c /^listiteratorstate_delete(ListIteratorState *p_state) {$/;" f
+main ./src/main.c /^main(int i_argc, char **pc_argv) {$/;" f
+map_clear ./src/data/map.c /^map_clear(Map *p_map) {$/;" f
+map_clear_and_free_vals ./src/data/map.c /^map_clear_and_free_vals(Map *p_map) {$/;" f
+map_delete ./src/data/map.c /^map_delete(Map *p_map) {$/;" f
+map_delete_and_free_vals ./src/data/map.c /^map_delete_and_free_vals(Map *p_map) {$/;" f
+map_empty ./src/data/map.c /^map_empty(Map *p_map) {$/;" f
+map_exists ./src/data/map.c /^map_exists(Map *p_map, char *c_key) {$/;" f
+map_exists2 ./src/data/map.c /^map_exists2(Map *p_map, char *c_key1, char *c_key2) {$/;" f
+map_full ./src/data/map.c /^map_full(Map *p_map) {$/;" f
+map_get ./src/data/map.c /^map_get(Map *p_map, char *c_key) {$/;" f
+map_get2 ./src/data/map.c /^map_get2(Map *p_map, char *c_key1, char *c_key2) {$/;" f
+map_get_addr ./src/data/map.c /^map_get_addr(Map *p_map, char *c_key) {$/;" f
+map_get_key ./src/data/map.c /^map_get_key(Map *p_map, void *p_val) {$/;" f
+map_insert ./src/data/map.c /^map_insert(Map *p_map, char *c_key, void *p_val) {$/;" f
+map_insert2 ./src/data/map.c /^map_insert2(Map *p_map, char *c_key1, char *c_key2, void *p_val) {$/;" f
+map_insert_if_not_exists ./src/data/map.c /^map_insert_if_not_exists(Map *p_map, char *c_key, void *p_val) {$/;" f
+map_iterate ./src/data/map.c /^map_iterate(Map *p_map, void (*func) (void *)) {$/;" f
+map_iterate2 ./src/data/map.c /^map_iterate2(Map *p_map, void (*func) (void *, void *), void *p_void) {$/;" f
+map_iterate2_keys ./src/data/map.c /^map_iterate2_keys(Map *p_map,$/;" f
+map_iterate3 ./src/data/map.c /^map_iterate3(Map *p_map,$/;" f
+map_iterate3_keys ./src/data/map.c /^map_iterate3_keys(Map *p_map,$/;" f
+map_iterate_keys ./src/data/map.c /^map_iterate_keys(Map *p_map, void (*func) (void *, char *)) {$/;" f
+map_new ./src/data/map.c /^map_new(int i_max_size) {$/;" f
+map_new_named ./src/data/map.c /^map_new_named(int i_max_size, char *c_name) {$/;" f
+map_next_free_addr ./src/data/map.c /^map_next_free_addr(Map *p_map) {$/;" f
+map_print ./src/data/map.c /^map_print(Map *p_map) {$/;" f
+map_remove ./src/data/map.c /^map_remove(Map *p_map, char *c_key) {$/;" f
+promise_delete ./src/core/promise.c /^promise_delete(Promise *p_promise) {$/;" f
+promise_new ./src/core/promise.c /^promise_new(Token *p_token_lambda, ListElem *p_elem_start) {$/;" f
+queue_clear ./src/data/queue.c /^queue_clear(Queue *p_queue) {$/;" f
+queue_delete ./src/data/queue.c /^queue_delete(Queue *p_queue) {$/;" f
+queue_empty ./src/data/queue.c /^queue_empty(Queue *p_queue) {$/;" f
+queue_iterate ./src/data/queue.c /^queue_iterate(Queue *p_queue, void (*func)(void *)) {$/;" f
+queue_iterate_t ./src/data/queue.c /^queue_iterate_t(Queue *p_queue, void (*func)(void *, TYPE)) {$/;" f
+queue_iterate_tl ./src/data/queue.c /^queue_iterate_tl(Queue *p_queue, void (*func)(void *, TYPE, _Bool)) {$/;" f
+queue_new ./src/data/queue.c /^queue_new() {$/;" f
+queue_pop ./src/data/queue.c /^queue_pop(Queue *p_queue) {$/;" f
+queue_pop_t ./src/data/queue.c /^queue_pop_t(Queue *p_queue, TYPE *p_type) {$/;" f
+queue_push ./src/data/queue.c /^queue_push(Queue *p_queue, void *p_val) {$/;" f
+queue_push_t ./src/data/queue.c /^queue_push_t(Queue *p_queue, void *p_val, TYPE type) {$/;" f
+queue_size ./src/data/queue.c /^queue_size(Queue *p_queue) {$/;" f
+queueelem_new ./src/data/queue.c /^queueelem_new() {$/;" f
+queueelem_new_t ./src/data/queue.c /^queueelem_new_t(TYPE type) {$/;" f
+queueiter_delete ./src/data/queue.c /^queueiter_delete(QueueIter *p_iter) {$/;" f
+queueiter_left ./src/data/queue.c /^queueiter_left(QueueIter *p_iter) {$/;" f
+queueiter_new ./src/data/queue.c /^queueiter_new(Queue *p_queue) {$/;" f
+queueiter_next ./src/data/queue.c /^queueiter_next(QueueIter *p_iter) {$/;" f
+queueiter_next_t ./src/data/queue.c /^queueiter_next_t(QueueIter *p_iter, TYPE *p_type) {$/;" f
+queueiter_queue ./src/data/queue.c /^queueiter_queue(QueueIter *p_iter) {$/;" f
+scanner_add_token ./src/core/scanner.c /^scanner_add_token(Scanner *p_scanner, char **cc_token, int *p_token_len,$/;" f
+scanner_cleanup_list_token_cb ./src/core/scanner.c /^scanner_cleanup_list_token_cb(void *p_void) {$/;" f
+scanner_delete ./src/core/scanner.c /^scanner_delete(Scanner *p_scanner) {$/;" f
+scanner_get_tt_cur ./src/core/scanner.c /^scanner_get_tt_cur(char *c_token) {$/;" f
+scanner_new ./src/core/scanner.c /^scanner_new(List *p_list_token, Tupel *p_tupel_argv) {$/;" f
+scanner_run ./src/core/scanner.c /^scanner_run(PBSc *p_fype) {$/;" f
+stack_clear ./src/data/stack.c /^stack_clear(Stack *p_stack) {$/;" f
+stack_concat ./src/data/stack.c /^stack_concat(Stack *p_stack, Stack *p_stack_concat) {$/;" f
+stack_delete ./src/data/stack.c /^stack_delete(Stack *p_stack) {$/;" f
+stack_delete_and_free ./src/data/stack.c /^stack_delete_and_free(Stack *p_stack) {$/;" f
+stack_empty ./src/data/stack.c /^stack_empty(Stack *p_stack) {$/;" f
+stack_iterate ./src/data/stack.c /^stack_iterate(Stack *p_stack, void (*func)(void *p_void)) {$/;" f
+stack_iterate2 ./src/data/stack.c /^stack_iterate2(Stack *p_stack, void (*func)(void *p_void, void *p_void2),$/;" f
+stack_iterate_level ./src/data/stack.c /^stack_iterate_level(Stack *p_stack, void (*func)(void *p_void,$/;" f
+stack_merge ./src/data/stack.c /^stack_merge(Stack *p_stack, Stack *p_stack_merge) {$/;" f
+stack_new ./src/data/stack.c /^stack_new() {$/;" f
+stack_pop ./src/data/stack.c /^stack_pop(Stack *p_stack) {$/;" f
+stack_push ./src/data/stack.c /^stack_push(Stack *p_stack, void *p_val) {$/;" f
+stack_size ./src/data/stack.c /^stack_size(Stack *p_stack) {$/;" f
+stack_top ./src/data/stack.c /^stack_top(Stack *p_stack) {$/;" f
+stackelem_new ./src/data/stack.c /^stackelem_new() {$/;" f
+stackiterator_delete ./src/data/stack.c /^stackiterator_delete(StackIterator *p_iter) {$/;" f
+stackiterator_has_next ./src/data/stack.c /^stackiterator_has_next(StackIterator *p_iter) {$/;" f
+stackiterator_new ./src/data/stack.c /^stackiterator_new(Stack *p_stack) {$/;" f
+stackiterator_next ./src/data/stack.c /^stackiterator_next(StackIterator *p_iter) {$/;" f
+stackiterator_remove_prev ./src/data/stack.c /^stackiterator_remove_prev(StackIterator *p_iter) {$/;" f
+symbol_delete ./src/core/frame.c /^symbol_delete(Symbol *p_symbol) {$/;" f
+symbol_delete_cb ./src/core/frame.c /^symbol_delete_cb(void *p_symbol) {$/;" f
+symbol_get_type_name ./src/core/frame.c /^symbol_get_type_name(Symbol *p_symbol) {$/;" f
+symbol_new ./src/core/frame.c /^symbol_new(SymbolType st, void *p_val) {$/;" f
+token_delete ./src/core/token.c /^token_delete(Token *p_token) {$/;" f
+token_delete_cb ./src/core/token.c /^token_delete_cb(void *p_void) {$/;" f
+token_is ./src/core/token.c /^token_is(Token *p_token, char *c_str) {$/;" f
+token_new ./src/core/token.c /^token_new(char *c_val, TokenType tt_cur, int i_line_nr,$/;" f
+token_new_dummy ./src/core/token.c /^token_new_dummy() {$/;" f
+token_print ./src/core/token.c /^token_print(Token *p_token) {$/;" f
+token_print_cb ./src/core/token.c /^token_print_cb(void *p_void) {$/;" f
+token_print_ln ./src/core/token.c /^token_print_ln(Token *p_token) {$/;" f
+tool_skip_block ./src/core/tools.c /^tool_skip_block(ListIterator *p_iter, int i_offset) {$/;" f
+tree_delete ./src/data/tree.c /^tree_delete(Tree *p_tree) {$/;" f
+tree_new ./src/data/tree.c /^tree_new() {$/;" f
+tree_print ./src/data/tree.c /^tree_print(Tree *p_tree) {$/;" f
+treeiterator_delete ./src/data/tree.c /^treeiterator_delete(TreeIterator *p_iter) {$/;" f
+treeiterator_has_next ./src/data/tree.c /^treeiterator_has_next(TreeIterator *p_iter) {$/;" f
+treeiterator_new ./src/data/tree.c /^treeiterator_new(Tree *p_tree) {$/;" f
+treeiterator_next ./src/data/tree.c /^treeiterator_next(TreeIterator *p_iter) {$/;" f
+treeiteratorstate_delete ./src/data/tree.c /^treeiteratorstate_delete(TreeIteratorState *p_state) {$/;" f
+treeiteratorstate_new ./src/data/tree.c /^treeiteratorstate_new(TreeNode *ptn) {$/;" f
+treenode_delete ./src/data/tree.c /^treenode_delete(TreeNode *p_treenode) {$/;" f
+treenode_insert_left ./src/data/tree.c /^treenode_insert_left(TreeNode *p_treenode, TreeNode *p_treenode2) {$/;" f
+treenode_insert_right ./src/data/tree.c /^treenode_insert_right(TreeNode *p_treenode, TreeNode *p_treenode2) {$/;" f
+treenode_new ./src/data/tree.c /^treenode_new(void *p_val) {$/;" f
+treenode_new2 ./src/data/tree.c /^treenode_new2(void *p_val, void *p_val2) {$/;" f
+tt_get_name ./src/core/token.c /^tt_get_name(TokenType tt_cur) {$/;" f
+tupel_delete ./src/data/tupel.c /^tupel_delete(Tupel *p_tupel) {$/;" f
+tupel_new ./src/data/tupel.c /^tupel_new() {$/;" f
+variable_delete ./src/core/variable.c /^variable_delete(Variable *p_variable) {$/;" f
+variable_new ./src/core/variable.c /^variable_new(char *c_name, Token *p_token,Frame *p_frame) {$/;" f
+variable_print ./src/core/variable.c /^variable_print(Variable *p_variable) {$/;" f
diff --git a/test.fype b/test.fype
new file mode 100644
index 0000000..e5fb86c
--- /dev/null
+++ b/test.fype
@@ -0,0 +1,13 @@
+(def (test a)
+ (def (test2 a2)
+ (def (test3 a3)
+ (BEEP))
+ (test3 a2))
+ (def foo bar)
+ (def (barrr) foo)
+ (def (barr) (foo baz))
+ (def (bar x) (foo baz))
+ (test2 a))
+(test (foo bar baz))
+(say "hello world" 1.2)
+
diff --git a/test.out b/test.out
new file mode 100644
index 0000000..2576315
--- /dev/null
+++ b/test.out
@@ -0,0 +1,116 @@
+(def (test a)
+ (def (test2 a2)
+ (def (test3 a3)
+ (BEEP))
+ (test3 a2))
+ (def foo bar)
+ (def (barrr) foo)
+ (def (barr) (foo baz))
+ (def (bar x) (foo baz))
+ (test2 a))
+(test (foo bar baz))
+(say "hello world" 1.2)
+
+Token (id=00000, line=00001, pos=0001, type=TT_PARANT_L, val=()
+Token (id=00001, line=00001, pos=0005, type=TT_IDENT, val=def)
+Token (id=00002, line=00001, pos=0006, type=TT_PARANT_L, val=()
+Token (id=00003, line=00001, pos=0011, type=TT_IDENT, val=test)
+Token (id=00004, line=00001, pos=0013, type=TT_IDENT, val=a)
+Token (id=00005, line=00001, pos=0014, type=TT_PARANT_R, val=))
+Token (id=00006, line=00002, pos=0004, type=TT_PARANT_L, val=()
+Token (id=00007, line=00002, pos=0008, type=TT_IDENT, val=def)
+Token (id=00008, line=00002, pos=0009, type=TT_PARANT_L, val=()
+Token (id=00009, line=00002, pos=0015, type=TT_IDENT, val=test2)
+Token (id=00010, line=00002, pos=0018, type=TT_IDENT, val=a2)
+Token (id=00011, line=00002, pos=0019, type=TT_PARANT_R, val=))
+Token (id=00012, line=00003, pos=0007, type=TT_PARANT_L, val=()
+Token (id=00013, line=00003, pos=0011, type=TT_IDENT, val=def)
+Token (id=00014, line=00003, pos=0012, type=TT_PARANT_L, val=()
+Token (id=00015, line=00003, pos=0018, type=TT_IDENT, val=test3)
+Token (id=00016, line=00003, pos=0021, type=TT_IDENT, val=a3)
+Token (id=00017, line=00003, pos=0022, type=TT_PARANT_R, val=))
+Token (id=00018, line=00004, pos=0010, type=TT_PARANT_L, val=()
+Token (id=00019, line=00004, pos=0015, type=TT_IDENT, val=BEEP)
+Token (id=00020, line=00004, pos=0016, type=TT_PARANT_R, val=))
+Token (id=00021, line=00004, pos=0017, type=TT_PARANT_R, val=))
+Token (id=00022, line=00005, pos=0007, type=TT_PARANT_L, val=()
+Token (id=00023, line=00005, pos=0013, type=TT_IDENT, val=test3)
+Token (id=00024, line=00005, pos=0016, type=TT_IDENT, val=a2)
+Token (id=00025, line=00005, pos=0017, type=TT_PARANT_R, val=))
+Token (id=00026, line=00005, pos=0018, type=TT_PARANT_R, val=))
+Token (id=00027, line=00006, pos=0004, type=TT_PARANT_L, val=()
+Token (id=00028, line=00006, pos=0008, type=TT_IDENT, val=def)
+Token (id=00029, line=00006, pos=0012, type=TT_IDENT, val=foo)
+Token (id=00030, line=00006, pos=0016, type=TT_IDENT, val=bar)
+Token (id=00031, line=00006, pos=0017, type=TT_PARANT_R, val=))
+Token (id=00032, line=00007, pos=0004, type=TT_PARANT_L, val=()
+Token (id=00033, line=00007, pos=0008, type=TT_IDENT, val=def)
+Token (id=00034, line=00007, pos=0009, type=TT_PARANT_L, val=()
+Token (id=00035, line=00007, pos=0015, type=TT_IDENT, val=barrr)
+Token (id=00036, line=00007, pos=0016, type=TT_PARANT_R, val=))
+Token (id=00037, line=00007, pos=0020, type=TT_IDENT, val=foo)
+Token (id=00038, line=00007, pos=0021, type=TT_PARANT_R, val=))
+Token (id=00039, line=00008, pos=0004, type=TT_PARANT_L, val=()
+Token (id=00040, line=00008, pos=0008, type=TT_IDENT, val=def)
+Token (id=00041, line=00008, pos=0009, type=TT_PARANT_L, val=()
+Token (id=00042, line=00008, pos=0014, type=TT_IDENT, val=barr)
+Token (id=00043, line=00008, pos=0015, type=TT_PARANT_R, val=))
+Token (id=00044, line=00008, pos=0016, type=TT_PARANT_L, val=()
+Token (id=00045, line=00008, pos=0020, type=TT_IDENT, val=foo)
+Token (id=00046, line=00008, pos=0024, type=TT_IDENT, val=baz)
+Token (id=00047, line=00008, pos=0025, type=TT_PARANT_R, val=))
+Token (id=00048, line=00008, pos=0026, type=TT_PARANT_R, val=))
+Token (id=00049, line=00009, pos=0004, type=TT_PARANT_L, val=()
+Token (id=00050, line=00009, pos=0008, type=TT_IDENT, val=def)
+Token (id=00051, line=00009, pos=0009, type=TT_PARANT_L, val=()
+Token (id=00052, line=00009, pos=0013, type=TT_IDENT, val=bar)
+Token (id=00053, line=00009, pos=0015, type=TT_IDENT, val=x)
+Token (id=00054, line=00009, pos=0016, type=TT_PARANT_R, val=))
+Token (id=00055, line=00009, pos=0017, type=TT_PARANT_L, val=()
+Token (id=00056, line=00009, pos=0021, type=TT_IDENT, val=foo)
+Token (id=00057, line=00009, pos=0025, type=TT_IDENT, val=baz)
+Token (id=00058, line=00009, pos=0026, type=TT_PARANT_R, val=))
+Token (id=00059, line=00009, pos=0027, type=TT_PARANT_R, val=))
+Token (id=00060, line=00010, pos=0004, type=TT_PARANT_L, val=()
+Token (id=00061, line=00010, pos=0010, type=TT_IDENT, val=test2)
+Token (id=00062, line=00010, pos=0012, type=TT_IDENT, val=a)
+Token (id=00063, line=00010, pos=0013, type=TT_PARANT_R, val=))
+Token (id=00064, line=00010, pos=0014, type=TT_PARANT_R, val=))
+Token (id=00065, line=00011, pos=0001, type=TT_PARANT_L, val=()
+Token (id=00066, line=00011, pos=0006, type=TT_IDENT, val=test)
+Token (id=00067, line=00011, pos=0007, type=TT_PARANT_L, val=()
+Token (id=00068, line=00011, pos=0011, type=TT_IDENT, val=foo)
+Token (id=00069, line=00011, pos=0015, type=TT_IDENT, val=bar)
+Token (id=00070, line=00011, pos=0019, type=TT_IDENT, val=baz)
+Token (id=00071, line=00011, pos=0020, type=TT_PARANT_R, val=))
+Token (id=00072, line=00011, pos=0021, type=TT_PARANT_R, val=))
+Token (id=00073, line=00012, pos=0001, type=TT_PARANT_L, val=()
+Token (id=00074, line=00012, pos=0005, type=TT_IDENT, val=say)
+Token (id=00075, line=00012, pos=0006, type=TT_STRING, val=hello world)
+Token (id=00076, line=00012, pos=0009, type=TT_INTEGER, val=1)
+Token (id=00077, line=00012, pos=0009, type=TT_DOT, val=.)
+Token (id=00078, line=00012, pos=0011, type=TT_INTEGER, val=2)
+Token (id=00079, line=00012, pos=0012, type=TT_PARANT_R, val=))
+No symbol 'BEEP' defined @ any frame:
+FRAME(id=3) 0:
++ST_VARIABLE(name=a3,value=a2)
+FRAME(id=2) 1:
++ST_VARIABLE(name=a2,value=a)
++ST_LAMBDA(name=test3;args=a3)
+( ( BEEP ) )
+FRAME(id=1) 2:
++ST_LAMBDA(name=a;args=)
+( ( foo bar baz )
++ST_LAMBDA(name=test2;args=a2)
+( ( def ( test3 a3 ) ( BEEP ) ) ( test3 a2 ) )
++ST_LAMBDA(name=barrr;args=)
+( foo )
++ST_LAMBDA(name=barr;args=)
+( ( foo baz ) )
++ST_LAMBDA(name=bar;args=x)
+( ( foo baz ) )
++ST_VARIABLE(name=foo,value=bar)
+FRAME(id=0) 3:
++ST_LAMBDA(name=test;args=a)
+( ( def ( test2 a2 ) ( def ( test3 a3 ) ( BEEP ) ) ( test3 a2 ) ) ( def foo bar ) ( def ( barrr ) foo ) ( def ( barr ) ( foo baz ) ) ( def ( bar x ) ( foo baz ) ) ( test2 a ) )
+Error.: Interpret error in ./test.fype line 4 pos 15 near 'BEEP' (Fype2 @ ./src/core/interpret.c line 342)