From a90467d4be3bcf91cab299b4521bf5f762abb1d5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 9 May 2010 09:30:29 +0000 Subject: added the scheme branch --- COPYING | 31 +++ INSTALL | 11 ++ Makefile | 118 +++++++++++ docs/header.txt | 31 +++ docs/help.txt | 8 + docs/pbsc.txt | 43 ++++ docs/stats.txt | 4 + docs/synopses.txt | 4 + docs/version.txt | 1 + docs/vim-tips.txt | 2 + examples/netsted.fype | 11 ++ examples/reverse.fype | 7 + src/argv.c | 181 +++++++++++++++++ src/argv.h | 51 +++++ src/build.h | 41 ++++ src/core/frame.c | 152 +++++++++++++++ src/core/frame.h | 68 +++++++ src/core/interpret.c | 379 +++++++++++++++++++++++++++++++++++ src/core/interpret.h | 58 ++++++ src/core/lambda.c | 98 ++++++++++ src/core/lambda.h | 55 ++++++ src/core/promise.c | 60 ++++++ src/core/promise.h | 49 +++++ src/core/scanner.c | 297 ++++++++++++++++++++++++++++ src/core/scanner.h | 69 +++++++ src/core/token.c | 135 +++++++++++++ src/core/token.h | 75 +++++++ src/core/tools.c | 64 ++++++ src/core/tools.h | 42 ++++ src/core/variable.c | 59 ++++++ src/core/variable.h | 52 +++++ src/data/array.c | 327 +++++++++++++++++++++++++++++++ src/data/array.h | 94 +++++++++ src/data/cons.c | 88 +++++++++ src/data/cons.h | 55 ++++++ src/data/dat.c | 268 +++++++++++++++++++++++++ src/data/dat.h | 88 +++++++++ src/data/hash.c | 306 +++++++++++++++++++++++++++++ src/data/hash.h | 84 ++++++++ src/data/list.c | 531 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/data/list.h | 118 +++++++++++ src/data/map.c | 289 +++++++++++++++++++++++++++ src/data/map.h | 88 +++++++++ src/data/queue.c | 210 ++++++++++++++++++++ src/data/queue.h | 81 ++++++++ src/data/stack.c | 271 ++++++++++++++++++++++++++ src/data/stack.h | 79 ++++++++ src/data/tree.c | 215 ++++++++++++++++++++ src/data/tree.h | 106 ++++++++++ src/data/tupel.c | 53 +++++ src/data/tupel.h | 47 +++++ src/data/types.h | 64 ++++++ src/defines.h | 108 ++++++++++ src/fype.c | 83 ++++++++ src/fype.h | 57 ++++++ src/main.c | 45 +++++ tags | 282 +++++++++++++++++++++++++++ test.fype | 13 ++ test.out | 116 +++++++++++ 59 files changed, 6422 insertions(+) create mode 100644 COPYING create mode 100644 INSTALL create mode 100644 Makefile create mode 100644 docs/header.txt create mode 100644 docs/help.txt create mode 100644 docs/pbsc.txt create mode 100644 docs/stats.txt create mode 100644 docs/synopses.txt create mode 100644 docs/version.txt create mode 100644 docs/vim-tips.txt create mode 100644 examples/netsted.fype create mode 100644 examples/reverse.fype create mode 100644 src/argv.c create mode 100644 src/argv.h create mode 100644 src/build.h create mode 100644 src/core/frame.c create mode 100644 src/core/frame.h create mode 100644 src/core/interpret.c create mode 100644 src/core/interpret.h create mode 100644 src/core/lambda.c create mode 100644 src/core/lambda.h create mode 100644 src/core/promise.c create mode 100644 src/core/promise.h create mode 100644 src/core/scanner.c create mode 100644 src/core/scanner.h create mode 100644 src/core/token.c create mode 100644 src/core/token.h create mode 100644 src/core/tools.c create mode 100644 src/core/tools.h create mode 100644 src/core/variable.c create mode 100644 src/core/variable.h create mode 100644 src/data/array.c create mode 100644 src/data/array.h create mode 100644 src/data/cons.c create mode 100644 src/data/cons.h create mode 100644 src/data/dat.c create mode 100644 src/data/dat.h create mode 100644 src/data/hash.c create mode 100644 src/data/hash.h create mode 100644 src/data/list.c create mode 100644 src/data/list.h create mode 100644 src/data/map.c create mode 100644 src/data/map.h create mode 100644 src/data/queue.c create mode 100644 src/data/queue.h create mode 100644 src/data/stack.c create mode 100644 src/data/stack.h create mode 100644 src/data/tree.c create mode 100644 src/data/tree.h create mode 100644 src/data/tupel.c create mode 100644 src/data/tupel.h create mode 100644 src/data/types.h create mode 100644 src/defines.h create mode 100644 src/fype.c create mode 100644 src/fype.h create mode 100644 src/main.c create mode 100644 tags create mode 100644 test.fype create mode 100644 test.out 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) + -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 :bd 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 +#include +#include + +#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 +#include + +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) { + T