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 contribu |
