diff options
| author | admin (centauri.fritz.box) <puppet@mx.buetow.org> | 2014-06-30 23:53:09 +0200 |
|---|---|---|
| committer | admin (centauri.fritz.box) <puppet@mx.buetow.org> | 2014-06-30 23:53:09 +0200 |
| commit | ac9339b92d8eb95d54c04cc1f507131642052199 (patch) | |
| tree | 9213a8bd41ba14bd8ed48c8bbc96851453b87f2d | |
| parent | 63cf3028445d8d213ffc774f77aafd7283cb4fbd (diff) | |
| parent | 9bf07e1dfa69b5d6e4c296c0690b5ed91f909b7b (diff) | |
Merge remote-tracking branch 'remotes/github/v0.1' into v0.1
62 files changed, 3620 insertions, 1909 deletions
@@ -1,27 +1,22 @@ -File: ./COPYING -A simple Fype interpreter +Fype (http://fype.buetow.org) is ... +... Copyright (c) 2005 2006 2007 2008 by Dipl.-Inf. (FH) Paul C. Buetow +All rights reserved. -WWW: http://fype.buetow.org -AUTHOR: http://paul.buetow.org -E-Mail: fype at dev.buetow.org +Redistribution and use in source and binary forms, with or without +modification, 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 P. B. Labs nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. -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 +THIS SOFTWARE IS PROVIDED BY Paul 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, +DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -6,6 +6,6 @@ How to install fype: How to read the docu: - man pbsc + man fype Examples can be found in the ./examples directory. @@ -1,11 +1,37 @@ -# THIS MAKEFILE ONLY WORKS WITH (NET)BSD MAKE AKA PMAKE! +# File: ./Makefile +# +# Copyright (c) 2005 2006 2007, Paul Buetow (http://www.pblabs.net) +# All rights reserved. +# +# 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 P. B. Labs 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 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 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. BIN=fype SRCS!=find ./src -name '*.c' OBJS=$(SRCS:.c=.o) CC?=cc #CC=mingw32-gcc -DEBUG=-g3 -ggdb3 +#DEBUG=-g3 -ggdb3 CFLAGS+=-c -Wall -std=c99 -pedantic $(DEBUG) LDADD+= HEADER?=docs/header.txt @@ -13,6 +39,7 @@ OSYSTEM!=uname PREFIX=/usr/local all: build $(OBJS) newline stats-tofile @$(CC) -lm -o $(BIN) $(OBJS) $(LDADD) + @if test -z '$(DEBUG)'; then strip $(BIN) ; fi @awk '$$2 == "BUILDNR" { printf("===> Fype build number % 13s :% 6s%d\n", \ "", "", $$3); exit(0); }' src/build.h @echo "===> Fype binary size : `du -hs $(BIN)`" @@ -29,7 +56,7 @@ clean: find ./ -name '*.bin' -exec rm -f {} \; find . -name '*.core' -exec rm -f {} \; if [ -f $(BIN) ]; then rm -f $(BIN); fi -build: ctags +build: #ctags @awk '{ \ if ($$2 == "BUILDNR") print $$1,$$2,$$3+1; \ else if ($$2 ~ /OS_/) printf("%s OS_%s\n", $$1, \ @@ -40,7 +67,7 @@ printbuild: @awk '$$2 == "BUILDNR" { printf("%d\n", \ $$3); exit(0); }' src/build.h ctags: - # Generating Source-Tags for Vim + @# Generating Source-Tags for Vim ctags `find . -name '*.c'` style: astyle check astyle: @@ -58,31 +85,25 @@ stats: 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`; \ + @sh -c 'wc=`find ./examples -name "*.fy" | xargs wc -l`; \ echo "===> Num of Fype source examples : `echo \"$$wc\" | \ - grep -E \"\\.fype$$\" | wc -l`"; \ + grep -E \"\\.fy$$\" | 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 +test: all + cat ./tmp/test.fy > ./tmp/test.out + ./$(BIN) -V ./tmp/test.fy | tee -a ./tmp/test.out run: - ./$(BIN) ./test.fype + ./$(BIN) ./tmp/test.fy core: - #gdb $(BIN) $(BIN).core - gdb $(BIN) core -gdb: - gdb --args $(BIN) .// + gdb $(BIN) $(BIN).core newline: @echo examples: all echo > ./examples/all-examples.txt - for i in ./examples/*.fype; do \ + for i in ./examples/*.fy; do \ echo "===> Running $$i"; \ ./$(BIN) $$i; \ cat $$i >> ./examples/all-examples.txt; \ @@ -94,10 +115,6 @@ replace: 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) @@ -116,3 +133,4 @@ deinstall: uninstall: deinstall pod: @cd ./docs/pod; make clean all + @@ -0,0 +1,379 @@ +NAME + Fype is for your program execution + + Fype is free yack programed for ELF + + It's not a hype - it's Fype! + +SYNOPSES + fype [-[hsvTV]] file.fy + fype -e "fype code string;" + +ABOUT + Fype is not yet released! Lots of basic stuff is still missing! See the + TODO file of the source distribution of Fype! + + Fype is a 32 bit scripting language created for fun. You can use it and + comment on it if you like. You could also write patches and mail them to + fype at dev dot buetow dot org! Or go visit the IRC channel #coding at + irc.german-elite.net and ask rantanplan. + + Fype is developed under the BSD license. See the COPYING file which is + included in the source tree. + + Fype should be "at least as good as AWK". This does not mean it will be + a replacement for AWK but it should support functions, loops and arrays + like AWK does but with a different syntax. It should also get extension + support like AWK has. I am not talking about GNU AWK but about New AWK, + which is included in the *BSD distributions! Fype already has a few + features which are not available in AWK. However, AWK has still many + features which are not available in Fype as well ;) + + Fancy stuff like OOP or unicode or threading is not yet planed. But + fancy stuff like function pointers and closures may be considered for + one of the first releases of Fype :) + +PARSING / CODE GENERATION + The Fype syntax is very simple and is using a maximum look ahead of 1 + and a very easy top down parsing. Fype is parsing and interpreting its + code simultaneous. This means, that syntax errors are only detected + during program runtime. + +REQUIREMENTS + Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows + support is not planned. But may work using Cygwin or SFU. + + You will also need: + + GNU GCC C Compiler (gcc.gnu.org) + NetBSD Make aka pmake (GNU Make will not work) (it's included in any *BSD) + +GETTING STARTED + Extract, compile and install Fype: + + tar xvjf fype.tar.bz2 + cd fype + make + sudo make install + make clean + + Run a .fy file: + + fype test.fy + + See the ./examples subdir of the Fype source distribution for examples! + See also fype -h for a list of all options. + +DATA TYPES + Fype uses auto type conversion. However, if you want to know what's + going on you may take a look at the provided basic datatypes. + + The basic data types + *integer* + Specifies an integer number + + *double* + Specifies a double number + + *string* + Specifies a string + + *number* + May be an integer or a double number + + *any* + May be of any type above + + *void* + No type + + *identifier* + It's a variable name or a procedure name or a function name + + Explicit type conversions + (*integer*) integer *any* + Converts any type to an integer + + (*double*) double *any* + Converts any type to a double + + (*string*) string *any* + Converts any type to a string + +SYNTAX + Comments + Text from a # character until the end of the current line is considered + being a comment. Multi line comments may start with an #* and and with + an *# anywhere. Exceptions are if those signs are inside of strings. + + Statements + A Fype program is a list of statements. Each keyword, expression or + function call is part of a statement. Each statement is ended with a + semicolon. Example: + + my bar = 3, foo = 1 + 2; + say foo; + exit foo - bar; + + Paranthesis + All paranthesis of function calls are optional. They help to make the + code better readable. They also help to force precedences of + expressions. + + Scopeing + A new scope starts with an { and ends with an }. An exception is a + procedure, which does not use its own scope (see later in this manual). + Control statements and functions support scopeings. Here is a small + example how to use scopes: + + my foo = 1; + + { + # Prints out 1 + put defined foo; + { + my bar = 2; + + # Prints out 1 + put defined bar; + } + + # Prints out 0 + put defined bar; + + my baz = 3; + } + + # Prints out 0 + say defined bar; + + Control statements + Fype knows the following control statements: + + if *<expression*> { *<statements*> } + Runs the statements if the expression evaluates to a true value. + + ifnot *<expression*> { *<statements*> } + Runs the statements if the expression evaluates to a false value. + + while *<expression*> { *<statements*> } + Runs the statements as long as the the expression evaluates to a + true value. + + until *<expression*> { *<statements*> } + Runs the statements as long as the the expression evaluates to a + false value. + +VARIABLES + Variables can be defined with the my keyword. If you don't assign a + value during declaration, then it's using the default integer value 0. + Variables may be changed during program runtime. Variables may be + deleted using the undef keyword! Example of defining variables: + + my foo = 1 + 2; + say foo; + + my bar = 12, baz = foo; + say 1 + bar; + say bar; + + my baz; + say baz; # Will print out 0 + + You may use the defined keyword to check if an identifier has been + defined or not. + + ifnot defined foo { + say "No foo yet defined"; + } + + my foo = 1; + + if defined foo { + put "foo is defined and has the value "; + say foo; + } + +BUILT IN FUNCTIONS + In Fype, operators are built in functions as well. The difference is, + that they may be written in infix notation instead in front of the + arguments. The types inside the () specify the return types. + + Math + (*any*) *any* + *any* + Special string behavior: A string will get auto convertet into an + *integer*. + + (*any*) *any* - *any* + Special string behavior: A string will get auto convertet into an + *integer*. + + (*any*) *any* * *any* + Special string behavior: A string will get auto convertet into an + *integer*. + + (*any*) *any* / *any* + Special string behavior: A string will get auto convertet into an + *integer*. + + Conditional + (*integer*) *any* == *any* + (*integer*) *any* != *any* + (*integer*) *any* <= *any* + (*integer*) *any* >= *any* + (*integer*) *any* < *any* + (*integer*) *any* > *any* + (*integer*) not *any* + + Definedness + (*integer*) defined *identifier* + Returns 1 if *identifier* has been defined. Returns 0 else. + + (*integer*) undef *identifier* + Tries to undefine/delete the *identifier*. Returns 1 if success, + otherwise 0 is returned. + + Bitwise + (*integer*) *any* :< *any* + (*integer*) *any* :> *any* + (*integer*) *any* and *any* + (*integer*) *any* or *any* + (*integer*) *any* xor *any* + + Numeric + (*number*) neg *number* + This function returns the negative value of *any* + + (*integer*) no [*integer*] + This function returns 1 if the argument is 0, otherwise it will + return 0! If no argument is given, then 0 is returned! + + (*integer*) yes [*integer*] + This function always returns 1. The parameter is optional. + + # Prints out 1, because foo is not defined + if yes { say no defined foo; } + + System + (*void*) end + Exits the program with the exit status of 0 + + (*void*) exit *integer* + Exits the program with the specified exit status + + (*integer*) fork + Fork forks a subprocess. It returns 0 for the child process and the + pid of the child process otherwise! Example: + + my pid = fork; + + if pid { + put "I am the parent process; child has the pid "; + say pid; + + } ifnot pid { + say "I am the child process"; + } + + (*integer*) gc + Executes the garbage collector and returns the number of items + freed! You may wonder why most of the time it will return a value of + 0! Fype tries to free not needed memory asap. This may change in + future versions in order to gain faster execution of scripts! + + I/O + (*any*) put *any* + Prints out the argument + + (*any*) say *any* + Same as put, but also includes an ending newline + + (*void*) ln + Just prints a newline + +SELF DEFINING PROCEDURES AND FUNCTIONS + Procedures + A procedure can be defined with the proc keyword and deleted with the + undef keyword. A procedure does not return any value and does not + support parameter passing. It's using already defined variables (e.g. + global variables). A procedure does not have its own namespace. It's + using the calling namespace. It is possible to define new variabes + inside of a procedure in the current namespace. + + proc foo { + say 1 + a * 3 + b; + my c = 6; + } + + my a = 2, b = 4; + + foo; # Run the procedure. Print out "11\n" + say c; # Print out "6\n"; + + Nested procedures + It's possible to define procedures inside of procedures. Since + procedures don't have its own scope, nested procedures will be available + to the current scope as soon as the main procedure has run the first + time. You may use the defined keyword in order to check if a procedure + has been defined or not. + + proc foo { + say "I am foo"; + + undef bar; + proc bar { + say "I am bar"; + } + } + + # Here bar would produce an error because + # the proc is not yet defined! + # bar; + + foo; # Here the procedure foo will define the procedure bar! + bar; # Now the procedure bar is defined! + foo; # Here the procedure foo will redefine bar again! + + Functions + A function should be defined with the func keyword and deleted with the + undef keyword. Function not yet return values (will be changed in future + versions) and supports not yet parameter passing (will be changed in + future versions). It's using local (lexical scoped) variables. If a + certain variable does not exist It's using already defined variables + (e.g. one scope above). + + func foo { + say 1 + a * 3 + b; + my c = 6; + } + + my a = 2, b = 4; + + foo; # Run the procedure. Print out "11\n" + say c; # Will produce an error, because c is out of scoped! + + Nested functions + Nested functions work the same way the nested procedures work, with the + exception that nested functions will not be available any more after the + function has been left! + + func foo { + func bar { + say "Hello i am nested"; + } + + bar; # Calling nested + } + + foo; + bar; # Will produce an error, because bar is out of scope! + +AUTHOR + Paul C. Buetow (http://paul.buetow.org) + +WEBSITE + The Fype Language (http://fype.buetow.org) + +SEE ALSO + awk(1) cc(1) make(1) + @@ -1,11 +1,9 @@ Todo's (not in any specific order) -Functions should be handled via hash and ptrs not if/else (in progress) -Arrays (in progress) +Arrays Closures Function arguments and return values Interactive shell Labels String operators/functions loop, next, break, do - diff --git a/docs/header.txt b/docs/header.txt index 83638b8..d673a17 100644 --- a/docs/header.txt +++ b/docs/header.txt @@ -1,11 +1,11 @@ File: ${FILE} -A simple Fype interpreter +A simple interpreter -WWW: http://fype.buetow.org -AUTHOR: http://paul.buetow.org -E-Mail: fype at dev.buetow.org +WWW : http://fype.buetow.org +E-Mail : fype@dev.buetow.org -The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow +Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow +All rights reserved. Redistribution and use in source and binary forms, with or without modi- fication, are permitted provided that the following conditions are met: @@ -14,14 +14,14 @@ fication, are permitted provided that the following conditions are met: * 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 + * Neither the name of P. B. Labs 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 +THIS SOFTWARE IS PROVIDED BY Paul 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, +DISCLAIMED. IN NO EVENT SHALL Paul 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) diff --git a/docs/help.txt b/docs/help.txt index 0033293..f5387aa 100644 --- a/docs/help.txt +++ b/docs/help.txt @@ -1,5 +1,5 @@ -Fype2 Alpha Build 10387 -(c) Paul C. Buetow (2005 - 2010) <fype@dev.buetow.org> +Fype v0.1 Build 9205 +Copyright by Paul C. Buetow (2005 - 2008) <fype@dev.buetow.org> -e Executes given code string (see synopses) -h Prints this help -s Prints the synopsis diff --git a/docs/pod/Makefile b/docs/pod/Makefile index ddc6de4..d6f56fe 100644 --- a/docs/pod/Makefile +++ b/docs/pod/Makefile @@ -1,4 +1,3 @@ -# THIS MAKEFILE MAY WORK ONLY WITH (NET)BSD MAKE AKA PMAKE! all: man html latex txt html: diff --git a/docs/pod/fype.1.gz b/docs/pod/fype.1.gz Binary files differindex 916f836..8491141 100644 --- a/docs/pod/fype.1.gz +++ b/docs/pod/fype.1.gz diff --git a/docs/pod/fype.html b/docs/pod/fype.html index 121cbea..66c2303 100644 --- a/docs/pod/fype.html +++ b/docs/pod/fype.html @@ -4,15 +4,13 @@ <head> <title>NAME</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> -<link rev="made" href="mailto:root@localhost" /> +<link rev="made" href="mailto:root@chuck.buetow.org" /> </head> <body style="background-color: white"> - -<!-- INDEX BEGIN --> -<div name="index"> <p><a name="__index__"></a></p> +<!-- INDEX BEGIN --> <ul> @@ -40,7 +38,6 @@ </ul> <li><a href="#variables">VARIABLES</a></li> - <li><a href="#synonyms">SYNONYMS</a></li> <li><a href="#built_in_functions">BUILT IN FUNCTIONS</a></li> <ul> @@ -66,25 +63,23 @@ <li><a href="#website">WEBSITE</a></li> <li><a href="#see_also">SEE ALSO</a></li> </ul> - -<hr name="index" /> -</div> <!-- INDEX END --> +<hr /> <p> </p> <h1><a name="name">NAME</a></h1> -<p><strong>Fype</strong> is <strong>F</strong>or <strong>Y</strong>our <strong>P</strong>rogram <strong>E</strong>xecution</p> -<p><strong>Fype</strong> is <strong>F</strong>ree <strong>Y</strong>ak <strong>P</strong>rogramed for <strong>E</strong>LF</p> -<p>It's not a hype - it's <strong>Fype</strong>!</p> +<p><strong>Fype</strong> is <strong>f</strong>or <strong>y</strong>our <strong>p</strong>rogram <strong>e</strong>xecution</p> +<p><strong>Fype</strong> is <strong>f</strong>ree <strong>y</strong>ack <strong>p</strong>rogramed for <strong>E</strong>LF</p> +<p>It's not a hype - it's Fype!</p> <p> </p> <hr /> <h1><a name="synopses">SYNOPSES</a></h1> <dl> -<dt><strong><a name="fype_hsvtv_file_fy" class="item"><strong>fype</strong> [-[hsvTV]] file.fy</a></strong></dt> +<dt><strong><a name="item_fype__5b_2d_5bhsvtv_5d_5d_file_2efy"><strong>fype</strong> [-[hsvTV]] file.fy</a></strong> -<dt><strong><a name="fype_e_fype_code_string" class="item"><strong>fype</strong> -e "fype code string;"</a></strong></dt> +<dt><strong><a name="item_fype__2de__22fype_code_string_3b_22"><strong>fype</strong> -e ``fype code string;''</a></strong> </dl> <p> @@ -95,7 +90,7 @@ TODO file of the source distribution of Fype!</p> <p>Fype is a 32 bit scripting language created for fun. You can use it and comment on it if you like. You could also write patches and mail them to fype at dev dot buetow dot org! Or go visit the IRC channel #coding at irc.german-elite.net and ask rantanplan.</p> <p>Fype is developed under the BSD license. See the COPYING file which is included in the source tree.</p> -<p>Fype should be "at least as good as AWK". This does not mean it will be a replacement for AWK but it should support functions, loops and arrays like AWK does but with a different syntax. It should also get extension support like AWK has. I am not talking about GNU AWK but about New AWK, which is included in the *BSD distributions! Fype already has a few features which are not available in AWK. However, AWK has still many features which are not available in Fype as well ;)</p> +<p>Fype should be ``at least as good as AWK''. This does not mean it will be a replacement for AWK but it should support functions, loops and arrays like AWK does but with a different syntax. It should also get extension support like AWK has. I am not talking about GNU AWK but about New AWK, which is included in the *BSD distributions! Fype already has a few features which are not available in AWK. However, AWK has still many features which are not available in Fype as well ;)</p> <p>Fancy stuff like OOP or unicode or threading is not yet planed. But fancy stuff like function pointers and closures may be considered for one of the first releases of Fype :)</p> <p> </p> @@ -106,24 +101,16 @@ TODO file of the source distribution of Fype!</p> </p> <hr /> <h1><a name="requirements">REQUIREMENTS</a></h1> -<p>Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows support is not planned. But may work using Cygwin or SFU. Linux users have to install pmake before compiling Fype!</p> -<p>You will need:</p> +<p>Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows support is not planned. But may work using Cygwin or SFU.</p> +<p>You will also need:</p> <pre> GNU GCC C Compiler (gcc.gnu.org) - NetBSD Make aka pmake (GNU Make will not work)</pre> -<p>NetBSD Make is included in any *BSD and can be run with just <strong>make</strong>.</p> + NetBSD Make aka pmake (GNU Make will not work) (it's included in any *BSD)</pre> <p> </p> <hr /> <h1><a name="getting_started">GETTING STARTED</a></h1> -<p>On Linux: Extract, compile and install Fype:</p> -<pre> - tar xvjf fype.tar.bz2 - cd fype - pmake - sudo pmake install - pmake clean</pre> -<p>On FreeBSD: Extract, compile and install Fype:</p> +<p>Extract, compile and install Fype:</p> <pre> tar xvjf fype.tar.bz2 cd fype @@ -143,61 +130,71 @@ TODO file of the source distribution of Fype!</p> </p> <h2><a name="the_basic_data_types">The basic data types</a></h2> <dl> -<dt><strong><a name="integer" class="item"><em>integer</em></a></strong></dt> +<dt><strong><a name="item_integer"><em>integer</em></a></strong> <dd> <p>Specifies an integer number</p> </dd> -<dt><strong><a name="double" class="item"><em>double</em></a></strong></dt> +</li> +<dt><strong><a name="item_double"><em>double</em></a></strong> <dd> <p>Specifies a double number</p> </dd> -<dt><strong><a name="string" class="item"><em>string</em></a></strong></dt> +</li> +<dt><strong><a name="item_string"><em>string</em></a></strong> <dd> <p>Specifies a string</p> </dd> -<dt><strong><a name="number" class="item"><em>number</em></a></strong></dt> +</li> +<dt><strong><a name="item_number"><em>number</em></a></strong> <dd> <p>May be an integer or a double number</p> </dd> -<dt><strong><a name="any" class="item"><em>any</em></a></strong></dt> +</li> +<dt><strong><a name="item_any"><em>any</em></a></strong> <dd> <p>May be of any type above</p> </dd> -<dt><strong><a name="void" class="item"><em>void</em></a></strong></dt> +</li> +<dt><strong><a name="item_void"><em>void</em></a></strong> <dd> <p>No type</p> </dd> -<dt><strong><a name="identifier" class="item"><em>identifier</em></a></strong></dt> +</li> +<dt><strong><a name="item_identifier"><em>identifier</em></a></strong> <dd> <p>It's a variable name or a procedure name or a function name</p> </dd> +</li> </dl> <p> </p> <h2><a name="explicit_type_conversions">Explicit type conversions</a></h2> <dl> -<dt><strong><a name="integer_integer_any" class="item">(<em>integer</em>) <strong>integer</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_integer_any">(<em>integer</em>) <strong>integer</strong> <em>any</em></a></strong> <dd> <p>Converts any type to an integer</p> </dd> -<dt><strong><a name="double_double_any" class="item">(<em>double</em>) <strong>double</strong> <em>any</em></a></strong></dt> +</li> +<dt><strong><a name="item__28double_29_double_any">(<em>double</em>) <strong>double</strong> <em>any</em></a></strong> <dd> <p>Converts any type to a double</p> </dd> -<dt><strong><a name="string_string_any" class="item">(<em>string</em>) <strong>string</strong> <em>any</em></a></strong></dt> +</li> +<dt><strong><a name="item__28string_29_string_any">(<em>string</em>) <strong>string</strong> <em>any</em></a></strong> <dd> <p>Converts any type to a string</p> </dd> +</li> </dl> <p> </p> @@ -222,7 +219,7 @@ TODO file of the source distribution of Fype!</p> <p> </p> <h2><a name="scopeing">Scopeing</a></h2> -<p>A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. The <strong>scope</strong> function will print out all available symbols at the current position. Here is a small example of how to use scopes:</p> +<p>A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. Here is a small example how to use scopes:</p> <pre> my foo = 1;</pre> <pre> @@ -233,11 +230,7 @@ TODO file of the source distribution of Fype!</p> my bar = 2;</pre> <pre> # Prints out 1 - put defined bar;</pre> -<pre> - # Prints out all available symbols at this - # point to stdout. Those are: bar and foo - scope; + put defined bar; }</pre> <pre> # Prints out 0 @@ -253,26 +246,30 @@ TODO file of the source distribution of Fype!</p> <h2><a name="control_statements">Control statements</a></h2> <p>Fype knows the following control statements:</p> <dl> -<dt><strong><a name="if_expression_statements" class="item">if <em><expression</em>> { <em><statements</em>> }</a></strong></dt> +<dt><strong><a name="item_if__3cexpression_3e__7b__3cstatements_3e__7d">if <em><expression</em>> { <em><statements</em>> }</a></strong> <dd> <p>Runs the statements if the expression evaluates to a true value.</p> </dd> -<dt><strong><a name="ifnot_expression_statements" class="item">ifnot <em><expression</em>> { <em><statements</em>> }</a></strong></dt> +</li> +<dt><strong><a name="item_ifnot__3cexpression_3e__7b__3cstatements_3e__7d">ifnot <em><expression</em>> { <em><statements</em>> }</a></strong> <dd> <p>Runs the statements if the expression evaluates to a false value.</p> </dd> -<dt><strong><a name="while_expression_statements" class="item">while <em><expression</em>> { <em><statements</em>> }</a></strong></dt> +</li> +<dt><strong><a name="item_while__3cexpression_3e__7b__3cstatements_3e__7d">while <em><expression</em>> { <em><statements</em>> }</a></strong> <dd> <p>Runs the statements as long as the the expression evaluates to a true value.</p> </dd> -<dt><strong><a name="until_expression_statements" class="item">until <em><expression</em>> { <em><statements</em>> }</a></strong></dt> +</li> +<dt><strong><a name="item_until__3cexpression_3e__7b__3cstatements_3e__7d">until <em><expression</em>> { <em><statements</em>> }</a></strong> <dd> <p>Runs the statements as long as the the expression evaluates to a false value.</p> </dd> +</li> </dl> <p> </p> @@ -305,173 +302,159 @@ not.</p> <p> </p> <hr /> -<h1><a name="synonyms">SYNONYMS</a></h1> -<p>Each variable can have as many synonyms as wished. A synonym is another name to access the content of a specific variable. Here is an example of how to use synomyms:</p> -<pre> - my foo = "foo"; - my bar = \foo; - foo = "bar";</pre> -<pre> - # The synonym variable should now also set to "bar" - assert "bar" == bar;</pre> -<p>Synonyms can be used for all kind of identifiers. It's not limited to normal variables but can be also used for function and procedure names etc.</p> -<pre> - # Create a new procedure baz - proc baz { say "I am baz"; }</pre> -<pre> - # Make a synonym baz, and undefine baz - my bay = \baz;</pre> -<pre> - undef baz;</pre> -<pre> - # bay still has a reference of the original procedure baz - bay; # this prints aut "I am baz"</pre> -<p>The <strong>syms</strong> keyword gives you the total number of synonyms pointing to a specific value:</p> -<pre> - my foo = 1; - say syms foo; # Prints 1</pre> -<pre> - my baz = \foo; - say syms foo; # Prints 2 - say syms baz; # Prints 2</pre> -<pre> - undef baz; - say syms foo; # Prints 1</pre> -<p> -</p> -<hr /> <h1><a name="built_in_functions">BUILT IN FUNCTIONS</a></h1> <p>In Fype, operators are built in functions as well. The difference is, that they may be written in infix notation instead in front of the arguments. The types inside the () specify the return types.</p> <p> </p> <h2><a name="math">Math</a></h2> <dl> -<dt><strong><a name="any_any_any" class="item">(<em>any</em>) <em>any</em> <strong>+</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28any_29_any__2b_any">(<em>any</em>) <em>any</em> <strong>+</strong> <em>any</em></a></strong> <dd> <p>Special string behavior: A string will get auto convertet into an <em>integer</em>.</p> </dd> -<dt><strong><a name="any_any_any2" class="item">(<em>any</em>) <em>any</em> <strong>-</strong> <em>any</em></a></strong></dt> +</li> +<dt><strong><a name="item__28any_29_any__2d_any">(<em>any</em>) <em>any</em> <strong>-</strong> <em>any</em></a></strong> <dd> <p>Special string behavior: A string will get auto convertet into an <em>integer</em>.</p> </dd> -<dt><strong><a name="any_any_any3" class="item">(<em>any</em>) <em>any</em> <strong>*</strong> <em>any</em></a></strong></dt> +</li> +<dt><strong><a name="item__28any_29_any__2a_any">(<em>any</em>) <em>any</em> <strong>*</strong> <em>any</em></a></strong> <dd> <p>Special string behavior: A string will get auto convertet into an <em>integer</em>.</p> </dd> -<dt><strong><a name="any_any_any4" class="item">(<em>any</em>) <em>any</em> <strong>/</strong> <em>any</em></a></strong></dt> +</li> +<dt><strong><a name="item__28any_29_any__2f_any">(<em>any</em>) <em>any</em> <strong>/</strong> <em>any</em></a></strong> <dd> <p>Special string behavior: A string will get auto convertet into an <em>integer</em>.</p> </dd> +</li> </dl> <p> </p> <h2><a name="conditional">Conditional</a></h2> <dl> -<dt><strong><a name="integer_any_any" class="item">(<em>integer</em>) <em>any</em> <strong>==</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any__3d_3d_any">(<em>integer</em>) <em>any</em> <strong>==</strong> <em>any</em></a></strong> -<dt><strong><a name="integer_any_any2" class="item">(<em>integer</em>) <em>any</em> <strong>!=</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any__21_3d_any">(<em>integer</em>) <em>any</em> <strong>!=</strong> <em>any</em></a></strong> -<dt><strong><a name="integer_any_any3" class="item">(<em>integer</em>) <em>any</em> <strong><=</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any__3c_3d_any">(<em>integer</em>) <em>any</em> <strong><=</strong> <em>any</em></a></strong> -<dt><strong><a name="integer_any_any4" class="item">(<em>integer</em>) <em>any</em> <strong>>=</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any__3e_3d_any">(<em>integer</em>) <em>any</em> <strong>>=</strong> <em>any</em></a></strong> -<dt><strong><a name="integer_any_any5" class="item">(<em>integer</em>) <em>any</em> <strong><</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any__3c_any">(<em>integer</em>) <em>any</em> <strong><</strong> <em>any</em></a></strong> -<dt><strong><a name="integer_any_any6" class="item">(<em>integer</em>) <em>any</em> <strong>></strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any__3e_any">(<em>integer</em>) <em>any</em> <strong>></strong> <em>any</em></a></strong> -<dt><strong><a name="integer_not_any" class="item">(<em>integer</em>) <strong>not</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_not_any">(<em>integer</em>) <strong>not</strong> <em>any</em></a></strong> </dl> <p> </p> <h2><a name="definedness">Definedness</a></h2> <dl> -<dt><strong><a name="integer_defined_identifier" class="item">(<em>integer</em>) <strong>defined</strong> <em>identifier</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_defined_identifier">(<em>integer</em>) <strong>defined</strong> <em>identifier</em></a></strong> <dd> <p>Returns 1 if <em>identifier</em> has been defined. Returns 0 else.</p> </dd> -<dt><strong><a name="integer_undef_identifier" class="item">(<em>integer</em>) <strong>undef</strong> <em>identifier</em></a></strong></dt> +</li> +<dt><strong><a name="item__28integer_29_undef_identifier">(<em>integer</em>) <strong>undef</strong> <em>identifier</em></a></strong> <dd> <p>Tries to undefine/delete the <em>identifier</em>. Returns 1 if success, otherwise 0 is returned.</p> </dd> +</li> </dl> <p> </p> <h2><a name="bitwise">Bitwise</a></h2> <dl> -<dt><strong><a name="integer_any_any7" class="item">(<em>integer</em>) <em>any</em> <strong>:<</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any__3a_3c_any">(<em>integer</em>) <em>any</em> <strong>:<</strong> <em>any</em></a></strong> -<dt><strong><a name="integer_any_any8" class="item">(<em>integer</em>) <em>any</em> <strong>:></strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any__3a_3e_any">(<em>integer</em>) <em>any</em> <strong>:></strong> <em>any</em></a></strong> -<dt><strong><a name="integer_any_and_any" class="item">(<em>integer</em>) <em>any</em> <strong>and</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any_and_any">(<em>integer</em>) <em>any</em> <strong>and</strong> <em>any</em></a></strong> -<dt><strong><a name="integer_any_or_any" class="item">(<em>integer</em>) <em>any</em> <strong>or</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any_or_any">(<em>integer</em>) <em>any</em> <strong>or</strong> <em>any</em></a></strong> -<dt><strong><a name="integer_any_xor_any" class="item">(<em>integer</em>) <em>any</em> <strong>xor</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28integer_29_any_xor_any">(<em>integer</em>) <em>any</em> <strong>xor</strong> <em>any</em></a></strong> </dl> <p> </p> <h2><a name="numeric">Numeric</a></h2> <dl> -<dt><strong><a name="number_neg_number" class="item">(<em>number</em>) <strong>neg</strong> <em>number</em></a></strong></dt> +<dt><strong><a name="item__28number_29_neg_number">(<em>number</em>) <strong>neg</strong> <em>number</em></a></strong> <dd> <p>This function returns the negative value of <em>any</em></p> </dd> -<dt><strong><a name="integer_no_integer" class="item">(<em>integer</em>) <strong>no</strong> [<em>integer</em>]</a></strong></dt> +</li> +<dt><strong><a name="item__28integer_29_no__5binteger_5d">(<em>integer</em>) <strong>no</strong> [<em>integer</em>]</a></strong> <dd> <p>This function returns 1 if the argument is 0, otherwise it will return 0! If no argument is given, then 0 is returned!</p> </dd> -<dt><strong><a name="integer_yes_integer" class="item">(<em>integer</em>) <strong>yes</strong> [<em>integer</em>]</a></strong></dt> +</li> +<dt><strong><a name="item__28integer_29_yes__5binteger_5d">(<em>integer</em>) <strong>yes</strong> [<em>integer</em>]</a></strong> <dd> -<p>This function always returns 1. The parameter is optional.</p> +<p>This function always returns 1. The parameter is optional. +</p> +</dd> +<dd> <pre> # Prints out 1, because foo is not defined if yes { say no defined foo; }</pre> </dd> +</li> </dl> <p> </p> <h2><a name="system">System</a></h2> <dl> -<dt><strong><a name="void_end" class="item">(<em>void</em>) <strong>end</strong></a></strong></dt> +<dt><strong><a name="item__28void_29_end">(<em>void</em>) <strong>end</strong></a></strong> <dd> <p>Exits the program with the exit status of 0</p> </dd> -<dt><strong><a name="void_exit_integer" class="item">(<em>void</em>) <strong>exit</strong> <em>integer</em></a></strong></dt> +</li> +<dt><strong><a name="item__28void_29_exit_integer">(<em>void</em>) <strong>exit</strong> <em>integer</em></a></strong> <dd> <p>Exits the program with the specified exit status</p> </dd> -<dt><strong><a name="integer_fork" class="item">(<em>integer</em>) <strong>fork</strong></a></strong></dt> +</li> +<dt><strong><a name="item__28integer_29_fork">(<em>integer</em>) <strong>fork</strong></a></strong> <dd> <p>Fork forks a subprocess. It returns 0 for the child process and the pid of the child process otherwise! Example:</p> +</dd> +<dd> <pre> my pid = fork;</pre> +</dd> +<dd> <pre> if pid { put "I am the parent process; child has the pid "; say pid;</pre> +</dd> +<dd> <pre> } ifnot pid { say "I am the child process"; }</pre> </dd> -<dt><strong><a name="integer_gc" class="item">(<em>integer</em>) <strong>gc</strong></a></strong></dt> +</li> +<dt><strong><a name="item__28integer_29_gc">(<em>integer</em>) <strong>gc</strong></a></strong> <dd> <p>Executes the garbage collector and returns the number of items freed! You may @@ -479,26 +462,30 @@ wonder why most of the time it will return a value of 0! Fype tries to free not needed memory asap. This may change in future versions in order to gain faster execution of scripts!</p> </dd> +</li> </dl> <p> </p> <h2><a name="i_o">I/O</a></h2> <dl> -<dt><strong><a name="any_put_any" class="item">(<em>any</em>) <strong>put</strong> <em>any</em></a></strong></dt> +<dt><strong><a name="item__28any_29_put_any">(<em>any</em>) <strong>put</strong> <em>any</em></a></strong> <dd> <p>Prints out the argument</p> </dd> -<dt><strong><a name="any_say_any" class="item">(<em>any</em>) <strong>say</strong> <em>any</em></a></strong></dt> +</li> +<dt><strong><a name="item__28any_29_say_any">(<em>any</em>) <strong>say</strong> <em>any</em></a></strong> <dd> <p>Same as put, but also includes an ending newline</p> </dd> -<dt><strong><a name="void_ln" class="item">(<em>void</em>) <strong>ln</strong></a></strong></dt> +</li> +<dt><strong><a name="item__28void_29_ln">(<em>void</em>) <strong>ln</strong></a></strong> <dd> <p>Just prints a newline</p> </dd> +</li> </dl> <p> </p> @@ -585,7 +572,9 @@ keyword in order to check if a procedure has been defined or not.</p> </p> <hr /> <h1><a name="see_also">SEE ALSO</a></h1> -<p><code>awk(1)</code> <code>cc(1)</code> <code>make(1)</code></p> +<p><code>awk(1)</code> <code>cc(1)</code> <code>make(1)</code> + +</p> </body> diff --git a/docs/pod/fype.man b/docs/pod/fype.man index ed963a7..22eec38 100644 --- a/docs/pod/fype.man +++ b/docs/pod/fype.man @@ -1,7 +1,15 @@ -.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) +.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== +.de Sh \" Subsection heading +.br +.if t .Sp +.ne 5 +.PP +\fB\\$1\fR +.PP +.. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp @@ -17,11 +25,11 @@ .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left -.\" double quote, and \*(R" will give a right double quote. \*(C+ will -.\" give a nicer C++. Capital omega is used to do unbreakable dashes and -.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, -.\" nothing in troff, for use with C<>. -.tr \(*W- +.\" double quote, and \*(R" will give a right double quote. | will give a +.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to +.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' +.\" expand to `' in nroff, nothing in troff, for use with C<>. +.tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- @@ -40,25 +48,22 @@ . ds R" '' 'br\} .\" -.\" Escape single quotes in literal strings from groff's Unicode transform. -.ie \n(.g .ds Aq \(aq -.el .ds Aq ' -.\" .\" If the F register is turned on, we'll generate index entries on stderr for -.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index +.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. -.ie \nF \{\ +.if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} -.el \{\ -. de IX -.. -.\} +.\" +.\" For nroff, turn off justification. Always turn off hyphenation; it makes +.\" way too many mistakes in technical documents. +.hy 0 +.if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. @@ -124,15 +129,11 @@ .\" ======================================================================== .\" .IX Title "FYPE 1" -.TH FYPE 1 "2014-06-22" "Fype Superalpha Build 9666" "The Fype Users Manual Page" -.\" For nroff, turn off justification. Always turn off hyphenation; it makes -.\" way too many mistakes in technical documents. -.if n .ad l -.nh +.TH FYPE 1 "2008-08-25" "Fype v0.0-devel Build 9175" "The Fype Users Manual Page" .SH "NAME" -Fype is For Your Program Execution +\&\fBFype\fR is \fBf\fRor \fBy\fRour \fBp\fRrogram \fBe\fRxecution .PP -Fype is Free Yak Programed for ELF +\&\fBFype\fR is \fBf\fRree \fBy\fRack \fBp\fRrogramed for \fBE\fRLF .PP It's not a hype \- it's Fype! .SH "SYNOPSES" @@ -155,35 +156,23 @@ Fype is developed under the \s-1BSD\s0 license. See the \s-1COPYING\s0 file whic .PP Fype should be \*(L"at least as good as \s-1AWK\s0\*(R". This does not mean it will be a replacement for \s-1AWK\s0 but it should support functions, loops and arrays like \s-1AWK\s0 does but with a different syntax. It should also get extension support like \s-1AWK\s0 has. I am not talking about \s-1GNU\s0 \s-1AWK\s0 but about New \s-1AWK\s0, which is included in the *BSD distributions! Fype already has a few features which are not available in \s-1AWK\s0. However, \s-1AWK\s0 has still many features which are not available in Fype as well ;) .PP -Fancy stuff like \s-1OOP\s0 or unicode or threading is not yet planed. But fancy stuff like function pointers and closures may be considered for one of the first releases of Fype :) +Fancy stuff like \s-1OOP\s0 or unicode or threading is not yet planed. But fancy stuff like function pointers and closures may be considered for one of the first releases of Fype :) .SH "PARSING / CODE GENERATION" .IX Header "PARSING / CODE GENERATION" -The Fype syntax is very simple and is using a maximum look ahead of 1 and a very easy top down parsing. Fype is parsing and interpreting its code simultaneous. This means, that syntax errors are only detected during program runtime. +The Fype syntax is very simple and is using a maximum look ahead of 1 and a very easy top down parsing. Fype is parsing and interpreting its code simultaneous. This means, that syntax errors are only detected during program runtime. .SH "REQUIREMENTS" .IX Header "REQUIREMENTS" -Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows support is not planned. But may work using Cygwin or \s-1SFU\s0. Linux users have to install pmake before compiling Fype! +Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows support is not planned. But may work using Cygwin or \s-1SFU\s0. .PP -You will need: +You will also need: .PP .Vb 2 \& GNU GCC C Compiler (gcc.gnu.org) -\& NetBSD Make aka pmake (GNU Make will not work) +\& NetBSD Make aka pmake (GNU Make will not work) (it's included in any *BSD) .Ve -.PP -NetBSD Make is included in any *BSD and can be run with just \fBmake\fR. .SH "GETTING STARTED" .IX Header "GETTING STARTED" -On Linux: Extract, compile and install Fype: -.PP -.Vb 5 -\& tar xvjf fype.tar.bz2 -\& cd fype -\& pmake -\& sudo pmake install -\& pmake clean -.Ve -.PP -On FreeBSD: Extract, compile and install Fype: +Extract, compile and install Fype: .PP .Vb 5 \& tar xvjf fype.tar.bz2 @@ -203,7 +192,7 @@ See the ./examples subdir of the Fype source distribution for examples! See also .SH "DATA TYPES" .IX Header "DATA TYPES" Fype uses auto type conversion. However, if you want to know what's going on you may take a look at the provided basic datatypes. -.SS "The basic data types" +.Sh "The basic data types" .IX Subsection "The basic data types" .IP "\fIinteger\fR" 4 .IX Item "integer" @@ -226,7 +215,7 @@ No type .IP "\fIidentifier\fR" 4 .IX Item "identifier" It's a variable name or a procedure name or a function name -.SS "Explicit type conversions" +.Sh "Explicit type conversions" .IX Subsection "Explicit type conversions" .IP "(\fIinteger\fR) \fBinteger\fR \fIany\fR" 4 .IX Item "(integer) integer any" @@ -239,52 +228,58 @@ Converts any type to a double Converts any type to a string .SH "SYNTAX" .IX Header "SYNTAX" -.SS "Comments" +.Sh "Comments" .IX Subsection "Comments" Text from a \fB#\fR character until the end of the current line is considered being a comment. Multi line comments may start with an \fB#*\fR and and with an \fB*#\fR anywhere. Exceptions are if those signs are inside of strings. -.SS "Statements" +.Sh "Statements" .IX Subsection "Statements" A Fype program is a list of statements. Each keyword, expression or function call is part of a statement. Each statement is ended with a semicolon. Example: .PP .Vb 3 \& my bar = 3, foo = 1 + 2; \& say foo; -\& exit foo \- bar; +\& exit foo - bar; .Ve -.SS "Paranthesis" +.Sh "Paranthesis" .IX Subsection "Paranthesis" All paranthesis of function calls are optional. They help to make the code better readable. They also help to force precedences of expressions. -.SS "Scopeing" +.Sh "Scopeing" .IX Subsection "Scopeing" -A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. The \fBscope\fR function will print out all available symbols at the current position. Here is a small example of how to use scopes: +A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. Here is a small example how to use scopes: .PP .Vb 1 \& my foo = 1; -\& +.Ve +.PP +.Vb 5 \& { \& # Prints out 1 \& put defined foo; \& { \& my bar = 2; -\& +.Ve +.PP +.Vb 3 \& # Prints out 1 \& put defined bar; -\& -\& # Prints out all available symbols at this -\& # point to stdout. Those are: bar and foo -\& scope; \& } -\& +.Ve +.PP +.Vb 2 \& # Prints out 0 \& put defined bar; -\& +.Ve +.PP +.Vb 2 \& my baz = 3; \& } -\& +.Ve +.PP +.Vb 2 \& # Prints out 0 \& say defined bar; .Ve -.SS "Control statements" +.Sh "Control statements" .IX Subsection "Control statements" Fype knows the following control statements: .IP "if \fI<expression\fR> { \fI<statements\fR> }" 4 @@ -305,12 +300,16 @@ Variables can be defined with the \fBmy\fR keyword. If you don't assign a value .PP .Vb 2 \& my foo = 1 + 2; -\& say foo; -\& +\& say foo; +.Ve +.PP +.Vb 3 \& my bar = 12, baz = foo; \& say 1 + bar; \& say bar; -\& +.Ve +.PP +.Vb 2 \& my baz; \& say baz; # Will print out 0 .Ve @@ -322,59 +321,22 @@ not. \& ifnot defined foo { \& say "No foo yet defined"; \& } -\& +.Ve +.PP +.Vb 1 \& my foo = 1; -\& +.Ve +.PP +.Vb 4 \& if defined foo { \& put "foo is defined and has the value "; \& say foo; \& } .Ve -.SH "SYNONYMS" -.IX Header "SYNONYMS" -Each variable can have as many synonyms as wished. A synonym is another name to access the content of a specific variable. Here is an example of how to use synomyms: -.PP -.Vb 3 -\& my foo = "foo"; -\& my bar = \efoo; -\& foo = "bar"; -\& -\& # The synonym variable should now also set to "bar" -\& assert "bar" == bar; -.Ve -.PP -Synonyms can be used for all kind of identifiers. It's not limited to normal variables but can be also used for function and procedure names etc. -.PP -.Vb 2 -\& # Create a new procedure baz -\& proc baz { say "I am baz"; } -\& -\& # Make a synonym baz, and undefine baz -\& my bay = \ebaz; -\& -\& undef baz; -\& -\& # bay still has a reference of the original procedure baz -\& bay; # this prints aut "I am baz" -.Ve -.PP -The \fBsyms\fR keyword gives you the total number of synonyms pointing to a specific value: -.PP -.Vb 2 -\& my foo = 1; -\& say syms foo; # Prints 1 -\& -\& my baz = \efoo; -\& say syms foo; # Prints 2 -\& say syms baz; # Prints 2 -\& -\& undef baz; -\& say syms foo; # Prints 1 -.Ve .SH "BUILT IN FUNCTIONS" .IX Header "BUILT IN FUNCTIONS" In Fype, operators are built in functions as well. The difference is, that they may be written in infix notation instead in front of the arguments. The types inside the () specify the return types. -.SS "Math" +.Sh "Math" .IX Subsection "Math" .IP "(\fIany\fR) \fIany\fR \fB+\fR \fIany\fR" 4 .IX Item "(any) any + any" @@ -388,7 +350,7 @@ Special string behavior: A string will get auto convertet into an \fIinteger\fR. .IP "(\fIany\fR) \fIany\fR \fB/\fR \fIany\fR" 4 .IX Item "(any) any / any" Special string behavior: A string will get auto convertet into an \fIinteger\fR. -.SS "Conditional" +.Sh "Conditional" .IX Subsection "Conditional" .IP "(\fIinteger\fR) \fIany\fR \fB==\fR \fIany\fR" 4 .IX Item "(integer) any == any" @@ -406,7 +368,7 @@ Special string behavior: A string will get auto convertet into an \fIinteger\fR. .IP "(\fIinteger\fR) \fBnot\fR \fIany\fR" 4 .IX Item "(integer) not any" .PD -.SS "Definedness" +.Sh "Definedness" .IX Subsection "Definedness" .IP "(\fIinteger\fR) \fBdefined\fR \fIidentifier\fR" 4 .IX Item "(integer) defined identifier" @@ -414,7 +376,7 @@ Returns 1 if \fIidentifier\fR has been defined. Returns 0 else. .IP "(\fIinteger\fR) \fBundef\fR \fIidentifier\fR" 4 .IX Item "(integer) undef identifier" Tries to undefine/delete the \fIidentifier\fR. Returns 1 if success, otherwise 0 is returned. -.SS "Bitwise" +.Sh "Bitwise" .IX Subsection "Bitwise" .IP "(\fIinteger\fR) \fIany\fR \fB:<\fR \fIany\fR" 4 .IX Item "(integer) any :< any" @@ -428,7 +390,7 @@ Tries to undefine/delete the \fIidentifier\fR. Returns 1 if success, otherwise 0 .IP "(\fIinteger\fR) \fIany\fR \fBxor\fR \fIany\fR" 4 .IX Item "(integer) any xor any" .PD -.SS "Numeric" +.Sh "Numeric" .IX Subsection "Numeric" .IP "(\fInumber\fR) \fBneg\fR \fInumber\fR" 4 .IX Item "(number) neg number" @@ -439,13 +401,13 @@ This function returns 1 if the argument is 0, otherwise it will return 0! If no argument is given, then 0 is returned! .IP "(\fIinteger\fR) \fByes\fR [\fIinteger\fR]" 4 .IX Item "(integer) yes [integer]" -This function always returns 1. The parameter is optional. +This function always returns 1. The parameter is optional. .Sp .Vb 2 \& # Prints out 1, because foo is not defined \& if yes { say no defined foo; } .Ve -.SS "System" +.Sh "System" .IX Subsection "System" .IP "(\fIvoid\fR) \fBend\fR" 4 .IX Item "(void) end" @@ -460,11 +422,15 @@ child process otherwise! Example: .Sp .Vb 1 \& my pid = fork; -\& +.Ve +.Sp +.Vb 3 \& if pid { \& put "I am the parent process; child has the pid "; \& say pid; -\& +.Ve +.Sp +.Vb 3 \& } ifnot pid { \& say "I am the child process"; \& } @@ -475,20 +441,20 @@ Executes the garbage collector and returns the number of items freed! You may wonder why most of the time it will return a value of 0! Fype tries to free not needed memory asap. This may change in future versions in order to gain faster execution of scripts! -.SS "I/O" +.Sh "I/O" .IX Subsection "I/O" .IP "(\fIany\fR) \fBput\fR \fIany\fR" 4 .IX Item "(any) put any" Prints out the argument .IP "(\fIany\fR) \fBsay\fR \fIany\fR" 4 .IX Item "(any) say any" -Same as put, but also includes an ending newline +Same as put, but also includes an ending newline .IP "(\fIvoid\fR) \fBln\fR" 4 .IX Item "(void) ln" Just prints a newline .SH "SELF DEFINING PROCEDURES AND FUNCTIONS" .IX Header "SELF DEFINING PROCEDURES AND FUNCTIONS" -.SS "Procedures" +.Sh "Procedures" .IX Subsection "Procedures" A procedure can be defined with the \fBproc\fR keyword and deleted with the \fBundef\fR keyword. A procedure does not return any value and does not support parameter passing. It's using already defined variables (e.g. global variables). A procedure does not have its own namespace. It's using the calling namespace. It is possible to define new variabes inside of a procedure in the current namespace. .PP @@ -497,13 +463,17 @@ A procedure can be defined with the \fBproc\fR keyword and deleted with the \fBu \& say 1 + a * 3 + b; \& my c = 6; \& } -\& +.Ve +.PP +.Vb 1 \& my a = 2, b = 4; -\& +.Ve +.PP +.Vb 2 \& foo; # Run the procedure. Print out "11\en" \& say c; # Print out "6\en"; .Ve -.SS "Nested procedures" +.Sh "Nested procedures" .IX Subsection "Nested procedures" It's possible to define procedures inside of procedures. Since procedures don't have its own scope, nested procedures will be available to the current scope as @@ -513,37 +483,47 @@ keyword in order to check if a procedure has been defined or not. .Vb 2 \& proc foo { \& say "I am foo"; -\& +.Ve +.PP +.Vb 5 \& undef bar; \& proc bar { \& say "I am bar"; \& } \& } -\& +.Ve +.PP +.Vb 3 \& # Here bar would produce an error because \& # the proc is not yet defined! -\& # bar; -\& +\& # bar; +.Ve +.PP +.Vb 3 \& foo; # Here the procedure foo will define the procedure bar! \& bar; # Now the procedure bar is defined! \& foo; # Here the procedure foo will redefine bar again! .Ve -.SS "Functions" +.Sh "Functions" .IX Subsection "Functions" -A function should be defined with the \fBfunc\fR keyword and deleted with the \fBundef\fR keyword. Function not yet return values (will be changed in future versions) and supports not yet parameter passing (will be changed in future versions). It's using local (lexical scoped) variables. If a certain variable does not exist It's using already defined variables (e.g. one scope above). +A function should be defined with the \fBfunc\fR keyword and deleted with the \fBundef\fR keyword. Function not yet return values (will be changed in future versions) and supports not yet parameter passing (will be changed in future versions). It's using local (lexical scoped) variables. If a certain variable does not exist It's using already defined variables (e.g. one scope above). .PP .Vb 4 \& func foo { \& say 1 + a * 3 + b; \& my c = 6; \& } -\& +.Ve +.PP +.Vb 1 \& my a = 2, b = 4; -\& +.Ve +.PP +.Vb 2 \& foo; # Run the procedure. Print out "11\en" \& say c; # Will produce an error, because c is out of scoped! .Ve -.SS "Nested functions" +.Sh "Nested functions" .IX Subsection "Nested functions" Nested functions work the same way the nested procedures work, with the exception that nested functions will not be available any more after the function has been left! .PP @@ -552,10 +532,14 @@ Nested functions work the same way the nested procedures work, with the exceptio \& func bar { \& say "Hello i am nested"; \& } -\& +.Ve +.PP +.Vb 2 \& bar; # Calling nested \& } -\& +.Ve +.PP +.Vb 2 \& foo; \& bar; # Will produce an error, because bar is out of scope! .Ve diff --git a/docs/pod/fype.pod b/docs/pod/fype.pod index 5006345..33e50f5 100644 --- a/docs/pod/fype.pod +++ b/docs/pod/fype.pod @@ -1,10 +1,10 @@ =head1 NAME -B<Fype> is B<F>or B<Y>our B<P>rogram B<E>xecution +B<Fype> is B<f>or B<y>our B<p>rogram B<e>xecution -B<Fype> is B<F>ree B<Y>ak B<P>rogramed for B<E>LF +B<Fype> is B<f>ree B<y>ack B<p>rogramed for B<E>LF -It's not a hype - it's B<Fype>! +It's not a hype - it's Fype! =head1 SYNOPSES @@ -35,26 +35,16 @@ The Fype syntax is very simple and is using a maximum look ahead of 1 and a very =head1 REQUIREMENTS -Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows support is not planned. But may work using Cygwin or SFU. Linux users have to install pmake before compiling Fype! +Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows support is not planned. But may work using Cygwin or SFU. -You will need: +You will also need: GNU GCC C Compiler (gcc.gnu.org) - NetBSD Make aka pmake (GNU Make will not work) - -NetBSD Make is included in any *BSD and can be run with just B<make>. + NetBSD Make aka pmake (GNU Make will not work) (it's included in any *BSD) =head1 GETTING STARTED -On Linux: Extract, compile and install Fype: - - tar xvjf fype.tar.bz2 - cd fype - pmake - sudo pmake install - pmake clean - -On FreeBSD: Extract, compile and install Fype: +Extract, compile and install Fype: tar xvjf fype.tar.bz2 cd fype @@ -144,7 +134,7 @@ All paranthesis of function calls are optional. They help to make the code bette =head2 Scopeing -A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. The B<scope> function will print out all available symbols at the current position. Here is a small example of how to use scopes: +A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. Here is a small example how to use scopes: my foo = 1; @@ -156,10 +146,6 @@ A new scope starts with an { and ends with an }. An exception is a procedure, wh # Prints out 1 put defined bar; - - # Prints out all available symbols at this - # point to stdout. Those are: bar and foo - scope; } # Prints out 0 @@ -223,43 +209,6 @@ not. say foo; } -=head1 SYNONYMS - -Each variable can have as many synonyms as wished. A synonym is another name to access the content of a specific variable. Here is an example of how to use synomyms: - - my foo = "foo"; - my bar = \foo; - foo = "bar"; - - # The synonym variable should now also set to "bar" - assert "bar" == bar; - -Synonyms can be used for all kind of identifiers. It's not limited to normal variables but can be also used for function and procedure names etc. - - # Create a new procedure baz - proc baz { say "I am baz"; } - - # Make a synonym baz, and undefine baz - my bay = \baz; - - undef baz; - - # bay still has a reference of the original procedure baz - bay; # this prints aut "I am baz" - -The B<syms> keyword gives you the total number of synonyms pointing to a specific value: - - my foo = 1; - say syms foo; # Prints 1 - - my baz = \foo; - say syms foo; # Prints 2 - say syms baz; # Prints 2 - - undef baz; - say syms foo; # Prints 1 - - =head1 BUILT IN FUNCTIONS In Fype, operators are built in functions as well. The difference is, that they may be written in infix notation instead in front of the arguments. The types inside the () specify the return types. diff --git a/docs/pod/fype.tex b/docs/pod/fype.tex index 7609a00..0558ff3 100644 --- a/docs/pod/fype.tex +++ b/docs/pod/fype.tex @@ -1,15 +1,15 @@ \section{NAME\label{NAME}\index{NAME}} -\textbf{Fype} is \textbf{F}or \textbf{Y}our \textbf{P}rogram \textbf{E}xecution +\textbf{Fype} is \textbf{f}or \textbf{y}our \textbf{p}rogram \textbf{e}xecution -\textbf{Fype} is \textbf{F}ree \textbf{Y}ak \textbf{P}rogramed for \textbf{E}LF +\textbf{Fype} is \textbf{f}ree \textbf{y}ack \textbf{p}rogramed for \textbf{E}LF -It's not a hype - it's \textbf{Fype}! +It's not a hype - it's Fype! \section{SYNOPSES\label{SYNOPSES}\index{SYNOPSES}} \begin{description} @@ -46,35 +46,20 @@ The Fype syntax is very simple and is using a maximum look ahead of 1 and a very \section{REQUIREMENTS\label{REQUIREMENTS}\index{REQUIREMENTS}} -Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows support is not planned. But may work using Cygwin or SFU. Linux users have to install pmake before compiling Fype! +Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows support is not planned. But may work using Cygwin or SFU. -You will need: +You will also need: \begin{verbatim} GNU GCC C Compiler (gcc.gnu.org) - NetBSD Make aka pmake (GNU Make will not work) + NetBSD Make aka pmake (GNU Make will not work) (it's included in any *BSD) \end{verbatim} - - -NetBSD Make is included in any *BSD and can be run with just \textbf{make}. - \section{GETTING STARTED\label{GETTING_STARTED}\index{GETTING STARTED}} -On Linux: Extract, compile and install Fype: - -\begin{verbatim} - tar xvjf fype.tar.bz2 - cd fype - pmake - sudo pmake install - pmake clean -\end{verbatim} - - -On FreeBSD: Extract, compile and install Fype: +Extract, compile and install Fype: \begin{verbatim} tar xvjf fype.tar.bz2 @@ -179,7 +164,7 @@ All paranthesis of function calls are optional. They help to make the code bette \subsection*{Scopeing\label{Scopeing}\index{Scopeing}} -A new scope starts with an \{ and ends with an \}. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. The \textbf{scope} function will print out all available symbols at the current position. Here is a small example of how to use scopes: +A new scope starts with an \{ and ends with an \}. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. Here is a small example how to use scopes: \begin{verbatim} my foo = 1; @@ -194,11 +179,6 @@ A new scope starts with an \{ and ends with an \}. An exception is a procedure, \begin{verbatim} # Prints out 1 put defined bar; -\end{verbatim} -\begin{verbatim} - # Prints out all available symbols at this - # point to stdout. Those are: bar and foo - scope; } \end{verbatim} \begin{verbatim} @@ -277,56 +257,6 @@ not. say foo; } \end{verbatim} -\section{SYNONYMS\label{SYNONYMS}\index{SYNONYMS}} - - -Each variable can have as many synonyms as wished. A synonym is another name to access the content of a specific variable. Here is an example of how to use synomyms: - -\begin{verbatim} - my foo = "foo"; - my bar = \foo; - foo = "bar"; -\end{verbatim} -\begin{verbatim} - # The synonym variable should now also set to "bar" - assert "bar" == bar; -\end{verbatim} - - -Synonyms can be used for all kind of identifiers. It's not limited to normal variables but can be also used for function and procedure names etc. - -\begin{verbatim} - # Create a new procedure baz - proc baz { say "I am baz"; } -\end{verbatim} -\begin{verbatim} - # Make a synonym baz, and undefine baz - my bay = \baz; -\end{verbatim} -\begin{verbatim} - undef baz; -\end{verbatim} -\begin{verbatim} - # bay still has a reference of the original procedure baz - bay; # this prints aut "I am baz" -\end{verbatim} - - -The \textbf{syms} keyword gives you the total number of synonyms pointing to a specific value: - -\begin{verbatim} - my foo = 1; - say syms foo; # Prints 1 -\end{verbatim} -\begin{verbatim} - my baz = \foo; - say syms foo; # Prints 2 - say syms baz; # Prints 2 -\end{verbatim} -\begin{verbatim} - undef baz; - say syms foo; # Prints 1 -\end{verbatim} \section{BUILT IN FUNCTIONS\label{BUILT_IN_FUNCTIONS}\index{BUILT IN FUNCTIONS}} diff --git a/docs/pod/fype.txt b/docs/pod/fype.txt index 8513538..3cc7d20 100644 --- a/docs/pod/fype.txt +++ b/docs/pod/fype.txt @@ -1,7 +1,7 @@ NAME - Fype is For Your Program Execution + Fype is for your program execution - Fype is Free Yak Programed for ELF + Fype is free yack programed for ELF It's not a hype - it's Fype! @@ -41,26 +41,15 @@ PARSING / CODE GENERATION REQUIREMENTS Fype only has been tested on FreeBSD 7.0. Linux may work too. Windows - support is not planned. But may work using Cygwin or SFU. Linux users - have to install pmake before compiling Fype! + support is not planned. But may work using Cygwin or SFU. - You will need: + You will also need: GNU GCC C Compiler (gcc.gnu.org) - NetBSD Make aka pmake (GNU Make will not work) - - NetBSD Make is included in any *BSD and can be run with just make. + NetBSD Make aka pmake (GNU Make will not work) (it's included in any *BSD) GETTING STARTED - On Linux: Extract, compile and install Fype: - - tar xvjf fype.tar.bz2 - cd fype - pmake - sudo pmake install - pmake clean - - On FreeBSD: Extract, compile and install Fype: + Extract, compile and install Fype: tar xvjf fype.tar.bz2 cd fype @@ -134,9 +123,8 @@ SYNTAX Scopeing A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). - Control statements and functions support scopeings. The scope function - will print out all available symbols at the current position. Here is a - small example of how to use scopes: + Control statements and functions support scopeings. Here is a small + example how to use scopes: my foo = 1; @@ -148,10 +136,6 @@ SYNTAX # Prints out 1 put defined bar; - - # Prints out all available symbols at this - # point to stdout. Those are: bar and foo - scope; } # Prints out 0 @@ -210,46 +194,6 @@ VARIABLES say foo; } -SYNONYMS - Each variable can have as many synonyms as wished. A synonym is another - name to access the content of a specific variable. Here is an example of - how to use synomyms: - - my foo = "foo"; - my bar = \foo; - foo = "bar"; - - # The synonym variable should now also set to "bar" - assert "bar" == bar; - - Synonyms can be used for all kind of identifiers. It's not limited to - normal variables but can be also used for function and procedure names - etc. - - # Create a new procedure baz - proc baz { say "I am baz"; } - - # Make a synonym baz, and undefine baz - my bay = \baz; - - undef baz; - - # bay still has a reference of the original procedure baz - bay; # this prints aut "I am baz" - - The syms keyword gives you the total number of synonyms pointing to a - specific value: - - my foo = 1; - say syms foo; # Prints 1 - - my baz = \foo; - say syms foo; # Prints 2 - say syms baz; # Prints 2 - - undef baz; - say syms foo; # Prints 1 - BUILT IN FUNCTIONS In Fype, operators are built in functions as well. The difference is, that they may be written in infix notation instead in front of the @@ -308,7 +252,7 @@ BUILT IN FUNCTIONS This function always returns 1. The parameter is optional. # Prints out 1, because foo is not defined - if yes { say no defined foo; } + if yes { say no defined foo; } System (*void*) end diff --git a/docs/pod/pod2htmd.tmp b/docs/pod/pod2htmd.tmp new file mode 100644 index 0000000..61e86d9 --- /dev/null +++ b/docs/pod/pod2htmd.tmp @@ -0,0 +1,2 @@ + +. diff --git a/docs/pod/pod2htmi.tmp b/docs/pod/pod2htmi.tmp new file mode 100644 index 0000000..61e86d9 --- /dev/null +++ b/docs/pod/pod2htmi.tmp @@ -0,0 +1,2 @@ + +. diff --git a/docs/stats.txt b/docs/stats.txt index 50cbda1..b49fcc8 100644 --- a/docs/stats.txt +++ b/docs/stats.txt @@ -1,4 +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 +===> Num of C source files : 42 +===> Num of C source lines : 7460 +===> Num of Fype source examples : 13 +===> Num of Fype source lines : 321 diff --git a/docs/version.txt b/docs/version.txt index d2c768b..bfffb0d 100644 --- a/docs/version.txt +++ b/docs/version.txt @@ -1 +1 @@ -Fype2 Alpha Build 10387 +Fype v0.1 Build 9205 diff --git a/examples/all-examples.txt b/examples/all-examples.txt index f71e8a2..bdf199f 100644 --- a/examples/all-examples.txt +++ b/examples/all-examples.txt @@ -283,10 +283,6 @@ my foo = 1; # Prints out 1 assert 1 == (put defined bar); - - # Prints out all available symbols at - # the current program position. - scope; } # Prints out 0 @@ -301,44 +297,6 @@ assert 0 == (say defined bar); #* - * Examples of how to use synonyms - *# - -# Create a variable foo, and bar is a synonym for foo -my foo = "foo"; -my bar = \foo; - -# Reset the value of foo -foo = "bar"; - -# The synonym variable should now also set to "bar" -assert "bar" == say bar; - -# Create a new procedure baz -proc baz { - say "I am baz"; -} - -# Make a synonym baz, and undefine baz -my bay = \baz; - -# Should be the num of syms for the same value -assert 2 == syms baz; -assert 2 == syms bay; -undef baz; -assert 1 == syms bay; - -# bay still has a reference of the original procedure baz -bay; # this prints aut "I am baz" - -assert 0 == defined baz; -assert 1 == defined bay; - -# This removes the procedure from memory -undef bay; - - -#* * Examples how to convert types *# diff --git a/examples/scopeing.fy b/examples/scopeing.fy index 434f38f..2e36c2c 100644 --- a/examples/scopeing.fy +++ b/examples/scopeing.fy @@ -13,10 +13,6 @@ my foo = 1; # Prints out 1 assert 1 == (put defined bar); - - # Prints out all available symbols at - # the current program position. - scope; } # Prints out 0 @@ -1,12 +1,12 @@ /*:* *: File: ./src/argv.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -46,7 +46,7 @@ char *BINARY; void -argv_run(PBSc *p_fype, int i_argc, char **pc_argv) { +argv_run(Fype *p_fype, int i_argc, char **pc_argv) { Dat *p_dat_string = dat_new(); BINARY = pc_argv[0]; @@ -1,12 +1,12 @@ /*:* *: File: ./src/argv.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -38,7 +38,7 @@ #include "data/tupel.h" #include "fype.h" -void argv_run(PBSc *p_fype, int i_argc, char **pc_argv); +void argv_run(Fype *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(); diff --git a/src/build.h b/src/build.h index 1e6006e..85f7184 100644 --- a/src/build.h +++ b/src/build.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/build.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -35,7 +35,7 @@ #ifndef BUILD_H #define BUILD_H -#define BUILDNR 10388 -#define OS_LINUX +#define BUILDNR 9207 +#define OS_FREEBSD #endif diff --git a/src/core/convert.c b/src/core/convert.c index cf8987e..73fb8a2 100644 --- a/src/core/convert.c +++ b/src/core/convert.c @@ -1,14 +1,13 @@ /*:* *: File: ./src/core/convert.c *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: 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 @@ -16,25 +15,24 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: + *: THIS SOFTWARE IS PROVIDED BY Paul 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) + *: DISCLAIMED. IN NO EVENT SHALL Paul 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 + *: 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 "convert.h" -#include "../data/array.h" void convert_to_integer(Token *p_token) { @@ -49,10 +47,6 @@ convert_to_integer(Token *p_token) { token_set_tt(p_token, TT_INTEGER); token_set_ival(p_token, atoi(token_get_val(p_token))); break; - case TT_ARRAY: - token_set_tt(p_token, TT_INTEGER); - token_set_ival(p_token, array_get_size(p_token->p_array)); - break; default: ERROR("Ouups(%s)", tt_get_name(token_get_tt(p_token))); break; @@ -68,9 +62,6 @@ convert_to_integer_get(Token *p_token) { return ((int) token_get_dval(p_token)); case TT_STRING: return (atoi(token_get_val(p_token))); - case TT_ARRAY: - return (array_get_size(p_token->p_array)); - break; default: ERROR("Ouups(%s)", tt_get_name(token_get_tt(p_token))); } @@ -91,10 +82,6 @@ convert_to_double(Token *p_token) { token_set_tt(p_token, TT_DOUBLE); token_set_dval(p_token, atof(token_get_val(p_token))); break; - case TT_ARRAY: - token_set_tt(p_token, TT_DOUBLE); - token_set_dval(p_token, array_get_size(p_token->p_array)); - break; default: token_print_val(p_token); ERROR("Datatype conversion error '%s'", token_get_val(p_token)); @@ -126,16 +113,6 @@ convert_to_string(Token *p_token) { strcpy(p_token->c_val, c_tmp); p_token->c_val[i_len] = 0; } - case TT_ARRAY: - { - token_set_tt(p_token, TT_STRING); - char c_tmp[1024]; - sprintf(c_tmp, "%d", array_get_size(p_token->p_array)); - int i_len = strlen(c_tmp); - p_token->c_val = realloc(p_token->c_val, sizeof(char) * (i_len + 1)); - strcpy(p_token->c_val, c_tmp); - p_token->c_val[i_len] = 0; - } break; case TT_STRING: break; @@ -146,11 +123,6 @@ convert_to_string(Token *p_token) { } void -convert_to_array(Token *p_token) { - ERROR("not yet implemented"); -} - -void convert_to_tt(Token *p_token, TokenType tt) { switch (tt) { case TT_INTEGER: @@ -162,9 +134,6 @@ convert_to_tt(Token *p_token, TokenType tt) { case TT_STRING: convert_to_string(p_token); break; - case TT_ARRAY: - convert_to_array(p_token); - break; default: ERROR("Ouups!"); } diff --git a/src/core/convert.h b/src/core/convert.h index 9dcf23e..0c8b7da 100644 --- a/src/core/convert.h +++ b/src/core/convert.h @@ -1,14 +1,13 @@ /*:* *: File: ./src/core/convert.h *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: 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 @@ -16,20 +15,20 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: + *: THIS SOFTWARE IS PROVIDED BY Paul 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) + *: DISCLAIMED. IN NO EVENT SHALL Paul 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 + *: 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. *:*/ @@ -46,7 +45,6 @@ int convert_to_integer_get(Token *p_token); void convert_to_integer(Token *p_token); void convert_to_double(Token *p_token); void convert_to_string(Token *p_token); -void convert_to_array(Token *p_token); void convert_to_tt(Token *p_token, TokenType tt); TokenType convert_to_highest(Token *p_token1, Token *p_token2); TokenType convert_function_arg_types_to_highest(Stack *p_stack_args, int diff --git a/src/core/function.c b/src/core/function.c index 70166ed..fda40b8 100644 --- a/src/core/function.c +++ b/src/core/function.c @@ -1,14 +1,13 @@ /*:* *: File: ./src/core/function.c *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: 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 @@ -16,36 +15,844 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: + *: THIS SOFTWARE IS PROVIDED BY Paul 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) + *: DISCLAIMED. IN NO EVENT SHALL Paul 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 + *: 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 "../defines.h" +#include <stdlib.h> +#include <sys/types.h> +#include <unistd.h> #include "function.h" -Function* -function_new() { - Function *p_function = malloc(sizeof(Function)); +#include "convert.h" +#include "scope.h" +#include "symbol.h" - return (p_function); +#define _FUNCTION_ERROR(m,t) \ + ERROR(\ + "%s: Function error in %s line %d pos %d near '%s'", m, \ + token_get_filename(t), \ + token_get_line_nr(t), \ + token_get_pos_nr(t), \ + token_get_val(t) \ + ) + +void +_process(Interpret *p_interpret, Token *p_token_store, Token *p_token_op, + Token *p_token_op2, Token *p_token_next) { + + TokenType tt_op = token_get_tt(p_token_op); + TokenType tt_op2 = p_token_op2 == NULL + ? TT_NONE + : token_get_tt(p_token_op2); + +#ifdef DEBUG_FUNCTION_PROCESS + if (p_token_op2 == NULL) + printf("PROCESS OPERATOR %s\n", tt_get_name(tt_op)); + else + printf("PROCESS OPERATOR %s %s\n", tt_get_name(tt_op), + tt_get_name(tt_op2)); + + token_print(p_token_next); + printf("\n"); + token_print(p_token_store); + printf("\n"); +#endif /* DEBUG_FUNCTION_PROCESS */ + + if (p_token_op2 != NULL) { + switch (tt_op) { + case TT_NOT: + switch (tt_op2) { + case TT_ASSIGN: + tt_op = TT_NEQ; + break; + default: + break; + } + break; + case TT_ASSIGN: + switch (tt_op2) { + case TT_ASSIGN: + tt_op = TT_EQ; + break; + default: + break; + } + break; + case TT_LT: + switch (tt_op2) { + case TT_ASSIGN: + tt_op = TT_LE; + break; + default: + break; + } + break; + case TT_GT: + switch (tt_op2) { + case TT_ASSIGN: + tt_op = TT_GE; + break; + default: + break; + } + break; + case TT_DDOT: + switch (tt_op2) { + case TT_LT: + tt_op = TT_LSHIFT; + break; + case TT_GT: + tt_op = TT_RSHIFT; + break; + default: + break; + } + break; + default: + break; + } + } else { + switch (tt_op) { + case TT_ASSIGN: + { + Token *p_token_assign = p_interpret->p_token_temp; + TokenType tt_assign = token_get_tt(p_token_assign); + + if (tt_assign != TT_IDENT) { + _FUNCTION_ERROR("Can only assign to symbols", + p_token_store); + } + + Symbol *p_symbol = scope_get(p_interpret->p_scope, + token_get_val(p_token_assign)); + + if (p_symbol == NULL) { + _FUNCTION_ERROR("No such symbol", + p_token_assign); + } + + symbol_set_val(p_symbol, p_token_store); + symbol_set_sym(p_symbol, SYM_VARIABLE); + + return; + } + + break; + NO_DEFAULT; + } + } + + p_token_next = token_new_copy(p_token_next); + TokenType tt_highest = convert_to_highest(p_token_store, p_token_next); + +#ifdef DEBUG_FUNCTION_PROCESS + printf("===> %s %s %s\n", + tt_get_name(tt_highest), + tt_get_name(tt_op), + tt_get_name(tt_highest)); +#endif /* DEBUG_FUNCTION_PROCESS */ + + switch (tt_op) { + case TT_ADD: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + token_get_ival(p_token_next) + + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_dval(p_token_store, + token_get_dval(p_token_next) + + token_get_dval(p_token_store)); + case TT_STRING: + token_set_ival(p_token_store, + atoi(token_get_val(p_token_next)) + + atoi(token_get_val(p_token_store))); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_SUB: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + token_get_ival(p_token_next) - + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_dval(p_token_store, + token_get_dval(p_token_next) - + token_get_dval(p_token_store)); + break; + case TT_STRING: + token_set_ival(p_token_store, + atoi(token_get_val(p_token_next)) - + atoi(token_get_val(p_token_store))); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_MULT: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + token_get_ival(p_token_next) * + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_dval(p_token_store, + token_get_dval(p_token_next) * + token_get_dval(p_token_store)); + break; + case TT_STRING: + token_set_ival(p_token_store, + atoi(token_get_val(p_token_next)) * + atoi(token_get_val(p_token_store))); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_DIV: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) / + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_dval(p_token_store, + token_get_dval(p_token_next) / + token_get_dval(p_token_store)); + break; + case TT_STRING: + token_set_dval(p_token_store, + atof(token_get_val(p_token_next)) / + atof(token_get_val(p_token_store))); + token_set_tt(p_token_store, TT_DOUBLE); + break; + NO_DEFAULT; + } + break; + case TT_EQ: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) == + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + token_get_dval(p_token_next) == + token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + strcmp(token_get_val(p_token_next), + token_get_val(p_token_store)) == 0); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_NEQ: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) != + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + token_get_dval(p_token_next) != + token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + strcmp(token_get_val(p_token_next), + token_get_val(p_token_store)) != 0); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_LE: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) <= + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + token_get_dval(p_token_next) <= + token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + strcmp(token_get_val(p_token_next), + token_get_val(p_token_store)) <= 0); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_GE: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) >= + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + token_get_dval(p_token_next) >= + token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + strcmp(token_get_val(p_token_next), + token_get_val(p_token_store)) >= 0); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_LT: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) < + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + token_get_dval(p_token_next) < + token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + strcmp(token_get_val(p_token_next), + token_get_val(p_token_store)) < 0); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_GT: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) > + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + token_get_dval(p_token_next) > + token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + strcmp(token_get_val(p_token_next), + token_get_val(p_token_store)) > 0); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_AND: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) & + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + (int) token_get_dval(p_token_next) & + (int) token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + atoi(token_get_val(p_token_next)) & + atoi(token_get_val(p_token_store))); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_OR: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) | + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + (int) token_get_dval(p_token_next) | + (int) token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + atoi(token_get_val(p_token_next)) | + atoi(token_get_val(p_token_store))); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_XOR: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) ^ + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + (int) token_get_dval(p_token_next) ^ + (int) token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + atoi(token_get_val(p_token_next)) ^ + atoi(token_get_val(p_token_store))); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_LSHIFT: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) << + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + (int) token_get_dval(p_token_next) << + (int) token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + atoi(token_get_val(p_token_next)) << + atoi(token_get_val(p_token_store))); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + case TT_RSHIFT: + switch (tt_highest) { + case TT_INTEGER: + token_set_ival(p_token_store, + (int) token_get_ival(p_token_next) >> + token_get_ival(p_token_store)); + break; + case TT_DOUBLE: + token_set_ival(p_token_store, + (int) token_get_dval(p_token_next) >> + (int) token_get_dval(p_token_store)); + token_set_tt(p_token_store, TT_INTEGER); + break; + case TT_STRING: + token_set_ival(p_token_store, + atoi(token_get_val(p_token_next)) >> + atoi(token_get_val(p_token_store))); + token_set_tt(p_token_store, TT_INTEGER); + break; + NO_DEFAULT; + } + break; + + default: + _FUNCTION_ERROR("No such function/operator", p_token_op); + } + +#ifdef DEBUG_FUNCTION_PROCESS + token_print(p_token_store); + printf("\n\n"); +#endif /* DEBUG_FUNCTION_PROCESS */ + + token_delete(p_token_next); +} + +void +function_process(Interpret *p_interpret, Token *p_token_op, + Token *p_token_op2, Stack *p_stack_args, int i_args) { + + Token *p_token_store = token_new_copy(stack_pop(p_stack_args)); + + for (int i = 0; i < i_args -1 && !stack_empty(p_stack_args); ++i) { + Token *p_token_next = stack_pop(p_stack_args); + + _process(p_interpret, p_token_store, p_token_op, + p_token_op2, p_token_next); + } + + stack_push(p_stack_args, p_token_store); +} + +_Bool +function_is_buildin(Token *p_token_ident) { + if (strcmp("assert", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("decr", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("double", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("end", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("exit", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("fork", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("gc", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("incr", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("integer", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("ln", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("neg", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("no", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("put", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("say", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("string", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("yes", token_get_val(p_token_ident)) == 0) + return (true); + + if (strcmp("not", token_get_val(p_token_ident)) == 0) + return (true); + + return (false); +} + +void +function_process_buildin(Interpret *p_interpret, Token *p_token_ident, + Stack *p_stack_args) { + + if (strcmp("assert", token_get_val(p_token_ident)) == 0) { + if (0 == stack_size(p_stack_args)) + _FUNCTION_ERROR("No argument given", p_token_ident); + + Token *p_token = stack_top(p_stack_args); + + switch (token_get_tt(p_token)) { + case TT_INTEGER: + if (token_get_ival(p_token) == 0) + _FUNCTION_ERROR("Assert failed", p_token); + break; + case TT_DOUBLE: + if (token_get_dval(p_token) == 0) + _FUNCTION_ERROR("Assert failed", p_token); + break; + case TT_STRING: + if (atoi(token_get_val(p_token)) == 0) + _FUNCTION_ERROR("Assert failed", p_token); + break; + NO_DEFAULT; + } + + } else if (strcmp("decr", token_get_val(p_token_ident)) == 0) { + if (0 == stack_size(p_stack_args)) + _FUNCTION_ERROR("No argument given", p_token_ident); + + Token *p_token = stack_top(p_stack_args); + switch (token_get_tt(p_token)) { + case TT_INTEGER: + token_set_ival(p_token, token_get_ival(p_token) - 1); + break; + case TT_DOUBLE: + token_set_dval(p_token, token_get_dval(p_token) - 1); + break; + case TT_STRING: + convert_to_integer(p_token); + token_set_ival(p_token, token_get_ival(p_token) - 1); + break; + NO_DEFAULT; + } + + } else if (strcmp("double", token_get_val(p_token_ident)) == 0) { + if (0 == stack_size(p_stack_args)) + _FUNCTION_ERROR("No argument given", p_token_ident); + + Token *p_token = token_new_copy(stack_pop(p_stack_args)); + convert_to_double(p_token); + stack_push(p_stack_args, p_token); + + } else if (strcmp("end", token_get_val(p_token_ident)) == 0) { + exit(0); + + } else if (strcmp("fork", token_get_val(p_token_ident)) == 0) { + Token *p_token = token_new_integer((int) fork()); + stack_push(p_stack_args, p_token); + + } else if (strcmp("gc", token_get_val(p_token_ident)) == 0) { + int i_count = garbage_collect(); + printf("ICOUNT %d\n", i_count); + Token *p_token = token_new_integer(i_count); + stack_push(p_stack_args, p_token); + + } else if (strcmp("exit", token_get_val(p_token_ident)) == 0) { + if (0 == stack_size(p_stack_args)) + _FUNCTION_ERROR("No argument given", p_token_ident); + + Token *p_token = stack_top(p_stack_args); + p_token = token_new_copy(p_token); + convert_to_integer(p_token); + exit(token_get_ival(p_token)); + + } else if (strcmp("incr", token_get_val(p_token_ident)) == 0) { + if (0 == stack_size(p_stack_args)) + _FUNCTION_ERROR("No argument given", p_token_ident); + + Token *p_token = stack_top(p_stack_args); + switch (token_get_tt(p_token)) { + case TT_INTEGER: + token_set_ival(p_token, token_get_ival(p_token) + 1); + break; + case TT_DOUBLE: + token_set_dval(p_token, token_get_dval(p_token) + 1); + break; + case TT_STRING: + convert_to_integer(p_token); + token_set_ival(p_token, token_get_ival(p_token) + 1); + break; + NO_DEFAULT; + } + + } else if (strcmp("integer", token_get_val(p_token_ident)) == 0) { + if (0 == stack_size(p_stack_args)) + _FUNCTION_ERROR("No argument given", p_token_ident); + + Token *p_token = token_new_copy(stack_pop(p_stack_args)); + convert_to_integer(p_token); + stack_push(p_stack_args, p_token); + + } else if (strcmp("ln", token_get_val(p_token_ident)) == 0) { + printf("\n"); + + } else if (strcmp("neg", token_get_val(p_token_ident)) == 0) { + if (0 == stack_size(p_stack_args)) + _FUNCTION_ERROR("No argument given", p_token_ident); + + Token *p_token = token_new_copy(stack_pop(p_stack_args)); + stack_push(p_stack_args, p_token); + + switch (token_get_tt(p_token)) { + case TT_INTEGER: + token_set_ival(p_token, -token_get_ival(p_token)); + break; + case TT_DOUBLE: + token_set_dval(p_token, -token_get_dval(p_token)); + break; + case TT_STRING: + token_set_ival(p_token, -atoi(token_get_val(p_token))); + token_set_tt(p_token, TT_INTEGER); + break; + NO_DEFAULT; + } + + } else if (strcmp("no", token_get_val(p_token_ident)) == 0) { + Token *p_token = NULL; + + if (0 == stack_size(p_stack_args)) { + p_token = token_new_integer(0); + + } else { + p_token = token_new_copy(stack_pop(p_stack_args)); + + switch (token_get_tt(p_token)) { + case TT_INTEGER: + token_set_ival(p_token, !token_get_ival(p_token)); + break; + case TT_DOUBLE: + token_set_dval(p_token, !token_get_dval(p_token)); + break; + case TT_STRING: + token_set_ival(p_token, !atoi(token_get_val(p_token))); + token_set_tt(p_token, TT_INTEGER); + break; + NO_DEFAULT; + } + } + + stack_push(p_stack_args, p_token); + + } else if (strcmp("put", token_get_val(p_token_ident)) == 0) { + StackIterator *p_iter = stackiterator_new(p_stack_args); + while (stackiterator_has_next(p_iter)) { + Token *p_token = stackiterator_next(p_iter); + switch (token_get_tt(p_token)) { + case TT_INTEGER: + printf("%d", token_get_ival(p_token)); + break; + case TT_DOUBLE: + printf("%f", token_get_dval(p_token)); + break; + case TT_STRING: + printf("%s", token_get_val(p_token)); + break; + NO_DEFAULT; + } + } + stackiterator_delete(p_iter); + + } else if (strcmp("say", token_get_val(p_token_ident)) == 0) { + StackIterator *p_iter = stackiterator_new(p_stack_args); + while (stackiterator_has_next(p_iter)) { + Token *p_token = stackiterator_next(p_iter); + switch (token_get_tt(p_token)) { + case TT_INTEGER: + printf("%d", token_get_ival(p_token)); + break; + case TT_DOUBLE: + printf("%f", token_get_dval(p_token)); + break; + case TT_STRING: + printf("%s", token_get_val(p_token)); + break; + NO_DEFAULT; + } + } + stackiterator_delete(p_iter); + printf("\n"); + + } else if (strcmp("string", token_get_val(p_token_ident)) == 0) { + if (0 == stack_size(p_stack_args)) + _FUNCTION_ERROR("No argument given", p_token_ident); + + Token *p_token = token_new_copy(stack_pop(p_stack_args)); + convert_to_string(p_token); + stack_push(p_stack_args, p_token); + + } else if (strcmp("yes", token_get_val(p_token_ident)) == 0) { + Token *p_token = NULL; + + if (0 == stack_size(p_stack_args)) { + p_token = token_new_integer(1); + + } else { + p_token = token_new_copy(stack_pop(p_stack_args)); + token_set_ival(p_token, 1); + token_set_tt(p_token, TT_INTEGER); + + } + + stack_push(p_stack_args, p_token); + + } else if (strcmp("not", token_get_val(p_token_ident)) == 0) { + if (0 == stack_size(p_stack_args)) + _FUNCTION_ERROR("No argument given", p_token_ident); + + Token *p_token = token_new_copy(stack_pop(p_stack_args)); + stack_push(p_stack_args, p_token); + + switch (token_get_tt(p_token)) { + case TT_INTEGER: + token_set_ival(p_token, !token_get_ival(p_token)); + break; + case TT_DOUBLE: + token_set_dval(p_token, !token_get_dval(p_token)); + break; + case TT_STRING: + token_set_ival(p_token, !atoi(token_get_val(p_token))); + token_set_tt(p_token, TT_INTEGER); + break; + NO_DEFAULT; + } + } +} + +_Bool +function_is_self_defined(Interpret *p_interpret) { + Symbol *p_symbol = scope_get(p_interpret->p_scope, + token_get_val(p_interpret->p_token)); + + if (p_symbol == NULL) + return (false); + + switch (symbol_get_sym(p_symbol)) { + case SYM_PROCEDURE: + case SYM_FUNCTION: + return (true); + NO_DEFAULT; + } + + return (false); } void -function_delete(Function *p_function) { - free(p_function); +function_process_self_defined(Interpret *p_interpret, Token *p_token_ident) { + Symbol *p_symbol = scope_get(p_interpret->p_scope, + token_get_val(p_token_ident)); + + switch (symbol_get_sym(p_symbol)) { + case SYM_PROCEDURE: + { + List *p_list_token = symbol_get_val(p_symbol); + interpret_subprocess(p_interpret, p_list_token); + } + break; + case SYM_FUNCTION: + { + List *p_list_token = symbol_get_val(p_symbol); + scope_up(p_interpret->p_scope); + interpret_subprocess(p_interpret, p_list_token); + scope_down(p_interpret->p_scope); + } + NO_DEFAULT; + } } diff --git a/src/core/function.h b/src/core/function.h index 748ebce..618ed94 100644 --- a/src/core/function.h +++ b/src/core/function.h @@ -1,14 +1,13 @@ /*:* *: File: ./src/core/function.h *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: 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 @@ -16,31 +15,36 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: + *: THIS SOFTWARE IS PROVIDED BY Paul 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) + *: DISCLAIMED. IN NO EVENT SHALL Paul 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 + *: 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 FUNCTION_H #define FUNCTION_H -typedef struct { - char *c_name; -} Function; +#include "token.h" -Function* function_new(); -void function_delete(Function *p_function); +#include "interpret.h" +#include "../data/stack.h" + +void function_process(Interpret *p_interp, Token *p_token_op, + Token *p_token_op2, Stack *p_stack_args, int i_args); +_Bool function_is_buildin(Token *p_token_ident); +void function_process_buildin(Interpret *p_interpret, Token *p_token_ident, Stack *p_stack_args); +_Bool function_is_self_defined(Interpret *p_interpret); +void function_process_self_defined(Interpret *p_interpret, Token *p_token_ident); #endif /* FUNCTION_H */ diff --git a/src/core/garbage.c b/src/core/garbage.c index 23c73b8..aba19c4 100644 --- a/src/core/garbage.c +++ b/src/core/garbage.c @@ -1,14 +1,13 @@ /*:* *: File: ./src/core/garbage.c *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: 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 @@ -16,20 +15,20 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: + *: THIS SOFTWARE IS PROVIDED BY Paul 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) + *: DISCLAIMED. IN NO EVENT SHALL Paul 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 + *: 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. *:*/ @@ -42,7 +41,6 @@ List *LIST_GARBAGE = NULL; typedef struct { void (*p_func)(void*); - void (*p_print)(void*); int *p_ref_count; void *p_2free; GarbageType type; @@ -54,12 +52,32 @@ garbage_init() { } void +_garbage_print(_Garbage *p_garbage) { + switch (p_garbage->type) { + case GC_TOKEN: + { + Token *p_token = p_garbage->p_2free; + token_print(p_token); + printf("\n"); + } + break; + } +} + +void garbage_destroy() { garbage_collect(); + if (!list_empty(LIST_GARBAGE)) { - EPRINTF("The garbage collector still has %d registered items " - " which don't have a zero ref count!\n", - list_size(LIST_GARBAGE)); + EPRINTF("The garbage collector still has %d registered items which don't have" + " a zero ref count!\n", list_size(LIST_GARBAGE)); + + ListIterator *p_iter = listiterator_new(LIST_GARBAGE); + while (listiterator_has_next(p_iter)) { + _Garbage *p_garbage = listiterator_next(p_iter); + _garbage_print(p_garbage); + } + listiterator_delete(p_iter); _GARBAGE_ERROR("Garbage left"); } @@ -77,13 +95,7 @@ garbage_collect() { _Garbage *p_garbage = listiterator_next(p_iter); if (p_garbage->p_ref_count == NULL || *p_garbage->p_ref_count <= 0) { -#ifdef DEBUG_GC - printf("DEBUG::GC: Freeing "); - if (NULL != p_garbage->p_print) - (*p_garbage->p_print) (p_garbage->p_2free); - else - printf("0x%x\n", (int) p_garbage->p_2free); -#endif /* DEBUG_GC */ + // _garbage_print(p_garbage); (*p_garbage->p_func) (p_garbage->p_2free); free(p_garbage); ++i_count; @@ -97,9 +109,6 @@ garbage_collect() { list_delete(LIST_GARBAGE); LIST_GARBAGE = p_list_garbage_new; -#ifdef DEBUG_GC - printf("DEBUG::GC: Freed %d items\n", i_count); -#endif /* DEBUG_GC */ return (i_count); } @@ -110,25 +119,11 @@ garbage_add(void *p, GarbageType type) { } void -garbage_add2(void *p, - void (*p_func)(void*), - int *p_ref_count, - GarbageType type) { - garbage_add3(p, free, p_func, NULL, type); -} - -void -garbage_add3(void *p, - void (*p_func)(void*), - void (*p_print)(void*), - int *p_ref_count, - GarbageType type) { - +garbage_add2(void *p, void (*p_func)(void*), int *p_ref_count, GarbageType type) { _Garbage *p_garbage = malloc(sizeof(_Garbage)); p_garbage->p_2free = p; p_garbage->p_func = p_func; - p_garbage->p_print = p_print; p_garbage->p_ref_count = p_ref_count; p_garbage->type = type; @@ -137,8 +132,5 @@ garbage_add3(void *p, void garbage_add_token(Token *p_token) { - garbage_add3(p_token, - token_delete_cb, - token_print_cb, - &p_token->i_ref_count, GC_TOKEN); + garbage_add2(p_token, token_delete_cb, &p_token->i_ref_count, GC_TOKEN); } diff --git a/src/core/garbage.h b/src/core/garbage.h index f7533eb..8a8a820 100644 --- a/src/core/garbage.h +++ b/src/core/garbage.h @@ -1,14 +1,13 @@ /*:* *: File: ./src/core/garbage.h *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: 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 @@ -16,20 +15,20 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: + *: THIS SOFTWARE IS PROVIDED BY Paul 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) + *: DISCLAIMED. IN NO EVENT SHALL Paul 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 + *: 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. *:*/ @@ -48,12 +47,7 @@ void garbage_init(); void garbage_destroy(); int garbage_collect(); void garbage_add(void *p, GarbageType type); -void garbage_add2(void *p, void (*p_func)(void*), - int *p_ref_count, - GarbageType type); -void garbage_add3(void *p, void (*p_func)(void*), - void (*p_print)(void*), - int *p_ref_count, +void garbage_add2(void *p, void (*p_func)(void*), int *p_ref_count, GarbageType type); void garbage_add_token(Token *p_token); diff --git a/src/core/interpret.c b/src/core/interpret.c index 28239ef..9728932 100644 --- a/src/core/interpret.c +++ b/src/core/interpret.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/core/interpret.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -33,347 +33,956 @@ *:*/ #include "interpret.h" -#include "promise.h" -#include "variable.h" -#include "tools.h" -void _eval(Interpret *p_inter); +#include "../defines.h" +#include "convert.h" +#include "function.h" +#include "symbol.h" + +#define _INTERPRET_ERROR(m,t) \ + ERROR(\ + "%s: Interpret error in %s line %d pos %d near '%s'", m, \ + token_get_filename(t), \ + token_get_line_nr(t), \ + token_get_pos_nr(t), \ + token_get_val(t) \ + ) + +#define _CHECK if (p_interpret->p_token == NULL) return (0); +#define _HAS_NEXT listiterator_has_next(p_interpret->p_iter) +#define _NEXT if (!_next(p_interpret)) { return (2); } +#define _NEXT_TT _next_tt(p_interpret) +#define _SKIP _next(p_interpret); + +void _print_lookahead(Interpret *p_interpret); +int _next(Interpret *p_interpret); +int _program(Interpret *p_interpret); +int _var_decl(Interpret *p_interpret); +int _var_assign(Interpret *p_interpret); +int _var_list(Interpret *p_interpret); +int _expression_get(Interpret *p_interpret, List *p_list_block); +int _block_get(Interpret *p_interpret, List *p_list_block); +int _block_skip(Interpret *p_interpret); +int _proc_decl(Interpret *p_interpret); +int _func_decl(Interpret *p_interpret); +int _statement(Interpret *p_interpret); +int _block(Interpret *p_interpret); +int _expression(Interpret *p_interpret); +int _expression_(Interpret *p_interpret); +int _control(Interpret *p_interpret); +int _compare(Interpret *p_interpret); +int _sum(Interpret *p_interpret); +int _product(Interpret *p_interpret); +int _product2(Interpret *p_interpret); +int _term(Interpret *p_interpret); Interpret* -interpret_new(List *p_list_token) { - Interpret *p_inter = malloc(sizeof(Interpret)); +interpret_new(List *p_list_token, Hash *p_hash_syms) { + Interpret *p_interpret = malloc(sizeof(Interpret)); - p_inter->p_frame = frame_new(NULL); + if (p_hash_syms != NULL) { + p_interpret->p_scope = scope_new(p_hash_syms); + p_interpret->b_scope_delete = true; - p_inter->p_list_token = p_list_token; - p_inter->p_token = NULL; - - p_inter->i_pcount = 0; + } else { + p_interpret->p_scope = NULL; + p_interpret->b_scope_delete = false; + } - p_inter->b_is_lambda_interpretation = false; - p_inter->p_lambda = NULL; + p_interpret->p_list_token = p_list_token; + p_interpret->p_stack = stack_new(); + p_interpret->tt = TT_NONE; + p_interpret->p_token = NULL; + p_interpret->tt_prev = TT_NONE; + p_interpret->p_token_prev = NULL; + p_interpret->p_token_temp = NULL; + p_interpret->ct = CONTROL_NONE; - return (p_inter); + return (p_interpret); } -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; +void +interpret_delete(Interpret *p_interpret) { + if (!p_interpret) + return; - p_inter_up->b_is_lambda_interpretation = true; - p_inter_up->p_lambda = p_lambda; + if (p_interpret->b_scope_delete) + scope_delete(p_interpret->p_scope); - return (p_inter_up); + stack_delete(p_interpret->p_stack); + free(p_interpret); } void -interpret_delete(Interpret *p_inter) { - frame_delete(p_inter->p_frame); - free(p_inter); +_print_lookahead(Interpret *p_interpret) { + ListIterator *p_iter = p_interpret->p_iter; + ListIteratorState *p_state = listiterator_get_state(p_iter); + + printf("LOOLAHEAD:\n"); + + token_print(p_interpret->p_token); + printf("\n"); + + while (listiterator_has_next(p_iter)) { + Token *p_token = listiterator_next(p_iter); + token_print(p_token); + printf("\n"); + } + + listiterator_set_state(p_iter, p_state); + listiteratorstate_delete(p_state); } -void -interpret_run(PBSc *p_fype) { - Interpret *p_inter = - interpret_new(p_fype->p_list_token); +int +_next(Interpret *p_interpret) { + if (listiterator_has_next(p_interpret->p_iter)) { + p_interpret->p_token_prev = p_interpret->p_token; + p_interpret->tt_prev = p_interpret->tt; - _eval(p_inter); + p_interpret->p_token = listiterator_next(p_interpret->p_iter); + p_interpret->tt = token_get_tt(p_interpret->p_token); + return (1); + } + + p_interpret->p_token = NULL; + p_interpret->tt = TT_NONE; - interpret_delete(p_inter); + return (0); } -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); +TokenType +_next_tt(Interpret *p_interpret) { + if (listiterator_has_next(p_interpret->p_iter)) { + Token *p_token = listiterator_current(p_interpret->p_iter); + return (token_get_tt(p_token)); + } + + return (TT_NONE); +} + +int +_program(Interpret *p_interpret) { + _CHECK TRACK + + while (_statement(p_interpret) == 1) + garbage_collect(); + + return (1); +} + +int +_var_decl(Interpret *p_interpret) { + _CHECK TRACK + + switch (p_interpret->tt) { + //case TT_ARR: //TODO cleanup TT_ARR + case TT_MY: + { + if (_NEXT_TT != TT_IDENT) + _INTERPRET_ERROR("'my' expects identifier", p_interpret->p_token); + + _NEXT + + Token *p_token_ident = p_interpret->p_token; + + _var_assign(p_interpret); + _var_list(p_interpret); + + if (p_interpret->tt == TT_SEMICOLON) { + _NEXT + return (1); + + } else if (p_interpret->p_token != NULL) { + _INTERPRET_ERROR("Expected ';'", p_interpret->p_token); + + } else { + _INTERPRET_ERROR("Expected ';' after", p_token_ident); } - break; - default: - ERROR_INTERPRET("Expected ( or identifier", p_token); + } + default: + break; + } + + return (0); +} + +int +_var_assign(Interpret *p_interpret) { + _CHECK TRACK + + if (p_interpret->tt == TT_IDENT) { + Token *p_token = p_interpret->p_token; + _NEXT + + char *c_name = token_get_val(p_token); + if (scope_exists(p_interpret->p_scope, c_name)) { + _INTERPRET_ERROR("Symbol already defined", p_token); } - } else if (p_token->tt_cur == TT_PARANT_L) { - List *p_list_args = list_new(); + if (p_interpret->tt == TT_ASSIGN) { + _NEXT - if (!listiterator_has_next(p_iter)) - ERROR_INTERPRET("Expected identifier", p_token); + Stack *p_stack = p_interpret->p_stack; + p_interpret->p_stack = stack_new(); - p_token = listiterator_next(p_iter); - if (p_token->tt_cur != TT_IDENT) - ERROR_INTERPRET("Expected identifier", p_token); + if (_expression_(p_interpret)) { + function_process_buildin(p_interpret, p_token, + p_interpret->p_stack); - c_name = p_token->c_val; - while (listiterator_has_next(p_iter)) { - p_token = listiterator_next(p_iter); + stack_merge(p_stack, p_interpret->p_stack); + stack_delete(p_interpret->p_stack); + p_interpret->p_stack = p_stack; - if (p_token->tt_cur != TT_IDENT) { - if (p_token->tt_cur != TT_PARANT_R) - ERROR_INTERPRET("Expected identifier or )", p_token); - break; + p_token = stack_top(p_interpret->p_stack); + Symbol *p_symbol = symbol_new(SYM_VARIABLE, p_token); + scope_newset(p_interpret->p_scope, c_name, p_symbol); } else { - list_add_back(p_list_args, p_token->c_val); + return (0); } + + } else { + Token *p_token = token_new_integer(0); + Symbol *p_symbol = symbol_new(SYM_VARIABLE, p_token); + scope_newset(p_interpret->p_scope, c_name, p_symbol); } + } - 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); + return (1); +} + +int +_var_list(Interpret *p_interpret) { + _CHECK TRACK + + if (p_interpret->tt == TT_COMMA) { + _NEXT + _var_assign(p_interpret); + _var_list(p_interpret); } - if (!b_success) - ERROR("Forbidden to redef symbol \"%s\" @ current frame", c_name); + return (1); } -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; +int +_block_get(Interpret *p_interpret, List *p_list_block) { + if (p_interpret->tt != TT_PARANT_CL) + _INTERPRET_ERROR("Expected '{'", p_interpret->p_token); + _NEXT + + int i_num_parant = 0; + + for (;;) { + if (p_interpret->tt == TT_PARANT_CL) { + ++i_num_parant; + + } else if (p_interpret->tt == TT_PARANT_CR) { + if (--i_num_parant == -1) { + _NEXT + break; /* for */ + } } + + list_add_back(p_list_block, p_interpret->p_token); + + _NEXT } + +#ifdef DEBUG_BLOCK_GET + printf("====> BLOCK\n"); + list_iterate(p_list_block, token_print_cb); + printf("<==== BLOCK\n"); +#endif /* DEBUG_BLOCK_GET */ + + return (1); } -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); - } +int +_expression_get(Interpret *p_interpret, List *p_list_expression) { + for (;;) { + if (p_interpret->tt == TT_PARANT_CL) { + break; /* for */ + } + + list_add_back(p_list_expression, p_interpret->p_token); + + _NEXT + } + +#ifdef DEBUG_EXPRESSION_GET + printf("====> EXPRESSION\n"); + list_iterate(p_list_expression, token_print_cb); + printf("<==== EXPRESSION\n"); +#endif /* DEBUG_EXPRESSION_GET */ + + return (1); +} + +int +_block_skip(Interpret *p_interpret) { + if (p_interpret->tt != TT_PARANT_CL) + _INTERPRET_ERROR("Expected '{'", p_interpret->p_token); + _NEXT + + int i_num_parant = 0; + + for (;;) { + if (p_interpret->tt == TT_PARANT_CL) { + ++i_num_parant; + + } else if (p_interpret->tt == TT_PARANT_CR) { + if (--i_num_parant == -1) { + _NEXT + break; /* for */ } - break; - case TT_PARANT_R: - ERROR_INTERPRET("Didn't expect ) here", p_token); + } + + _NEXT + } + + return (1); +} + +int +_proc_decl(Interpret *p_interpret) { + _CHECK TRACK + + if (p_interpret->tt == TT_PROC) { + _NEXT + + if (p_interpret->tt != TT_IDENT) + _INTERPRET_ERROR("Expected identifier", p_interpret->p_token); + + Token *p_token_ident = p_interpret->p_token; + _NEXT + + if (scope_exists(p_interpret->p_scope, token_get_val(p_token_ident))) { + _INTERPRET_ERROR("Symbol already defined", p_token_ident); + } + + List *p_list_proc = list_new(); + + if (_block_get(p_interpret, p_list_proc)) { + + Symbol *p_symbol = symbol_new(SYM_PROCEDURE, p_list_proc); + scope_newset(p_interpret->p_scope, token_get_val(p_token_ident), + p_symbol); + + return (1); + } + + list_delete(p_list_proc); + } + + return (0); +} + +int +_func_decl(Interpret *p_interpret) { + _CHECK TRACK + + if (p_interpret->tt == TT_FUNC) { + _NEXT + + if (p_interpret->tt != TT_IDENT) + _INTERPRET_ERROR("Expected identifier", p_interpret->p_token); + + Token *p_token_ident = p_interpret->p_token; + _NEXT + + if (scope_exists(p_interpret->p_scope, token_get_val(p_token_ident))) { + _INTERPRET_ERROR("Symbol already defined", p_token_ident); + } + + List *p_list_proc = list_new(); + + if (_block_get(p_interpret, p_list_proc)) { + + Symbol *p_symbol = symbol_new(SYM_FUNCTION, p_list_proc); + scope_newset(p_interpret->p_scope, token_get_val(p_token_ident), + p_symbol); + + return (1); + } + + list_delete(p_list_proc); + } + + return (0); +} + +int +_statement(Interpret *p_interpret) { + _CHECK TRACK + + for (int i = 0; i < 2; ++i) { + if (_proc_decl(p_interpret)) return (1); + if (_func_decl(p_interpret)) return (1); + if (_var_decl(p_interpret)) return (1); + if (_control(p_interpret)) return (1); + if (_expression(p_interpret)) return (1); + if (_block(p_interpret)) return (1); + } + + return (0); +} + +int +_block(Interpret *p_interpret) { + if (p_interpret->tt == TT_PARANT_CL) { + List *p_list_block = list_new(); + + if (_block_get(p_interpret, p_list_block)) { + scope_up(p_interpret->p_scope); + interpret_subprocess(p_interpret, p_list_block); + scope_down(p_interpret->p_scope); + list_delete(p_list_block); + return (1); + } + + list_delete(p_list_block); + } + + return (0); +} + +int +_expression(Interpret *p_interpret) { + _CHECK TRACK + + if (_expression_(p_interpret)) { + if (p_interpret->tt == TT_SEMICOLON) { + _NEXT + + } else { + _INTERPRET_ERROR("Expected ';'", p_interpret->p_token); + } + + stack_clear(p_interpret->p_stack); + return (1); + } + + return (0); +} + +int +_expression_(Interpret *p_interpret) { + return (_compare(p_interpret)); +} + +int +_control(Interpret *p_interpret) { + _CHECK TRACK + + Token *p_token = p_interpret->p_token; + + switch (p_interpret->tt) { + case TT_IF: + case TT_IFNOT: + { + TokenType tt = p_interpret->tt; + _NEXT + if (_expression_(p_interpret)) { + Token *p_token_top = stack_pop(p_interpret->p_stack); + List *p_list_block = list_new(); + _block_get(p_interpret, p_list_block); + int ret = 0; + + switch (tt) { + case TT_IF: + if (convert_to_integer_get(p_token_top)) { + scope_up(p_interpret->p_scope); + ret = interpret_subprocess(p_interpret, p_list_block); + scope_down(p_interpret->p_scope); + } 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); + case TT_IFNOT: + if (!convert_to_integer_get(p_token_top)) { + scope_up(p_interpret->p_scope); + ret = interpret_subprocess(p_interpret, p_list_block); + scope_down(p_interpret->p_scope); } + break; + NO_DEFAULT; } - break; - } + + list_delete(p_list_block); + return (1); + + } else { + _INTERPRET_ERROR("Expected expression after control keyword", p_token); } + } + break; + case TT_WHILE: + case TT_UNTIL: + { + TokenType tt = p_interpret->tt; + List *p_list_expr = list_new(), *p_list_block = list_new(); + _Bool b_flag = true; + + _NEXT + + _expression_get(p_interpret, p_list_expr); + _block_get(p_interpret, p_list_block); + Token *p_token_backup = p_interpret->p_token; - listiterator_delete(p_iter_args); + do { + Stack *p_stack_backup = p_interpret->p_stack; + p_interpret->p_stack = stack_new(); + + ListIterator *p_iter_backup = p_interpret->p_iter; + p_interpret->p_iter = listiterator_new(p_list_expr); + + _NEXT + + /* Dont use if here, because we want to check the p_itnerpret->ct */ + if (_expression_(p_interpret)) { + Token *p_token_top = stack_pop(p_interpret->p_stack); + + if (p_token_top == NULL) { + printf("FOO\n"); + exit(0); + } + if (tt == TT_WHILE) { + if (convert_to_integer_get(p_token_top)) { + scope_up(p_interpret->p_scope); + interpret_subprocess(p_interpret, p_list_block); + scope_down(p_interpret->p_scope); + + } else { + b_flag = false; + } + + } else if (tt == TT_UNTIL) { + if (!convert_to_integer_get(p_token_top)) { + scope_up(p_interpret->p_scope); + interpret_subprocess(p_interpret, p_list_block); + scope_down(p_interpret->p_scope); + + } else { + b_flag = false; + } + } + + /* + switch (p_interpret->ct) { + case CONTROL_BREAK: + p_interpret->ct = CONTROL_NONE; + b_flag = false; + break; + case CONTROL_NEXT: + p_interpret->ct = CONTROL_NONE; + break; + NO_DEFAULT; + } + */ + + } else { + _INTERPRET_ERROR("Expected expression after control keyword", p_token); + } + + listiterator_delete(p_interpret->p_iter); + p_interpret->p_iter = p_iter_backup; + + stack_delete(p_interpret->p_stack); + p_interpret->p_stack = p_stack_backup; + + } while (b_flag); + + list_delete(p_list_expr); + list_delete(p_list_block); + p_interpret->p_token = p_token_backup; + p_interpret->tt = token_get_tt(p_token_backup); + + return (1); } + break; + NO_DEFAULT; + } + + return (0); +} + +int +_compare(Interpret *p_interpret) { + _CHECK TRACK + + if (_sum(p_interpret)) { + _Bool b_flag = true; + + do { + switch (p_interpret->tt) { + case TT_NOT: + case TT_ASSIGN: + case TT_LT: + case TT_GT: + { + Token *p_token_op = p_interpret->p_token; + Token *p_token_op2 = NULL; + _NEXT + + switch (p_interpret->tt) { + case TT_NOT: + case TT_ASSIGN: + case TT_LT: + case TT_GT: + p_token_op2 = p_interpret->p_token; + _NEXT + default: + break; + } + + if (!_sum(p_interpret)) + _INTERPRET_ERROR("Expected sum", p_interpret->p_token); + + function_process(p_interpret, p_token_op, p_token_op2, + p_interpret->p_stack, 2); + } + break; /* case */ + + default: + b_flag = false; + break; - if (!listiterator_has_next(p_iter)) - ERROR_EOB; + } /* switch */ - _eval(p_inter_local); - interpret_delete(p_inter_local); + } while (b_flag); + + return (1); + } + + return (0); } -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"); +int +_sum(Interpret *p_interpret) { + _CHECK TRACK + + if (_product(p_interpret)) { + _Bool b_flag = true; + + do { + Token *p_token_op2 = NULL, *p_token_tmp = NULL; + + switch (p_interpret->tt) { + case TT_DDOT: + p_token_tmp = p_interpret->p_token; + _NEXT + case TT_ADD: + case TT_SUB: + case TT_AND: + case TT_OR: + case TT_XOR: + { + Token *p_token_op = p_interpret->p_token; + _NEXT + + if (p_token_tmp != NULL) { + p_token_op2 = p_token_op; + p_token_op = p_token_tmp;; + } + + if (!_product(p_interpret)) + _INTERPRET_ERROR("Expected product", p_token_op); + + function_process(p_interpret, p_token_op, p_token_op2, + p_interpret->p_stack, 2); + + } + break; /* case */ + + default: + b_flag = false; + break; + + } /* switch */ + + } while (b_flag); + + return (1); } - break; - case ST_VARIABLE: - break; + + return (0); +} + +int +_product(Interpret *p_interpret) { + _CHECK TRACK + + if (_product2(p_interpret)) { + _Bool b_flag = true; + + do { + switch (p_interpret->tt) { + case TT_MULT: + case TT_DIV: + { + Token *p_token = p_interpret->p_token; + _NEXT + + if (!_product2(p_interpret)) + _INTERPRET_ERROR("Expected product2", p_token); + + function_process(p_interpret, p_token, NULL, + p_interpret->p_stack, 2); + + } + break; /* case */ + + default: + b_flag = false; + break; + + } /* switch */ + + } while (b_flag); + + return (1); } + + return (0); } -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; +int +_product2(Interpret *p_interpret) { + _CHECK TRACK + + if (_term(p_interpret)) { + _Bool b_flag = true; + + do { + if (p_interpret->tt == TT_ASSIGN + && IS_NOT_OPERATOR(_NEXT_TT)) { + Token *p_token = p_interpret->p_token; + Token *p_token_temp = p_interpret->p_token_prev; + _NEXT - } else if (p_token->tt_cur == TT_PARANT_R) { - if (--p_inter->i_pcount == 0) - return (NULL); + if (!_expression_(p_interpret)) + _INTERPRET_ERROR("Expected expression", p_token); - else if (p_inter->i_pcount < 0) - ERROR_INTERPRET("Too many closing )'s", - p_token); + p_interpret->p_token_temp = p_token_temp; + function_process(p_interpret, p_token, NULL, + p_interpret->p_stack, 2); + p_interpret->p_token_temp = NULL; + + } else { + b_flag = false; + break; + } /* if */ + } while (b_flag); + + return (1); } - return (p_token); + return (0); } -void -_run_func(Interpret *p_inter, Token *p_token, ListIterator *p_iter) { - Frame *p_frame = p_inter->p_frame; - Symbol *p_symbol = NULL; +int +_term(Interpret *p_interpret) { + _CHECK TRACK + + switch (p_interpret->tt) { + case TT_INTEGER: + case TT_DOUBLE: + case TT_STRING: + stack_push(p_interpret->p_stack, p_interpret->p_token); + _NEXT + return (1); + + case TT_IDENT: + { + if (_NEXT_TT != TT_ASSIGN) { + if (function_is_buildin(p_interpret->p_token)) { + Token *p_token = p_interpret->p_token; + Stack *p_stack = p_interpret->p_stack; + p_interpret->p_stack = stack_new(); + + if (_HAS_NEXT) { + _NEXT + if (_expression_(p_interpret)); + + } else { + _SKIP + } - if (listiterator_has_next(p_iter)) { - if (! (p_token = _parant(p_inter, listiterator_next(p_iter))) ) - return; + function_process_buildin(p_interpret, p_token, + p_interpret->p_stack); - //printf("::Interpreting: %s\n", p_token->c_val); + stack_merge(p_stack, p_interpret->p_stack); + stack_delete(p_interpret->p_stack); + p_interpret->p_stack = p_stack; - if (token_is(p_token, "def")) { + return (1); - _def(p_inter, p_token, p_iter); + } else if (function_is_self_defined(p_interpret)) { + Token *p_token = p_interpret->p_token; + Stack *p_stack = p_interpret->p_stack; + p_interpret->p_stack = stack_new(); + + _NEXT + if (_expression_(p_interpret)); + + function_process_self_defined(p_interpret, p_token); + + if (stack_empty(p_interpret->p_stack)) { + Token *p_token = token_new_dummy(); + token_set_tt(p_token, TT_INTEGER); + token_set_ival(p_token, 0); + stack_push(p_interpret->p_stack, p_token); + } + + stack_merge(p_stack, p_interpret->p_stack); + stack_delete(p_interpret->p_stack); + p_interpret->p_stack = p_stack; + + return (1); + } + } - } else if (token_is(p_token, "say")) { - _say(p_inter, p_token, p_iter); + /* It is not a function, it is a variable or some sort of */ - } else if (token_is(p_token, "noop")) { + char *c_name = token_get_val(p_interpret->p_token); + Symbol *p_symbol = scope_get(p_interpret->p_scope, c_name); - } else if ( (p_symbol = frame_get_symbol(p_frame, p_token->c_val)) != NULL ) { - _eval_symbol(p_inter, p_symbol, p_iter); + if (p_symbol == NULL) + _INTERPRET_ERROR("No such symbol", p_interpret->p_token); - } else if (token_is(p_token, "show-frames")) { - frame_print(p_inter->p_frame); + SymbolType st = symbol_get_sym(p_symbol); - } else if (token_is(p_token, "beep")) { - printf("BEEP\n"); + switch (st) { + case SYM_VARIABLE: + stack_push(p_interpret->p_stack, symbol_get_val(p_symbol)); + _NEXT + return (1); + + /* Example: proc foo { foo = "Hello"; } foo; say foo; */ + case SYM_PROCEDURE: + stack_push(p_interpret->p_stack, symbol_get_val(p_symbol)); + _NEXT + return (1); + + NO_DEFAULT; + } + } + break; + case TT_DEFINED: + { + _NEXT + if (p_interpret->tt != TT_IDENT) + _INTERPRET_ERROR("Expexted identifier for 'defined'", + p_interpret->p_token); + + char *c_name = token_get_val(p_interpret->p_token); + Token *p_token = token_new_integer(0); + + if (scope_exists(p_interpret->p_scope, c_name)) + token_set_ival(p_token, 1); + + stack_push(p_interpret->p_stack, p_token); + + _NEXT; + return (1); + } + break; + + case TT_UNDEF: + { + _NEXT + if (p_interpret->tt != TT_IDENT) + _INTERPRET_ERROR("Expexted identifier for 'defined'", + p_interpret->p_token); + + char *c_name = token_get_val(p_interpret->p_token); + Token *p_token = NULL; + Symbol *p_symbol = NULL; + + if ((p_symbol = scope_remove(p_interpret->p_scope, c_name))) { + symbol_delete(p_symbol); + p_token = token_new_integer(1); } else { - printf("No symbol '%s' defined @ any frame:\n", p_token->c_val); - frame_print(p_frame); - ERROR_INTERPRET("Error.", p_token); + p_token = token_new_integer(0); } + + stack_push(p_interpret->p_stack, p_token); + + _NEXT; + return (1); } -} + break; -void -_eval(Interpret *p_inter) { - ListIterator *p_iter = NULL; - ListElem *p_listelem_end = NULL; + /* + case TT_PARANT_AL: + { + Token *p_token = p_interpret->p_token; + _NEXT - 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; + Token *p_token_arr = token_new_array(ARRAY_SIZE); + stack_push(p_interpret->p_stack, p_token_arr); + _INTERPRET_ERROR("arrays not yet fully implemented", p_token_arr); } + break; + */ - 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; + case TT_PARANT_L: + { + Token *p_token = p_interpret->p_token; + _NEXT + + if (_expression_(p_interpret)) { + if (p_interpret->tt != TT_PARANT_R) + _INTERPRET_ERROR("Expected ')'", p_token); + + } else { + _INTERPRET_ERROR("Expected expression", p_token); } } - listiterator_delete(p_iter); + _NEXT + return (1); + + default: + break; + } + + return (0); } + +int +interpret_process(Interpret *p_interpret) { + p_interpret->p_iter = listiterator_new(p_interpret->p_list_token); + + _NEXT + _program(p_interpret); + + listiterator_delete(p_interpret->p_iter); + + return (1); +} + + +int +interpret_subprocess(Interpret *p_interpret, List *p_list_token) { + Interpret *p_interpret_sub = interpret_new(p_list_token, + NULL); + + p_interpret_sub->p_scope = p_interpret->p_scope; + + int i_ret = interpret_process(p_interpret_sub); + p_interpret->ct = p_interpret_sub->ct; + + interpret_delete(p_interpret_sub); + + return (i_ret); +} + +void +interpret_run(Fype *p_fype) { + Interpret *p_interpret = + interpret_new(p_fype->p_list_token, p_fype->p_hash_syms); + + interpret_process(p_interpret); + + interpret_delete(p_interpret); +} + diff --git a/src/core/interpret.h b/src/core/interpret.h index 6d3a4a5..6e50e8d 100644 --- a/src/core/interpret.h +++ b/src/core/interpret.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/core/interpret.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -35,24 +35,41 @@ #ifndef INTERPRET_H #define INTERPRET_H -#include "frame.h" -#include "token.h" -#include "lambda.h" #include "../data/list.h" +#include "../data/stack.h" +#include "../data/hash.h" + #include "../fype.h" -typedef struct _Interpret { +#include "garbage.h" +#include "scope.h" +#include "token.h" + +typedef enum { + CONTROL_NONE, + CONTROL_NEXT, + CONTROL_BREAK, +} ControlType; + +typedef struct { List *p_list_token; - Frame *p_frame; + Scope *p_scope; + _Bool b_scope_delete; + Stack *p_stack; + ControlType ct; + + ListIterator *p_iter; Token *p_token; - int i_pcount; - _Bool b_is_lambda_interpretation; - Lambda *p_lambda; + TokenType tt; + Token *p_token_prev; + TokenType tt_prev; + Token *p_token_temp; } 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); +Interpret* interpret_new(List *p_list_token, Hash *p_hash_syms); +void interpret_delete(Interpret *p_interpret); +void interpret_run(Fype *p_type); +int interpret_process(Interpret *p_interpret); +int interpret_subprocess(Interpret *p_interpret, List *p_list_token); #endif /* INTERPRET_H */ diff --git a/src/core/scanner.c b/src/core/scanner.c index a2b2b10..49026c2 100644 --- a/src/core/scanner.c +++ b/src/core/scanner.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/core/scanner.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -37,7 +37,8 @@ #include <ctype.h> #include <string.h> -const char _TOKEN_ENDS[] = "()"; +const char _TOKENENDS[] = "}])+-*/={([<>;:,.!"; +#define _ADD_SEMICOLON_INDEX 2 int _CODESTR_INDEX = 0; Scanner* @@ -68,8 +69,8 @@ scanner_new(List *p_list_token, Tupel *p_tupel_argv) { 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; + p_scanner->i_num_tokenends = strlen(_TOKENENDS); + p_scanner->tt_last = TT_NONE; return p_scanner; } @@ -81,6 +82,66 @@ scanner_delete(Scanner *p_scanner) { free(p_scanner); } +void +_add_semicolon_to_list(Scanner *p_scanner) { + int i_token_len = 1; + char *c_token = calloc(2, sizeof(char*)); + c_token[0] = ';'; + c_token[1] = '\0'; + scanner_add_token(p_scanner, &c_token, &i_token_len, TT_SEMICOLON); +} + +void +scanner_post_task(Scanner *p_scanner) { + List *p_list_token = scanner_get_list_token(p_scanner); + ListIterator *p_iter = listiterator_new(p_list_token); + + Token *pt_last[] = { NULL, NULL }; + TokenType tt_last[] = { TT_NONE, TT_NONE }; + + while (listiterator_has_next(p_iter)) { + ListElem *p_le = listiterator_next_elem(p_iter); + Token *p_token = p_le->p_val; + TokenType tt_cur = token_get_tt(p_token); + + if (pt_last[0]) { + if (tt_cur == TT_INTEGER && tt_last[1] == TT_DOT + && tt_last[0] == TT_INTEGER) { + + token_ref_down(pt_last[0]); + token_ref_down(pt_last[1]); + + char *c_2 = token_get_val(p_token); + char *c_0 = token_get_val(pt_last[0]); + int i_len = strlen(c_2) + strlen(c_0) + 1; + char *c_new = calloc(i_len+1, sizeof(char)); + + sprintf(c_new, "%s.%s", c_0, c_2); + free(c_2); + c_new[i_len] = 0; + + token_set_val(p_token, c_new); + token_set_tt(p_token, TT_DOUBLE); + token_set_dval(p_token, atof(c_new)); + + list_remove_elem(p_list_token, p_le->p_prev); + list_remove_elem(p_list_token, p_le->p_prev); + + pt_last[0] = pt_last[1] = NULL; + tt_last[0] = tt_last[1] = TT_NONE; + } + } + + tt_last[0] = tt_last[1]; + tt_last[1] = tt_cur; + + pt_last[0] = pt_last[1]; + pt_last[1] = p_token; + } + + listiterator_delete(p_iter); +} + _Bool _scanner_has_next_char(Scanner *p_scanner) { if (p_scanner->fp) @@ -98,9 +159,8 @@ _scanner_get_next_char(Scanner *p_scanner) { } void -scanner_run(PBSc *p_fype) { - Scanner *p_scanner = scanner_new(p_fype->p_list_token, - p_fype->p_tupel_argv); +scanner_run(Fype *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)); @@ -149,6 +209,7 @@ scanner_run(PBSc *p_fype) { } { int i_num_nl = 0; + //_Bool flag = false; do { c = _scanner_get_next_char(p_scanner); if ( c == '\n' ) { @@ -166,6 +227,7 @@ scanner_run(PBSc *p_fype) { c_token[i_token_len-1] = '"'; } else { + //flag = true; break; } @@ -182,6 +244,9 @@ scanner_run(PBSc *p_fype) { if (i_num_nl) p_scanner->i_current_line_nr += i_num_nl; + + //if (flag) + // _add_semicolon_to_list(p_scanner); } break; @@ -201,31 +266,26 @@ scanner_run(PBSc *p_fype) { 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); + if (tt_cur == TT_PARANT_CR && p_scanner->tt_last == TT_STRING) + _add_semicolon_to_list(p_scanner); - 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; + char d = c_token[i_token_len-1]; + if ((!isalpha(d) && !isdigit(d) /*&& d != '-'*/) && + (isalpha(c) || isdigit(c))) { + + scanner_add_token(p_scanner, &c_token, &i_token_len, tt_cur); + + } else { + for (int i = 0; i < p_scanner->i_num_tokenends; ++i) { + if (_TOKENENDS[i] == c) { + scanner_add_token(p_scanner, &c_token, &i_token_len, tt_cur); + if (i < _ADD_SEMICOLON_INDEX) + _add_semicolon_to_list(p_scanner); + break; + } } } } @@ -242,6 +302,14 @@ scanner_run(PBSc *p_fype) { scanner_add_token(p_scanner, &c_token, &i_token_len, tt_cur); } + /* Check if there is a ; missing */ + List *p_list_token = scanner_get_list_token(p_scanner); + Token *p_last_token = list_last(p_list_token); + if (token_get_tt(p_last_token) != TT_SEMICOLON) + _add_semicolon_to_list(p_scanner); + + scanner_post_task(p_scanner); + char *c_filename = scanner_get_filename(p_scanner); scanner_delete(p_scanner); @@ -268,12 +336,11 @@ 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); + 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); + token_ref_up(p_token); *cc_token = malloc(sizeof(char)); (*cc_token)[0] = 0; @@ -287,7 +354,12 @@ scanner_get_tt_cur(char *c_token) { if (isdigit(c_token[0])) return TT_INTEGER; - return (get_tt(c_token)); + if (c_token[0] == '-' && 1 < strlen(c_token) && isdigit(c_token[1])) + return TT_INTEGER; + + TokenType tt_cur = get_tt(c_token); + + return tt_cur == TT_NONE ? TT_IDENT : tt_cur; } void diff --git a/src/core/scanner.h b/src/core/scanner.h index b15707b..4626595 100644 --- a/src/core/scanner.h +++ b/src/core/scanner.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/core/scanner.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -58,9 +58,10 @@ typedef struct { TokenType tt_last; } Scanner; -void scanner_run(PBSc *p_fype); Scanner *scanner_new(List *p_list_token, Tupel *p_tupel_argv); +void scanner_post_task(Scanner *p_scanner); void scanner_delete(Scanner *p_scanner); +void scanner_run(Fype *p_fype); 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); diff --git a/src/core/scope.c b/src/core/scope.c index a9098a9..1bf8dd2 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -1,14 +1,13 @@ /*:* *: File: ./src/core/scope.c *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: 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 @@ -16,20 +15,20 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: + *: THIS SOFTWARE IS PROVIDED BY Paul 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) + *: DISCLAIMED. IN NO EVENT SHALL Paul 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 + *: 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. *:*/ @@ -149,21 +148,3 @@ scope_newset(Scope *p_scope, char *c_key, Symbol *p_symbol) { return (true); } - -void -_scope_print_cb(void *p_void, int i_level) { - Hash *p_hash_syms = p_void; - if (i_level > 0) - printf("%d level(s) up:\n", i_level); - hash_iterate_key(p_hash_syms, symbol_print_cb); -} - -void -scope_print(Scope *p_scope) { - printf("Scopes:\n"); - printf("Scope stack size: %d\n", stack_size(p_scope->p_stack_scopes)); - printf("Global symbols:\n"); - hash_iterate_key(p_scope->p_hash_global, symbol_print_cb); - printf("Local symbols:\n"); - stack_iterate_level(p_scope->p_stack_scopes, _scope_print_cb); -} diff --git a/src/core/scope.h b/src/core/scope.h index c1193c9..59ed3c8 100644 --- a/src/core/scope.h +++ b/src/core/scope.h @@ -1,14 +1,13 @@ /*:* *: File: ./src/core/scope.h *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: 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 @@ -16,20 +15,20 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: + *: THIS SOFTWARE IS PROVIDED BY Paul 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) + *: DISCLAIMED. IN NO EVENT SHALL Paul 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 + *: 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. *:*/ @@ -41,6 +40,7 @@ #include "../defines.h" #include "symbol.h" + typedef struct { Hash *p_hash_global; Stack *p_stack_scopes; @@ -55,6 +55,5 @@ _Bool scope_newset(Scope *p_scope, char *c_key, Symbol *p_symbol); _Bool scope_reset(Scope *p_scope, char *c_key, Symbol *p_symbol); void scope_down(Scope *p_scope); void scope_up(Scope *p_scope); -void scope_print(Scope *p_scope); #endif /* SCOPE_H */ diff --git a/src/core/symbol.c b/src/core/symbol.c index f4ad990..2343cdb 100644 --- a/src/core/symbol.c +++ b/src/core/symbol.c @@ -1,14 +1,13 @@ /*:* *: File: ./src/core/symbol.c *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: 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 @@ -16,27 +15,26 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: + *: THIS SOFTWARE IS PROVIDED BY Paul 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) + *: DISCLAIMED. IN NO EVENT SHALL Paul 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 + *: 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 "symbol.h" #include "../data/list.h" -#include "token.h" Symbol* symbol_new(SymbolType sym, void *p_val) { @@ -44,79 +42,25 @@ symbol_new(SymbolType sym, void *p_val) { p_symbol->sym = sym; p_symbol->p_val = p_val; - p_symbol->i_refs = 1; return p_symbol; } void symbol_delete(Symbol *p_symbol) { - if (--p_symbol->i_refs == 0) { - switch (symbol_get_sym(p_symbol)) { - case SYM_PROCEDURE: - { - List *p_list_token = symbol_get_val(p_symbol); - list_delete(p_list_token); - } - case SYM_ARRAY: - symbol_delete(symbol_get_val(p_symbol)); - break; - NO_DEFAULT; - } - free(p_symbol); + switch (symbol_get_sym(p_symbol)) { + case SYM_PROCEDURE: + { + List *p_list_token = symbol_get_val(p_symbol); + list_delete(p_list_token); + } + break; + NO_DEFAULT; } + free(p_symbol); } void symbol_cleanup_hash_syms_cb(void *p_void) { symbol_delete(p_void); } - -void -symbol_print(Symbol *p_symbol, char *c_key) { - printf("%s: %s", sym_get_name(p_symbol->sym), c_key); - - switch (p_symbol->sym) { - case SYM_BUILDIN: - case SYM_CONSTANT: - break; - case SYM_PROCEDURE: - case SYM_FUNCTION: - //list_iterate(symbol_get_val(p_symbol), token_print_cb); - break; - case SYM_ARRAY: - break; - case SYM_VARIABLE: - printf(" "); - token_print(symbol_get_val(p_symbol)); - break; - } - - printf("\n"); -} - -void -symbol_print_cb(void *p_void, char *c_key) { - symbol_print(p_void, c_key); -} - -char* -sym_get_name(SymbolType sym) { - switch (sym) { - case SYM_CONSTANT: - return ("SYM_CONSTANT"); - case SYM_ARRAY: - return ("SYM_ARRAY"); - case SYM_VARIABLE: - return ("SYM_VARIABLE"); - case SYM_BUILDIN: - return ("SYM_BUILDIN"); - case SYM_PROCEDURE: - return ("SYM_PROCEDURE"); - case SYM_FUNCTION: - return ("SYM_FUNCTION"); - } - - // Never reach this point - return ("NONE"); -} diff --git a/src/core/symbol.h b/src/core/symbol.h index 56f0e44..2bd248c 100644 --- a/src/core/symbol.h +++ b/src/core/symbol.h @@ -1,14 +1,13 @@ /*:* *: File: ./src/core/symbol.h *: A simple interpreter - *: - *: WWW : http://fype.buetow.org - *: AUTHOR : http://paul.buetow.org - *: E-Mail : fype at dev.buetow.org - *: - *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow + *: + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org + *: + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow *: All rights reserved. - *: + *: *: 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 @@ -16,20 +15,20 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: + *: THIS SOFTWARE IS PROVIDED BY Paul 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) + *: DISCLAIMED. IN NO EVENT SHALL Paul 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 + *: 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. *:*/ @@ -42,30 +41,24 @@ #define symbol_set_sym(s,st) s->sym = st #define symbol_get_val(s) s->p_val #define symbol_get_sym(s) s->sym -#define symbol_ref_up(s) ++s->i_refs #define IS_A_FUNCTION(s) (s == SYM_INLINEFUNCTION || s == SYM_FUNCTION) #define IS_NOT_A_FUNCTION(s) !IS_A_FUNCTION(s) typedef enum { - SYM_BUILDIN, SYM_CONSTANT, - SYM_FUNCTION, - SYM_PROCEDURE, - SYM_ARRAY, SYM_VARIABLE, + SYM_BUILDIN, + SYM_PROCEDURE, + SYM_FUNCTION, } SymbolType; typedef struct { SymbolType sym; void *p_val; - unsigned i_refs; } Symbol; Symbol* symbol_new(SymbolType sym, void *p_val); void symbol_delete(Symbol *p_symbol); void symbol_cleanup_hash_syms_cb(void *p_void); -void symbol_print(Symbol *p_symbol, char *c_key); -void symbol_print_cb(void *p_void, char *c_key); -char* sym_get_name(SymbolType sym); #endif diff --git a/src/core/token.c b/src/core/token.c index a0a6ad0..1a2aec9 100644 --- a/src/core/token.c +++ b/src/core/token.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/core/token.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -34,63 +34,287 @@ #include "token.h" +#include "garbage.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("if") TT_IF; + CHECK("ifnot") TT_IFNOT; + CHECK("else") TT_ELSE; + CHECK("break") TT_BREAK; + CHECK("while") TT_WHILE; + CHECK("until") TT_UNTIL; + CHECK("int") TT_INT; + CHECK("next") TT_NEXT; + CHECK("defined") TT_DEFINED; + CHECK("undef") TT_UNDEF; + CHECK("ret") TT_RET; + CHECK("const") TT_CONST; + CHECK("proc") TT_PROC; + CHECK("func") TT_FUNC; + CHECK("my") TT_MY; + CHECK("arr") TT_ARR; + CHECK("!") TT_NOT; + CHECK("!=") TT_NEQ; + CHECK("=~") TT_RE; CHECK("(") TT_PARANT_L; CHECK(")") TT_PARANT_R; - CHECK("'") TT_SQUOTE; + CHECK("[") TT_PARANT_AL; + CHECK("]") TT_PARANT_AR; + CHECK("*") TT_MULT; + CHECK("+") TT_ADD; + CHECK("++") TT_INCR; + CHECK(",") TT_COMMA; + CHECK("-") TT_SUB; + CHECK("--") TT_DECR; CHECK(".") TT_DOT; + CHECK("/") TT_DIV; + CHECK("\\") TT_VID; + CHECK(":") TT_DDOT; + CHECK("==") TT_EQ; + CHECK(";") TT_SEMICOLON; + CHECK("<<") TT_LSHIFT; + CHECK(">>") TT_RSHIFT; + CHECK("and") TT_AND; + CHECK("or") TT_OR; + CHECK("xor") TT_XOR; + CHECK("=") TT_ASSIGN; + CHECK("<") TT_LT; + CHECK(">") TT_GT; + CHECK(">=") TT_GE; + CHECK("<=") TT_LE; + CHECK("{") TT_PARANT_CL; + CHECK("}") TT_PARANT_CR; - return TT_IDENT; + return TT_NONE; } +#define CASE(t,r) case t: return r; + 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(START_TERMINALS, "START_TERMINALS") + CASE(START_TYPES, "START_TYPES") + CASE(START_NUMERICAL, "START_NUMERICAL") + CASE(START_ASSIGNABLES, "START_ASSIGNABLES") + CASE(TT_IDENT, "TT_IDENT") CASE(TT_DOUBLE,"TT_DOUBLE") CASE(TT_STRING,"TT_STRING") + CASE(TT_ARRAY,"TT_ARRAY") + CASE(TT_INTEGER,"TT_INTEGER") + CASE(TT_BOOL,"TT_BOOL") + CASE(END_ASSIGNABLES, "END_ASSIGNABLES") + CASE(END_NUMERICAL, "END_NUMERICAL") + CASE(END_TYPES, "END_TYPES") + + // Keywords + CASE(START_KEYWORDS, "START_KEYWORDS") + CASE(TT_ELSE,"TT_ELSE") + CASE(TT_BREAK,"TT_BREAK") + CASE(TT_IF,"TT_IF") + CASE(TT_IFNOT,"TT_IFNOT") + CASE(TT_RET,"TT_RET") + CASE(TT_CONST,"TT_CONST") + CASE(TT_PROC,"TT_PROC") + CASE(TT_FUNC,"TT_FUNC") + CASE(TT_MY,"TT_MY") + CASE(TT_ARR,"TT_ARR") + CASE(TT_WHILE,"TT_WHILE") + CASE(TT_UNTIL,"TT_UNTIL") + CASE(TT_NEXT,"TT_NEXT") + CASE(TT_DEFINED,"TT_DEFINED") + CASE(TT_UNDEF,"TT_UNDEF") + CASE(TT_INT,"TT_INT") + CASE(END_KEYWORDS, "END_KEYWORDS") + + // Braces + CASE(START_PARANTS, "START_PARANTS") + CASE(TT_PARANT_CL,"TT_PARANT_CL") + CASE(TT_PARANT_CR,"TT_PARANT_CR") + CASE(TT_PARANT_AL,"TT_PARANT_AL") + CASE(TT_PARANT_AR,"TT_PARANT_AR") + CASE(TT_PARANT_L,"TT_PARANT_L") + CASE(TT_PARANT_R,"TT_PARANT_R") + CASE(END_PARANTS, "END_PARANTS") + + // Operators + CASE(START_OPERATORS, "START_OPERATORS") + CASE(TT_ADD,"TT_ADD") + CASE(TT_ASSIGN,"TT_ASSIGN") + CASE(TT_COMMA,"TT_COMMA") + CASE(TT_DDOT,"TT_DDOT") + CASE(TT_DECR,"TT_DECR") + CASE(TT_DIV,"TT_DIV") + CASE(TT_VID,"TT_VID") CASE(TT_DOT,"TT_DOT") - CASE(TT_SQUOTE,"TT_SQUOTE") - CASE(TT_IDENT,"TT_IDENT") + CASE(TT_EQ,"TT_EQ") + CASE(TT_LE,"TT_LE") + CASE(TT_LT,"TT_LT") + CASE(TT_GE,"TT_GE") + CASE(TT_GT,"TT_GT") + CASE(TT_INCR,"TT_INCR") + CASE(TT_LSHIFT,"TT_LSHIFT") + CASE(TT_RSHIFT,"TT_RSHIFT") + CASE(TT_AND,"TT_AND") + CASE(TT_OR,"TT_OR") + CASE(TT_XOR,"TT_XOR") + CASE(TT_NOT,"TT_NOT") + CASE(TT_MULT,"TT_MULT") + CASE(TT_NEQ,"TT_NEQ") + CASE(TT_RE,"TT_RE") + CASE(TT_NOTEQ,"TT_NOTEQ") + CASE(TT_SEMICOLON,"TT_SEMICOLON") + CASE(TT_SUB,"TT_SUB") + CASE(END_OPERATORS, "END_OPERATORS") + CASE(END_TERMINALS, "END_TERMINALS") + + // Diverse + CASE(TT_NONE,"TT_NONE") + CASE(TT_END_OF_CODE,"TT_END_OF_CODE") } - return "TT_IDENT"; + // Never reach this point + return "XXXXXXX"; } Token* -token_new(char *c_val, TokenType tt_cur, int i_line_nr, - int i_pos_nr, char *c_filename) { +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->i_val = 0; + p_token->d_val = 0; 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; + p_token->p_array = NULL; + + switch (tt_cur) { + case TT_INTEGER: + p_token->i_val = atoi(c_val); + break; + case TT_DOUBLE: + { + p_token->d_val = atof(c_val); + break; + } + case TT_ARRAY: + { + p_token->p_array = array_new(); + break; + } + NO_DEFAULT; + } + + return p_token; +} + +Token* +token_new_integer(int i_val) { + Token *p_token = token_new_dummy(); + token_set_tt(p_token, TT_INTEGER); + token_set_ival(p_token, i_val); return (p_token); } Token* +token_new_double(double d_val) { + Token *p_token = token_new_dummy(); + token_set_tt(p_token, TT_DOUBLE); + token_set_dval(p_token, d_val); + + return (p_token); +} + +Token* +token_new_string(char *c_val) { + Token *p_token = token_new_dummy(); + token_set_tt(p_token, TT_STRING); + + p_token->c_val = calloc(strlen(c_val)+1, sizeof(char)); + strcpy(p_token->c_val, c_val); + + return (p_token); +} + +Token* +token_new_array(int i_size) { + Token *p_token = token_new_dummy(); + token_set_tt(p_token, TT_ARRAY); + array_resize(p_token->p_array, i_size); + + return (p_token); +} + + +Token* +token_new_(char *c_val, TokenType tt_cur, char *c_filename) { + return token_new(c_val, tt_cur, -1, -1, c_filename); +} + +Token* token_new_dummy() { Token *p_token = malloc(sizeof(Token)); p_token->c_val = NULL; - p_token->tt_cur = TT_IDENT; + p_token->tt_cur = TT_NONE; 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++; + p_token->i_ref_count = 0; - return (p_token); + /* Register the token in the garbage collector */ + garbage_add_token(p_token); + + return p_token; +} + +Token* +token_new_copy(Token *p_token) { + Token *p_token_copy = malloc(sizeof(Token)); + p_token->u_token_id = TOKEN_ID_COUNTER++; + + if (p_token_copy == NULL) + ERROR("Memory alloc error"); + + token_copy_vals(p_token_copy, p_token); + p_token_copy->i_ref_count = 0; + + /* Register the token in the garbage collector */ + garbage_add_token(p_token_copy); + + return (p_token_copy); +} + +void token_copy_vals(Token *p_token_to, Token *p_token_from) { + int i_len; + + // TODO: Check against mem leak + // if (p_token_to->c_val) + // free(p_token_to->c_val); + + if (p_token_from->c_val) { + i_len = strlen(p_token_from->c_val); + p_token_to->c_val = calloc(i_len+1, sizeof(char)); + strcpy(p_token_to->c_val, p_token_from->c_val); + } else { + p_token_to->c_val = NULL; + } + + p_token_to->tt_cur = p_token_from->tt_cur; + p_token_to->i_val = p_token_from->i_val; + p_token_to->d_val = p_token_from->d_val; + p_token_to->i_line_nr = p_token_from->i_line_nr; + p_token_to->i_pos_nr = p_token_from->i_pos_nr; + p_token_to->c_filename = p_token_from->c_filename; } void @@ -99,31 +323,77 @@ token_delete_cb(void *p_void) { } void -token_delete(Token *p_token) { +token_ref_down_cb(void *p_void) { + Token *p_token = p_void; + token_ref_down(p_token); +} + +void* +token_copy_cb(void *p_void) { + return (token_new_copy(p_void)); } -_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; +void +token_delete(Token *p_token) { + if (token_ref_down(p_token) <= 0) { + if (p_token->i_ref_count == 0) { +#ifdef DEBUG_TOKEN_REFCOUNT + printf("Token refcount debug: Token ref count is 0 == %d\n", + p_token->i_ref_count); +#endif /* DEBUG_TOKEN_REFCOUNT */ + if (p_token->c_val) + free(p_token->c_val); - return false; + if (p_token->p_array) + array_delete(p_token->p_array); + + free(p_token); + } +#ifdef DEBUG_TOKEN_REFCOUNT + else { + printf("Token refcount debug: Token ref count is 0 > %d\n", + p_token->i_ref_count); + } +#endif /* DEBUG_TOKEN_REFCOUNT */ + } +#ifdef DEBUG_TOKEN_REFCOUNT + else { + printf("Token refcount debug: Token ref count is 0 < %d\n", + p_token->i_ref_count); + } +#endif /* DEBUG_TOKEN_REFCOUNT */ } void token_print(Token *p_token) { - printf("(id=%05u, line=%05d, pos=%04d, type=%s, val=%s)", + printf("(id=%05u, line=%05d, pos=%04d, type=%s, val=%s, ival=%d, dval=%f," + " refs=%d)", 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); + p_token->c_val, + p_token->i_val, + p_token->d_val, + p_token->i_ref_count); } void -token_print_ln(Token *p_token) { - token_print(p_token); - printf("\n"); +token_print_val(Token *p_token) { + TokenType tt = token_get_tt(p_token); + switch (tt) { + case TT_INTEGER: + printf("(%s, %d)", tt_get_name(tt), token_get_ival(p_token)); + break; + case TT_DOUBLE: + printf("(%s, %f)", tt_get_name(tt), token_get_dval(p_token)); + break; + case TT_STRING: + printf("(%s, %s)", tt_get_name(tt), token_get_val(p_token)); + break; + default: + ERROR("Ouups(%s)!", tt_get_name(tt)); + } } void diff --git a/src/core/token.h b/src/core/token.h index 8f1ab53..caf4854 100644 --- a/src/core/token.h +++ b/src/core/token.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/core/token.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -38,38 +38,153 @@ #include "../defines.h" #include "../data/array.h" +#define IS_TERMINAL(t) (START_TERMINALS < t && t < END_TERMINALS) +#define IS_NOT_TERMINAL(t) !IS_TERMINAL(t) +#define IS_TYPE(t) (START_TYPES < t && t < END_TYPES) +#define IS_NOT_TYPE(t) !IS_TYPE(t) +#define IS_KEYWORD(t) (START_KEYWORDS < t && t < END_KEYWORDS) +#define IS_NOT_KEYWORD(t) !IS_KEYWORD(t) +#define IS_OPERATOR(t) (START_OPERATORS < t && t < END_OPERATORS) +#define IS_NOT_OPERATOR(t) !IS_OPERATOR(t) +#define IS_NON_TERMINAL(t) (START_NON_TERMINALS < t && t < END_NON_TERMINALS) +#define IS_NOT_NON_TERMINAL(t) !IS_NON_TERMINAL(t) +#define IS_IDENT(t) (t == TT_IDENT) +#define IS_NOT_IDENT(t) !(IS_IDENT(t)) +#define IS_ASSIGNABLE(t) (START_ASSIGNABLES < t && t < END_ASSIGNABLES) +#define IS_NUMERICAL(t) (START_NUMERICAL < t && t < END_NUMERICAL) +#define IS_NOT_NUMERICAL(t) !(IS_NUMERICAL(t)) + +#define token_get_filename(t) \ + (t->c_filename != NULL ? t->c_filename : "Code string") +#define token_get_line_nr(t) t->i_line_nr +#define token_get_pos_nr(t) t->i_pos_nr +#define token_get_tt(t) (t ? t->tt_cur : TT_NONE) +#define token_get_val(t) t->c_val +#define token_get_ival(t) t->i_val +#define token_get_dval(t) t->d_val +#define token_set_tt(t,tt) t->tt_cur = tt +#define token_set_val(t,c) t->c_val = c +#define token_set_ival(t,i) t->i_val = i +#define token_set_dval(t,d) t->d_val = d +#define token_set_pos(t, l, p) t->i_line_nr = l; t->i_pos_nr = p +#define token_get_posnr(t) t->i_pos_nr +#define token_get_linenr(t) t->i_line_nr +#define token_ref_up(t) ++t->i_ref_count +#define token_ref_down(t) --t->i_ref_count + typedef enum { - TT_IDENT, - TT_PARANT_L, - TT_PARANT_R, + // Diverse + TT_NONE, + TT_END_OF_CODE, + TT_BOOL, // Temporaly disabled, maybe NUMERICAL in future again + + // Diverse types + START_TERMINALS, + START_TYPES, + START_ASSIGNABLES, + START_NUMERICAL, TT_INTEGER, TT_DOUBLE, + END_NUMERICAL, TT_STRING, - TT_SQUOTE, - TT_DOT + TT_ARRAY, + END_ASSIGNABLES, + TT_IDENT, + END_TYPES, + + // Keywords + START_KEYWORDS, + TT_ELSE, + TT_BREAK, + TT_IF, + TT_IFNOT, + TT_RET, + TT_CONST, + TT_PROC, + TT_FUNC, + TT_MY, + TT_ARR, + TT_WHILE, + TT_UNTIL, + TT_NEXT, + TT_INT, + TT_DEFINED, + TT_UNDEF, + END_KEYWORDS, + + START_PARANTS, + TT_PARANT_CL, + TT_PARANT_CR, + TT_PARANT_AL, + TT_PARANT_AR, + TT_PARANT_L, + TT_PARANT_R, + END_PARANTS, + + // Operators + START_OPERATORS, + TT_ADD, + TT_AND, + TT_ASSIGN, + TT_COMMA, + TT_DDOT, + TT_DECR, + TT_DIV, + TT_DOT, + TT_EQ, + TT_GE, + TT_GT, + TT_INCR, + TT_LE, + TT_LSHIFT, + TT_LT, + TT_MULT, + TT_NEQ, + TT_NOT, + TT_NOTEQ, + TT_OR, + TT_RE, + TT_RSHIFT, + TT_SEMICOLON, + TT_SUB, + TT_VID, + TT_XOR, + END_OPERATORS, + + END_TERMINALS, + } TokenType; typedef struct { TokenType tt_cur; char *c_val; + int i_val; + double d_val; int i_line_nr; int i_pos_nr; char *c_filename; unsigned int u_token_id; + int i_ref_count; + Array *p_array; } Token; -Token* token_new(char *c_val, TokenType tt_cur, int i_line_nr, - int i_pos_nr, char *c_filename); +Token* token_new(char *c_val, TokenType tt_cur, int i_line_nr, int i_pos_nr, char *c_filename); +Token* token_new_integer(int i_val); +Token* token_new_couble(double d_val); +Token* token_new_string(char *c_val); +Token* token_new_array(int i_size); +Token* token_new_copy(Token *p_token); +Token* token_new_(char *c_val, TokenType tt_cur, char *c_filename); Token* token_new_dummy(); +void token_copy_vals(Token *p_token_to, Token *p_token_from); void token_delete(Token *p_token); void token_delete_cb(void *p_token); +void token_ref_down_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/data/array.c b/src/data/array.c index f50e998..2ae4ece 100644 --- a/src/data/array.c +++ b/src/data/array.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/array.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -40,32 +40,10 @@ array_new() { p_array->i_size = 0; p_array->pp_ae = NULL; - array_set_used(p_array, 0); - return (p_array); + 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) { @@ -83,23 +61,6 @@ array_delete(Array *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; @@ -108,18 +69,9 @@ array_set(Array *p_array, int i_index, void *p_val) { 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); @@ -135,15 +87,12 @@ array_insert(Array *p_array, int i_index, void *p_val) { 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); + return NULL; ArrayElement *p_ae = p_array->pp_ae[i_index]; void *p_ret = p_ae->p_val; @@ -155,7 +104,8 @@ array_remove(Array *p_array, int i_index) { p_array->pp_ae[i-1] = p_ae; array_resize(p_array, p_array->i_size - 1); - return (p_ret); + + return p_ret; } void @@ -192,24 +142,22 @@ array_resize(Array *p_array, int i_size) { 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 p_array->pp_ae[i_index]->p_val; - return (NULL); + return NULL; } _Bool array_defined(Array *p_array, int i_index) { if (i_index >= p_array->i_size) - return (false); + return false; - return (p_array->pp_ae[i_index]->p_val != NULL); + return p_array->pp_ae[i_index]->p_val != NULL; } void @@ -235,9 +183,8 @@ array_splice(Array *p_array, int i_index, Array *p_array2) { 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); + int i_size = array_get_size(p_array); + array_set(p_array, i_size, p_void); } void @@ -252,18 +199,11 @@ array_push(Array *p_array, void *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) + for (int i = 0; i < array_get_size(p_array); ++i) (*func) (array_get(p_array, i)); } @@ -272,7 +212,7 @@ 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) + for (int i = 0; i < array_get_size(p_array); ++i) (*func) (array_get(p_array, i), p_void); } @@ -282,7 +222,7 @@ arrayelement_new(void *p_val) { p_ae->p_val = p_val; - return (p_ae); + return p_ae; } void @@ -296,13 +236,13 @@ arrayelement_delete(ArrayElement *p_ae) { ArrayIterator* arrayiterator_new(Array *p_array) { if (!p_array) - return (NULL); + return NULL; ArrayIterator *p_arrayiterator = malloc(sizeof(ArrayIterator)); p_arrayiterator->p_array = p_array; p_arrayiterator->i_cur_pos = 0; - return (p_arrayiterator); + return p_arrayiterator; } void @@ -313,15 +253,14 @@ arrayiterator_delete(ArrayIterator *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)); + return p_arrayiterator->i_cur_pos < + array_get_size(p_arrayiterator->p_array); } void* arrayiterator_next(ArrayIterator *p_arrayiterator) { if (!arrayiterator_has_next(p_arrayiterator)) - return (NULL); + return NULL; - return (array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++)); + return array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++); } diff --git a/src/data/array.h b/src/data/array.h index 6800061..b343521 100644 --- a/src/data/array.h +++ b/src/data/array.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/array.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -41,8 +41,6 @@ #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) @@ -54,7 +52,6 @@ typedef struct { typedef struct { ArrayElement **pp_ae; - int i_used; int i_size; } Array; @@ -64,10 +61,7 @@ typedef struct { } 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); @@ -77,12 +71,10 @@ _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); diff --git a/src/data/dat.c b/src/data/dat.c index b448cdc..6d4f10d 100644 --- a/src/data/dat.c +++ b/src/data/dat.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/dat.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -35,7 +35,6 @@ #include "dat.h" #include <stdlib.h> -#include "../defines.h" Dat* dat_new() { @@ -45,12 +44,12 @@ dat_new() { p_dat->p_last = 0; p_dat->i_size = 0; - return (p_dat); + return p_dat; } DatElem* datelem_new() { - return (datelem_new_t(TYPE_UNKNOWN)); + return datelem_new_t(TYPE_UNKNOWN); } DatElem* @@ -61,15 +60,15 @@ datelem_new_t(TYPE type) { p_elem->p_val = 0; p_elem->type = type; - return (p_elem); + return p_elem; } _Bool dat_empty(Dat *p_dat) { if (p_dat == NULL) - return (false); + return 0; - return (p_dat->i_size == 0); + return p_dat->i_size == 0; } void @@ -93,13 +92,13 @@ dat_push_t(Dat *p_dat, void *p_val, TYPE type) { void* dat_pop(Dat *p_dat) { TYPE type; - return (dat_pop_t(p_dat, &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); + return 0; DatElem *p_elem = p_dat->p_first; p_dat->p_first = p_elem->p_next; @@ -109,7 +108,7 @@ dat_pop_t(Dat *p_dat, TYPE *p_type) { void *p_ret = p_elem->p_val; *p_type = p_elem->type; free(p_elem); - return (p_ret); + return p_ret; } void @@ -125,7 +124,7 @@ dat_delete(Dat *p_dat) { unsigned dat_size(Dat *p_dat) { - return (p_dat->i_size); + return p_dat->i_size; } void @@ -164,52 +163,52 @@ dat_iterate_tl(Dat *p_dat, void (*func)(void *, TYPE, _Bool)) { void* dat_first(Dat *p_dat) { if (dat_empty(p_dat)) - return (NULL); + return NULL; - return (p_dat->p_first->p_val); + return p_dat->p_first->p_val; } void* dat_second(Dat *p_dat) { - if (2 > dat_size(p_dat)) - return (NULL); + if ( 2 > dat_size(p_dat)) + return NULL; - return (p_dat->p_first->p_next->p_val); + return p_dat->p_first->p_next->p_val; } void* dat_last(Dat *p_dat) { if (dat_empty(p_dat)) - return (NULL); + return NULL; - return (p_dat->p_last->p_val); + return p_dat->p_last->p_val; } void* dat_first_t(Dat *p_dat, TYPE *p_type) { if (dat_empty(p_dat)) - return (NULL); + return NULL; *p_type = p_dat->p_first->type; - return (p_dat->p_first->p_val); + 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); + 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); + 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); + return NULL; *p_type = p_dat->p_last->type; - return (p_dat->p_last->p_val); + return p_dat->p_last->p_val; } DatIter* @@ -222,7 +221,7 @@ datiter_new(Dat *p_dat) { p_iter->i_left = dat_size(p_dat); p_iter->p_dat = p_dat; - return (p_iter); + return p_iter; } void @@ -239,13 +238,13 @@ datiter_skip(DatIter *p_iter, unsigned i_num) { void* datiter_next(DatIter *p_iter) { TYPE type; - return (datiter_next_t(p_iter, &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); + return NULL; void *p_ret = p_iter->p_next->p_val; *p_type = p_iter->p_next->type; @@ -253,16 +252,16 @@ datiter_next_t(DatIter *p_iter, TYPE *p_type) { p_iter->p_next = p_iter->p_next->p_next; --p_iter->i_left; - return (p_ret); + return p_ret; } unsigned datiter_left(DatIter *p_iter) { - return (p_iter->i_left); + return p_iter->i_left; } Dat* datiter_dat(DatIter *p_iter) { - return (p_iter->p_dat); + return p_iter->p_dat; } diff --git a/src/data/dat.h b/src/data/dat.h index dcc7928..83e24a6 100644 --- a/src/data/dat.h +++ b/src/data/dat.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/dat.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) diff --git a/src/data/hash.c b/src/data/hash.c index e196840..5555eb1 100644 --- a/src/data/hash.c +++ b/src/data/hash.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/hash.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -50,7 +50,7 @@ hash_new(unsigned i_size) { for (int i = 0; i < i_size; ++i) p_hash->p_elems[i].flag = 'f'; - return (p_hash); + return p_hash; } void @@ -68,10 +68,10 @@ 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); + int i_addr = hash_getaddr(p_hash, c_key, free_ADDR); if (i_addr == RET_ERROR ) - return (RET_NO_SPACE); + return RET_NO_SPACE; strncpy(p_hash->p_elems[i_addr].c_key, c_key, HASH_MKEYLEN); @@ -80,12 +80,12 @@ hash_insert_ht(Hash *p_hash, char *c_key, void *p_val, TYPE type) { p_hash->p_elems[i_addr].p_val = p_val; p_hash->i_cur_size++; - return (RET_OK); + 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)); + return hash_insert_ht(p_hash, c_key, p_val, TYPE_VOIDP); } void* @@ -96,20 +96,20 @@ hash_remove(Hash *p_hash, char *c_key) { int i_addr = hash_getaddr(p_hash, c_key, OCC_ADDR); if (i_addr == -1 ) - return (NULL); + return 0; 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); + 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)); + return hash_get_ht_addr(p_hash, c_key, p_type, &i_addr); } void* @@ -117,16 +117,16 @@ 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); + return 0; *p_type = p_hash->p_elems[i_addr].type; - return (p_hash->p_elems[i_addr].p_val); + 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)); + return hash_get_ht(p_hash, c_key, &type); } int @@ -144,68 +144,67 @@ hash_getaddr(Hash *p_hash, char *c_key, HASH_OP OP) { i_addr = (i_addr *p_hash->i_size + (int) c_key[i]) % p_hash->i_size; switch (OP) { - case FREE_ADDR: + case free_ADDR: if (!hash_addrisfree(p_hash,i_addr)) - return (i_addr); + return i_addr; break; case OCC_ADDR: if (!hash_addrisocc(p_hash,i_addr, c_key)) - return (i_addr); + return i_addr; break; default: - return (RET_ERROR); + return RET_ERROR; } - return (hash_nextaddr(p_hash, p_hash->i_size, c_key, i_addr, OP)); + 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_OK; - return (RET_ERROR); + 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_OK; - return (RET_ERROR); + 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); + return RET_ERROR; i_addr = (i_addr + 1) % p_hash->i_size; switch (OP) { - case FREE_ADDR: + case free_ADDR: if (!hash_addrisfree(p_hash,i_addr)) - return (i_addr); + return i_addr; break; case OCC_ADDR: if (!hash_addrisocc(p_hash,i_addr, c_key)) - return (i_addr); + return i_addr; break; } - return (hash_nextaddr(p_hash, i_max_tries, c_key, i_addr, OP)); + 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 -> ", + 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) { @@ -280,7 +279,7 @@ hash_size(Hash *p_hash, int i_size) { p_old_elems[i].p_val, p_old_elems[i].type); free(p_old_elems); - return (RET_OK); + return RET_OK; } void @@ -289,18 +288,3 @@ hash_iterate(Hash *p_hash, void (*func)(void *)) { 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 index 8bf0a49..196c4a8 100644 --- a/src/data/hash.h +++ b/src/data/hash.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/hash.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -39,7 +39,7 @@ #include "types.h" typedef enum HASH_OP_ { - FREE_ADDR, + free_ADDR, OCC_ADDR } HASH_OP; @@ -60,10 +60,10 @@ 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_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); @@ -71,12 +71,8 @@ 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); +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 diff --git a/src/data/list.c b/src/data/list.c index e641133..83860c3 100644 --- a/src/data/list.c +++ b/src/data/list.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/list.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -42,7 +42,7 @@ list_new() { p_list->p_last = NULL; p_list->i_size = 0; - return (p_list); + return p_list; } void @@ -78,13 +78,12 @@ listelem_new() { p_elem->p_next = NULL; p_elem->p_prev = NULL; p_elem->p_val = NULL; - - return (p_elem); + return p_elem; } _Bool list_empty(List *p_list) { - return (p_list->i_size == 0); + return p_list->i_size == 0; } void @@ -173,7 +172,7 @@ list_add_back(List *p_list, void *p_val) { void* list_remove_front(List *p_list) { if (list_empty(p_list)) - return (NULL); + return NULL; ListElem *p_elem = p_list->p_first; p_list->p_first = p_elem->p_next; @@ -186,13 +185,13 @@ list_remove_front(List *p_list) { --p_list->i_size; - return (p_val); + return p_val; } void* list_remove_back(List *p_list) { if (list_empty(p_list)) - return (NULL); + return NULL; ListElem *p_elem = p_list->p_last; p_list->p_last = p_elem->p_prev; @@ -203,7 +202,7 @@ list_remove_back(List *p_list) { --p_list->i_size; - return (p_val); + return p_val; } void @@ -238,7 +237,7 @@ list_delete_and_free_vals(List *p_list) { unsigned list_size(List *p_list) { - return (p_list->i_size); + return p_list->i_size; } void @@ -272,9 +271,7 @@ list_iterate2_ptr(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) { +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) { @@ -284,8 +281,7 @@ list_iterate3(List *p_list, } void -list_iterate3_ptr(List *p_list, - void (*func)(void *, void *, 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; @@ -330,7 +326,7 @@ list_remove_elem(List *p_list, ListElem *p_elem_remove) { ListIterator* listiterator_new(List *p_list) { if (!p_list) - return (NULL); + return NULL; ListIterator *p_iter = malloc(sizeof(ListIterator)); @@ -338,46 +334,20 @@ listiterator_new(List *p_list) { 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); + return p_iter; } ListIterator* listiterator_new_reverse(List *p_list) { if (!p_list) - return (NULL); + 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); + return p_iter; } void @@ -436,27 +406,6 @@ listiterator_current(ListIterator *p_iter) { 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; @@ -467,28 +416,6 @@ listiterator_end(ListIterator *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) { diff --git a/src/data/list.h b/src/data/list.h index fb6a9b8..323f496 100644 --- a/src/data/list.h +++ b/src/data/list.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/list.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -84,31 +84,18 @@ 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 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_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); +void *listiterator_next(ListIterator *p_iter); +void *listiterator_prev(ListIterator *p_iter); +void *listiterator_current(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); diff --git a/src/data/map.c b/src/data/map.c index 3c95dc2..b5c016e 100644 --- a/src/data/map.c +++ b/src/data/map.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/map.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -36,7 +36,7 @@ Map* map_new(int i_max_size) { - return (map_new_named(i_max_size, "noname")); + return map_new_named(i_max_size, "noname"); } Map* @@ -55,29 +55,29 @@ map_new_named(int i_max_size, char *c_name) { p_map->i_size = 0; p_map->i_max_size = i_max_size; - return (p_map); + return p_map; } _Bool map_empty(Map *p_map) { - return (p_map->i_size == 0); + return p_map->i_size == 0; } _Bool map_full(Map *p_map) { - return (p_map->i_size == p_map->i_max_size); + 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); + return i; ERROR("No free space left in the map (%s)", p_map->c_name); // This point should not be reached! - return (0); + return 0; } _Bool @@ -90,14 +90,14 @@ map_insert(Map *p_map, char *c_key, void *p_val) { p_map->pp_vals[i_free_addr] = p_val; ++p_map->i_size; - return (true); + 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)); + return map_insert(p_map, c_key, p_val); } _Bool @@ -105,11 +105,11 @@ 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 false; - return (map_insert(p_map, c_key, p_val)); + return map_insert(p_map, c_key, p_val); - return (true); + return true; } void @@ -130,33 +130,33 @@ map_remove(Map *p_map, char *c_key) { void* map_get(Map *p_map, char *c_key) { if (map_empty(p_map)) - return (NULL); + return NULL; int i_index = map_get_addr(p_map, c_key); - return (i_index >= 0 ? p_map->pp_vals[i_index] : NULL); + 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)); + return map_get(p_map, c_key); } _Bool map_exists(Map *p_map, char *c_key) { if (map_empty(p_map)) - return (false); + return false; int i_index = map_get_addr(p_map, c_key); - return (i_index >= 0 ? true : false); + 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); + return false; char c_key[HASH_MKEYLEN]; sprintf(c_key, "%s%s%s:", c_key1, SEP, c_key2); @@ -168,25 +168,25 @@ map_exists2(Map *p_map, char *c_key1, char *c_key2) { char* map_get_key(Map *p_map, void *p_val) { if (map_empty(p_map)) - return (NULL); + 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 p_map->pc_keys[i]; - return (NULL); + return NULL; } int map_get_addr(Map *p_map, char *c_key) { if (map_empty(p_map)) - return (-1); + 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 i; - return (-1); + return -1; } void @@ -261,27 +261,21 @@ 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) { +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) { +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) { +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 index c01dbe1..fe7397f 100644 --- a/src/data/map.h +++ b/src/data/map.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/map.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -72,15 +72,9 @@ 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); +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 diff --git a/src/data/queue.c b/src/data/queue.c index 63987a0..d4697bb 100644 --- a/src/data/queue.c +++ b/src/data/queue.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/queue.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) diff --git a/src/data/queue.h b/src/data/queue.h index 227ce29..f345cce 100644 --- a/src/data/queue.h +++ b/src/data/queue.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/queue.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) diff --git a/src/data/stack.c b/src/data/stack.c index e6a60a4..9afb9b4 100644 --- a/src/data/stack.c +++ b/src/data/stack.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/stack.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -93,14 +93,6 @@ stack_pop(Stack *p_stack) { 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)); @@ -181,35 +173,6 @@ 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) { - 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)); diff --git a/src/data/stack.h b/src/data/stack.h index 395dd32..4774cef 100644 --- a/src/data/stack.h +++ b/src/data/stack.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/stack.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -35,6 +35,8 @@ #ifndef STACK_H #define STACK_H +#define stack_top(s) s->p_first->p_val; + #include <stdlib.h> typedef struct StackElem_ { @@ -57,13 +59,8 @@ 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); diff --git a/src/data/tree.c b/src/data/tree.c index c55dcf1..0160eb9 100644 --- a/src/data/tree.c +++ b/src/data/tree.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/tree.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -75,23 +75,58 @@ _tree_print_cb(void *p_void, void *p_indent) { TreeNode *ptn = p_void; _indent((int) p_indent); +#ifdef FYPE + TokenType tt = (TokenType) treenode_get_val(ptn); + + if (IS_NOT_TERMINAL(tt)) + goto no_token_val; + + Token *p_token = treenode_get_val2(ptn); + + if (!p_token) + goto no_token_val; + + char *c_token_val = token_get_val(p_token); + TokenType tt_token = token_get_tt(p_token); + + if (!c_token_val) + c_token_val = ""; + + printf(" %s=%s", tt_get_name(tt_token), c_token_val); + return; + +no_token_val: + printf(" %s", tt_get_name(tt)); + +#else printf(" %d", (int) treenode_get_val(ptn)); +#endif } 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)); + TokenType tt = (TokenType)treenode_get_val(p_treenode); + +#ifdef FYPE + _Bool b_print_nl = false; + if (IS_NOT_TERMINAL(tt)) { + _indent(i_indent); + printf("%s:", tt_get_name(tt)); + b_print_nl = true; + } +#else + _indent(i_indent); + printf("%s:", tt_get_name(tt)); +#endif array_iterate2(p_treenode->p_array_childs, _tree_print_cb, (void*) 0); - printf("\nTree "); +#ifdef FYPE + if (b_print_nl) +#endif + printf("\nTree "); - array_iterate2(p_treenode->p_array_childs, - _tree_print_cb2, - (void*) (i_indent + TREE_PRINT_INDENT)); + array_iterate2(p_treenode->p_array_childs, _tree_print_cb2, (void*) (i_indent + TREE_PRINT_INDENT)); } void diff --git a/src/data/tree.h b/src/data/tree.h index ce9ecc4..1f9b18c 100644 --- a/src/data/tree.h +++ b/src/data/tree.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/tree.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -39,7 +39,7 @@ #include "array.h" #include "stack.h" -#ifdef PBSC +#ifdef FYPE #include "../core/token.h" #endif diff --git a/src/data/tupel.c b/src/data/tupel.c index 68c0247..bcb67f6 100644 --- a/src/data/tupel.c +++ b/src/data/tupel.c @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/tupel.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) diff --git a/src/data/tupel.h b/src/data/tupel.h index e5d0fe7..d70bf9f 100644 --- a/src/data/tupel.h +++ b/src/data/tupel.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/tupel.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) diff --git a/src/data/types.h b/src/data/types.h index 2899dfe..b20d67a 100644 --- a/src/data/types.h +++ b/src/data/types.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/data/types.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) diff --git a/src/defines.h b/src/defines.h index 9484784..4f1ec53 100644 --- a/src/defines.h +++ b/src/defines.h @@ -1,12 +1,12 @@ /*:* *: File: ./src/defines.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -42,18 +42,19 @@ #include "build.h" -#define COPYRIGHT "(c) Paul C. Buetow (2005 - 2010) <fype@dev.buetow.org>" +#define COPYRIGHT "Copyright by Paul C. Buetow (2005 - 2008) <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 NAME "Fype" +#define ASSEMBLER "yasm" #define LINKER "cc" #define SCANNER_BUFSIZE 512 #define URL "<http://fype.buetow.org>" -#define VERSION "Alpha Build" +#define VERSION "v0.1 Build" #ifndef false #define false (_Bool)0 @@ -63,7 +64,6 @@ #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) @@ -73,7 +73,6 @@ 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 @@ -94,15 +93,4 @@ #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 @@ -1,12 +1,12 @@ /*:* *: File: ./src/fype.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -35,46 +35,54 @@ #include "fype.h" #include "argv.h" -#include "core/scanner.h" -#include "core/token.h" +#include "core/garbage.h" #include "core/interpret.h" +#include "core/scanner.h" +#include "core/symbol.h" -PBSc* +Fype* fype_new() { - PBSc *p_fype = malloc(sizeof(PBSc)); + Fype *p_fype = malloc(sizeof(Fype)); 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; + garbage_init(); + return (p_fype); } void -fype_delete(PBSc *p_fype) { +fype_delete(Fype *p_fype) { argv_tupel_delete(p_fype->p_tupel_argv); + hash_iterate(p_fype->p_hash_syms, symbol_cleanup_hash_syms_cb); hash_delete(p_fype->p_hash_syms); - list_iterate(p_fype->p_list_token, token_delete_cb); + //list_iterate(p_fype->p_list_token, token_print_cb); + list_iterate(p_fype->p_list_token, token_ref_down_cb); + //list_iterate(p_fype->p_list_token, token_print_cb); list_delete(p_fype->p_list_token); if (p_fype->c_basename) free(p_fype->c_basename); + + garbage_destroy(); } int fype_run(int i_argc, char **pc_argv) { - PBSc *p_fype = fype_new(); + Fype *p_fype = fype_new(); // argv: Maintains command line options argv_run(p_fype, i_argc, pc_argv); - // scanner: Fills the list of tokens + // scanner: Creates a list of token scanner_run(p_fype); - // interpret: Interprets the list of tokens + // interpret: Interpret the list of token interpret_run(p_fype); fype_delete(p_fype); @@ -1,12 +1,12 @@ /*:* *: File: ./src/fype.h - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) @@ -45,13 +45,13 @@ typedef struct { Tupel *p_tupel_argv; // Contains command line options - List *p_list_token; // Initial list of tokens + List *p_list_token; // Initial list of token Hash *p_hash_syms; // Symbol table char *c_basename; -} PBSc; +} Fype; -PBSc *fype_new(); -void fype_delete(PBSc *p_fype); +Fype *fype_new(); +void fype_delete(Fype *p_fype); int fype_run(int i_argc, char **pc_argv); #endif /* FYPE_H */ @@ -1,12 +1,12 @@ /*:* *: File: ./src/main.c - *: A simple Fype interpreter + *: A simple interpreter *: - *: WWW: http://fype.buetow.org - *: AUTHOR: http://paul.buetow.org - *: E-Mail: fype at dev.buetow.org + *: WWW : http://fype.buetow.org + *: E-Mail : fype@dev.buetow.org *: - *: The Fype Language; (c) 2005 - 2010 - Dipl.-Inform. (FH) Paul C. Buetow + *: Copyright (c) 2005 2006 2007 2008, Dipl.-Inf. (FH) Paul C. Buetow + *: All rights reserved. *: *: Redistribution and use in source and binary forms, with or without modi- *: fication, are permitted provided that the following conditions are met: @@ -15,14 +15,14 @@ *: * 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 + *: * Neither the name of P. B. Labs 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 + *: THIS SOFTWARE IS PROVIDED BY Paul 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, + *: DISCLAIMED. IN NO EVENT SHALL Paul 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) |
