summaryrefslogtreecommitdiff
path: root/gemfeed/2010-05-09-the-fype-programming-language.html
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-04-07 00:49:19 +0300
committerPaul Buetow <paul@buetow.org>2023-04-07 00:49:19 +0300
commit30fc4e8f74315a92aaec36dfb9a8d4efa0a21791 (patch)
tree97ef2b26fd54a366d72f5289ba11ea311f8a0173 /gemfeed/2010-05-09-the-fype-programming-language.html
parent5c9e3886de0f9041e4a6fb6fea9917e29a8fbd76 (diff)
exact style
Diffstat (limited to 'gemfeed/2010-05-09-the-fype-programming-language.html')
-rw-r--r--gemfeed/2010-05-09-the-fype-programming-language.html262
1 files changed, 186 insertions, 76 deletions
diff --git a/gemfeed/2010-05-09-the-fype-programming-language.html b/gemfeed/2010-05-09-the-fype-programming-language.html
index 7aa1517d..eba53a7e 100644
--- a/gemfeed/2010-05-09-the-fype-programming-language.html
+++ b/gemfeed/2010-05-09-the-fype-programming-language.html
@@ -8,8 +8,10 @@
<link rel="stylesheet" href="style-override.css" />
</head>
<body>
-<h1>The Fype Programming Language</h1>
-<p class="quote"><i>Published at 2010-05-09T12:48:29+01:00; Updated at 2021-05-05</i></p>
+<h1 style='display: inline'>The Fype Programming Language</h1><br />
+<br />
+<span class=quote>Published at 2010-05-09T12:48:29+01:00; Updated at 2021-05-05</span><br />
+<br />
<pre>
____ _ __
/ / _|_ _ _ __ ___ _ _ ___ __ _| |__ / _|_ _
@@ -18,12 +20,19 @@
(_)_/ |_| \__, | .__/ \___| \__, |\___|\__,_|_| |_(_)_| \__, |
|___/|_| |___/ |___/
</pre>
-<p>Fype is an interpreted programming language created by me for learning and fun. The interpreter is written in C. It has been tested on FreeBSD and NetBSD and may also work on other Unix like operating systems such as Linux based ones. Besides learning and fun, there is no other use case of why Fype exists as many other programming languages are much faster and more powerful.</p>
-<p>The Fype syntax is straightforward and uses a maximum look ahead of 1 and an effortless top-down parsing mechanism. Fype is parsing and interpreting its code simultaneously. This means that syntax errors are only detected during program runtime. </p>
-<p>Fype is a recursive acronym and means "Fype is For Your Program Execution" or "Fype is Free Yak Programmed for ELF". You could also say, "It's not a hype - it's Fype!".</p>
-<h2>Object-oriented C style</h2>
-<p>The Fype interpreter is written in an object-oriented style of C. Each "main component" has its own .h and .c file. There is a struct type for each (most components at least) component, which can be initialized using a "COMPONENT_new" function and destroyed using a "COMPONENT_delete" function. Method calls follow the same schema, e.g. "COMPONENT_METHODNAME". There is no such as class inheritance and polymorphism involved. </p>
-<p>To give you an idea of how it works here as an example is a snippet from the main Fype "class header":</p>
+<br />
+<span>Fype is an interpreted programming language created by me for learning and fun. The interpreter is written in C. It has been tested on FreeBSD and NetBSD and may also work on other Unix like operating systems such as Linux based ones. Besides learning and fun, there is no other use case of why Fype exists as many other programming languages are much faster and more powerful.</span><br />
+<br />
+<span>The Fype syntax is straightforward and uses a maximum look ahead of 1 and an effortless top-down parsing mechanism. Fype is parsing and interpreting its code simultaneously. This means that syntax errors are only detected during program runtime. </span><br />
+<br />
+<span>Fype is a recursive acronym and means "Fype is For Your Program Execution" or "Fype is Free Yak Programmed for ELF". You could also say, "It's not a hype - it's Fype!".</span><br />
+<br />
+<h2 style='display: inline'>Object-oriented C style</h2><br />
+<br />
+<span>The Fype interpreter is written in an object-oriented style of C. Each "main component" has its own .h and .c file. There is a struct type for each (most components at least) component, which can be initialized using a "COMPONENT_new" function and destroyed using a "COMPONENT_delete" function. Method calls follow the same schema, e.g. "COMPONENT_METHODNAME". There is no such as class inheritance and polymorphism involved. </span><br />
+<br />
+<span>To give you an idea of how it works here as an example is a snippet from the main Fype "class header":</span><br />
+<br />
<pre>
typedef struct {
Tupel *p_tupel_argv; // Contains command line options
@@ -32,7 +41,9 @@ typedef struct {
char *c_basename;
} Fype;
</pre>
-<p>And here is a snippet from the primary Fype "class implementation":</p>
+<br />
+<span>And here is a snippet from the primary Fype "class implementation":</span><br />
+<br />
<pre>
Fype*
fype_new() {
@@ -82,8 +93,10 @@ fype_run(int i_argc, char **pc_argv) {
return (0);
}
</pre>
-<h2>Data types</h2>
-<p>Fype uses auto type conversion. However, if you want to know what's going on, you may take a look at the following basic data types:</p>
+<br />
+<h2 style='display: inline'>Data types</h2><br />
+<br />
+<span>Fype uses auto type conversion. However, if you want to know what's going on, you may take a look at the following basic data types:</span><br />
<ul>
<li>integer - Specifies a number</li>
<li>double - Specifies a double-precision number</li>
@@ -92,13 +105,19 @@ fype_run(int i_argc, char **pc_argv) {
<li>any- May be any type above</li>
<li>void - No type</li>
<li>identifier - It's a variable name or a procedure name, or a function name</li>
-</ul>
-<p>There is no boolean type, but we can use the integer values 0 for false and 1 for true. There is support for explicit type casting too.</p>
-<h2>Syntax</h2>
-<h3>Comments</h3>
-<p>Text from a # character until the end of the current line is considered being a comment. Multi-line comments may start with an #* and with a *# anywhere. Exceptions are if those signs are inside of strings.</p>
-<h3>Variables</h3>
-<p>Variables are defined with the "my" keyword (inspired by Perl :-). If you don't assign a value during declaration, it uses the default integer value 0. Variables may be changed during program runtime. Variables may be deleted using the "undef" keyword! Example:</p>
+</ul><br />
+<span>There is no boolean type, but we can use the integer values 0 for false and 1 for true. There is support for explicit type casting too.</span><br />
+<br />
+<h2 style='display: inline'>Syntax</h2><br />
+<br />
+<h3 style='display: inline'>Comments</h3><br />
+<br />
+<span>Text from a # character until the end of the current line is considered being a comment. Multi-line comments may start with an #* and with a *# anywhere. Exceptions are if those signs are inside of strings.</span><br />
+<br />
+<h3 style='display: inline'>Variables</h3><br />
+<br />
+<span>Variables are defined with the "my" keyword (inspired by Perl :-). If you don't assign a value during declaration, it uses the default integer value 0. Variables may be changed during program runtime. Variables may be deleted using the "undef" keyword! Example:</span><br />
+<br />
<pre>
my foo = 1 + 2;
say foo;
@@ -110,7 +129,9 @@ say bar;
my baz;
say baz; # Will print out 0
</pre>
-<p>You may use the "defined" keyword to check if an identifier has been defined or not:</p>
+<br />
+<span>You may use the "defined" keyword to check if an identifier has been defined or not:</span><br />
+<br />
<pre>
ifnot defined foo {
say "No foo yet defined";
@@ -123,8 +144,11 @@ if defined foo {
say foo;
}
</pre>
-<h3>Synonyms</h3>
-<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 it:</p>
+<br />
+<h3 style='display: inline'>Synonyms</h3><br />
+<br />
+<span>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 it:</span><br />
+<br />
<pre>
my foo = "foo";
my bar = \foo;
@@ -133,7 +157,9 @@ foo = "bar";
# 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 standard variables but can also be used for function and procedure names (more about functions and procedures later).</p>
+<br />
+<span>Synonyms can be used for all kind of identifiers. It's not limited to standard variables but can also be used for function and procedure names (more about functions and procedures later).</span><br />
+<br />
<pre>
# Create a new procedure baz
proc baz { say "I am baz"; }
@@ -146,7 +172,9 @@ undef baz;
# bay still has a reference of the original procedure baz
bay; # this prints aut "I am baz"
</pre>
-<p>The "syms" keyword gives you the total number of synonyms pointing to a specific value:</p>
+<br />
+<span>The "syms" keyword gives you the total number of synonyms pointing to a specific value:</span><br />
+<br />
<pre>
my foo = 1;
say syms foo; # Prints 1
@@ -158,17 +186,25 @@ say syms baz; # Prints 2
undef baz;
say syms foo; # Prints 1
</pre>
-<h2>Statements and expressions</h2>
-<p>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:</p>
+<br />
+<h2 style='display: inline'>Statements and expressions</h2><br />
+<br />
+<span>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:</span><br />
+<br />
<pre>
my bar = 3, foo = 1 + 2;
say foo;
exit foo - bar;
</pre>
-<h3>Parenthesis</h3>
-<p>All parenthesis for function arguments is optional. They help to make the code better readable. They also help to force the precedence of expressions.</p>
-<h3>Basic expressions</h3>
-<p>Any "any" value holding a string will be automatically converted to an integer value.</p>
+<br />
+<h3 style='display: inline'>Parenthesis</h3><br />
+<br />
+<span>All parenthesis for function arguments is optional. They help to make the code better readable. They also help to force the precedence of expressions.</span><br />
+<br />
+<h3 style='display: inline'>Basic expressions</h3><br />
+<br />
+<span>Any "any" value holding a string will be automatically converted to an integer value.</span><br />
+<br />
<pre>
(any) &lt;any&gt; + &lt;any&gt;
(any) &lt;any&gt; - &lt;any&gt;
@@ -182,7 +218,9 @@ exit foo - bar;
(integer) &lt;any&gt; gt &lt;any&gt;
(integer) not &lt;any&gt;
</pre>
-<h3>Bitwise expressions</h3>
+<br />
+<h3 style='display: inline'>Bitwise expressions</h3><br />
+<br />
<pre>
(integer) &lt;any&gt; :&lt; &lt;any&gt;
(integer) &lt;any&gt; :&gt; &lt;any&gt;
@@ -190,43 +228,64 @@ exit foo - bar;
(integer) &lt;any&gt; or &lt;any&gt;
(integer) &lt;any&gt; xor &lt;any&gt;
</pre>
-<h3>Numeric expressions</h3>
+<br />
+<h3 style='display: inline'>Numeric expressions</h3><br />
+<br />
<pre>
(number) neg &lt;number&gt;
</pre>
-<p>... returns the negative value of "number":</p>
+<br />
+<span>... returns the negative value of "number":</span><br />
+<br />
<pre>
(integer) no &lt;integer&gt;
</pre>
-<p>... returns 1 if the argument is 0; otherwise, it will return 0! If no argument is given, then 0 is returned!</p>
+<br />
+<span>... returns 1 if the argument is 0; otherwise, it will return 0! If no argument is given, then 0 is returned!</span><br />
+<br />
<pre>
(integer) yes &lt;integer&gt;
</pre>
-<p>... always returns 1. The parameter is optional. Example:</p>
+<br />
+<span>... always returns 1. The parameter is optional. Example:</span><br />
+<br />
<pre>
# Prints out 1, because foo is not defined
if yes { say no defined foo; }
</pre>
-<h2>Control statements</h2>
-<p>Control statements available in Fype:</p>
+<br />
+<h2 style='display: inline'>Control statements</h2><br />
+<br />
+<span>Control statements available in Fype:</span><br />
+<br />
<pre>
if &lt;expression&gt; { &lt;statements&gt; }
</pre>
-<p>... runs the statements if the expression evaluates to a true value.</p>
+<br />
+<span>... runs the statements if the expression evaluates to a true value.</span><br />
+<br />
<pre>
ifnot &lt;expression&gt; { &lt;statements&gt; }
</pre>
-<p>... runs the statements if the expression evaluates to a false value.</p>
+<br />
+<span>... runs the statements if the expression evaluates to a false value.</span><br />
+<br />
<pre>
while &lt;expression&gt; { &lt;statements&gt; }
</pre>
-<p>... runs the statements as long as the expression evaluates to a true value.</p>
+<br />
+<span>... runs the statements as long as the expression evaluates to a true value.</span><br />
+<br />
<pre>
until &lt;expression&gt; { &lt;statements&gt; }
</pre>
-<p>... runs the statements as long as the expression evaluates to a false value.</p>
-<h2>Scopes</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 scopes. The "scope" function prints out all available symbols at the current scope. Here is a small example:</p>
+<br />
+<span>... runs the statements as long as the expression evaluates to a false value.</span><br />
+<br />
+<h2 style='display: inline'>Scopes</h2><br />
+<br />
+<span>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 scopes. The "scope" function prints out all available symbols at the current scope. Here is a small example:</span><br />
+<br />
<pre>
my foo = 1;
@@ -253,7 +312,9 @@ my foo = 1;
# Prints out 0
say defined bar;
</pre>
-<p>Another example including an actual output:</p>
+<br />
+<span>Another example including an actual output:</span><br />
+<br />
<pre>
./fype -e ’my global; func foo { my var4; func bar { my var2, var3; func baz { my var1; scope; } baz; } bar; } foo;’
Scopes:
@@ -271,29 +332,43 @@ SYM_FUNCTION: baz
SYM_VARIABLE: var4 (id=00035, line=-0001, pos=-001, type=TT_INTEGER, dval=0.000000, refs=-1)
SYM_FUNCTION: bar
</pre>
-<h2>Definedness </h2>
+<br />
+<h2 style='display: inline'>Definedness </h2><br />
+<br />
<pre>
(integer) defined &lt;identifier&gt;
</pre>
-<p>... returns 1 if "identifier" has been defined. Returns 0 otherwise.</p>
+<br />
+<span>... returns 1 if "identifier" has been defined. Returns 0 otherwise.</span><br />
+<br />
<pre>
(integer) undef &lt;identifier&gt;
</pre>
-<p>... tries to undefine/delete the "identifier". Returns 1 if it succeeded, otherwise 0 is returned.</p>
-<h2>System </h2>
-<p>These are some system and interpreter specific built-in functions supported:</p>
+<br />
+<span>... tries to undefine/delete the "identifier". Returns 1 if it succeeded, otherwise 0 is returned.</span><br />
+<br />
+<h2 style='display: inline'>System </h2><br />
+<br />
+<span>These are some system and interpreter specific built-in functions supported:</span><br />
+<br />
<pre>
(void) end
</pre>
-<p>... exits the program with the exit status of 0.</p>
+<br />
+<span>... exits the program with the exit status of 0.</span><br />
+<br />
<pre>
(void) exit &lt;integer&gt;
</pre>
-<p>... exits the program with the specified exit status.</p>
+<br />
+<span>... exits the program with the specified exit status.</span><br />
+<br />
<pre>
(integer) fork
</pre>
-<p>... forks a subprocess. It returns 0 for the child process and the PID of the child process otherwise! Example:</p>
+<br />
+<span>... forks a subprocess. It returns 0 for the child process and the PID of the child process otherwise! Example:</span><br />
+<br />
<pre>
my pid = fork;
@@ -305,27 +380,41 @@ if pid {
say "I am the child process";
}
</pre>
-<p>To execute the garbage collector do:</p>
+<br />
+<span>To execute the garbage collector do:</span><br />
+<br />
<pre>
(integer) GC
</pre>
-<p>It returns the number of items freed! You may wonder why most of the time, it will produce a value of 0! Fype tries to free not needed memory ASAP. This may change in future versions to gain faster execution speed!</p>
-<h3>I/O </h3>
+<br />
+<span>It returns the number of items freed! You may wonder why most of the time, it will produce a value of 0! Fype tries to free not needed memory ASAP. This may change in future versions to gain faster execution speed!</span><br />
+<br />
+<h3 style='display: inline'>I/O </h3><br />
+<br />
<pre>
(any) put &lt;any&gt;
</pre>
-<p>... prints out the argument</p>
+<br />
+<span>... prints out the argument</span><br />
+<br />
<pre>
(any) say &lt;any&gt;
</pre>
-<p>is the same as put, but also includes an ending newline.</p>
+<br />
+<span>is the same as put, but also includes an ending newline.</span><br />
+<br />
<pre>
(void) ln
</pre>
-<p>... just prints a new line.</p>
-<h2>Procedures and functions</h2>
-<h3>Procedures</h3>
-<p>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 variables inside of a procedure in the current namespace.</p>
+<br />
+<span>... just prints a new line.</span><br />
+<br />
+<h2 style='display: inline'>Procedures and functions</h2><br />
+<br />
+<h3 style='display: inline'>Procedures</h3><br />
+<br />
+<span>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 variables inside of a procedure in the current namespace.</span><br />
+<br />
<pre>
proc foo {
say 1 + a * 3 + b;
@@ -337,8 +426,11 @@ my a = 2, b = 4;
foo; # Run the procedure. Print out "11\n"
say c; # Print out "6\n";
</pre>
-<h3>Nested procedures</h3>
-<p>It's possible to define procedures inside of procedures. Since procedures don't have their 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 to check if a procedure has been defined or not.</p>
+<br />
+<h3 style='display: inline'>Nested procedures</h3><br />
+<br />
+<span>It's possible to define procedures inside of procedures. Since procedures don't have their 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 to check if a procedure has been defined or not.</span><br />
+<br />
<pre>
proc foo {
say "I am foo";
@@ -357,8 +449,11 @@ 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!
</pre>
-<h3>Functions</h3>
-<p>A function can be defined with the "func" keyword and deleted with the "undef" keyword. Function do not yet return values and do not yet supports parameter passing. It's using local (lexical scoped) variables. If a certain variable does not exist, when It's using already defined variables (e.g. one scope above). </p>
+<br />
+<h3 style='display: inline'>Functions</h3><br />
+<br />
+<span>A function can be defined with the "func" keyword and deleted with the "undef" keyword. Function do not yet return values and do not yet supports parameter passing. It's using local (lexical scoped) variables. If a certain variable does not exist, when It's using already defined variables (e.g. one scope above). </span><br />
+<br />
<pre>
func foo {
say 1 + a * 3 + b;
@@ -370,8 +465,11 @@ my a = 2, b = 4;
foo; # Run the procedure. Print out "11\n"
say c; # Will produce an error because c is out of scope!
</pre>
-<h3>Nested functions</h3>
-<p>Nested functions work the same way the nested procedures work, except that nested functions will not be available anymore after the function has been left!</p>
+<br />
+<h3 style='display: inline'>Nested functions</h3><br />
+<br />
+<span>Nested functions work the same way the nested procedures work, except that nested functions will not be available anymore after the function has been left!</span><br />
+<br />
<pre>
func foo {
func bar {
@@ -384,14 +482,19 @@ func foo {
foo;
bar; # Will produce an error because bar is out of scope!
</pre>
-<h2>Arrays</h2>
-<p>Some progress on arrays has been made too. The following example creates a multidimensional array "foo". Its first element is the return value of the func which is "bar". The fourth value is a string" 3" converted to a double number. The last element is an anonymous array which itself contains another anonymous array as its final element:</p>
+<br />
+<h2 style='display: inline'>Arrays</h2><br />
+<br />
+<span>Some progress on arrays has been made too. The following example creates a multidimensional array "foo". Its first element is the return value of the func which is "bar". The fourth value is a string" 3" converted to a double number. The last element is an anonymous array which itself contains another anonymous array as its final element:</span><br />
+<br />
<pre>
func bar { say ”bar” }
my foo = [bar, 1, 4/2, double ”3”, [”A”, [”BA”, ”BB”]]];
say foo;
</pre>
-<p>It produces the following output:</p>
+<br />
+<span>It produces the following output:</span><br />
+<br />
<pre>
% ./fype arrays.fy
bar
@@ -402,13 +505,20 @@ A
BA
BB
</pre>
-<h2>Fancy stuff</h2>
-<p>Fancy stuff like OOP or Unicode or threading is not planed. But fancy stuff like function pointers and closures may be considered.:) </p>
-<h2>May the source be with you</h2>
-<p>You can find all of this on the GitHub page. There is also an "examples" folders containing some Fype scripts!</p>
-<a class="textlink" href="https://codeberg.org/snonux/fype">https://codeberg.org/snonux/fype</a><br />
-<p>E-Mail your comments to hi@paul.cyou :-)</p>
-<a class="textlink" href="../">Back to the main site</a><br />
+<br />
+<h2 style='display: inline'>Fancy stuff</h2><br />
+<br />
+<span>Fancy stuff like OOP or Unicode or threading is not planed. But fancy stuff like function pointers and closures may be considered.:) </span><br />
+<br />
+<h2 style='display: inline'>May the source be with you</h2><br />
+<br />
+<span>You can find all of this on the GitHub page. There is also an "examples" folders containing some Fype scripts!</span><br />
+<br />
+<a class=textlink href='https://codeberg.org/snonux/fype'>https://codeberg.org/snonux/fype</a><br />
+<br />
+<span>E-Mail your comments to hi@paul.cyou :-)</span><br />
+<br />
+<a class=textlink href='../'>Back to the main site</a><br />
<p class="footer">
Generated with <a href="https://codeberg.org/snonux/gemtexter">Gemtexter</a> |
served by <a href="https://www.OpenBSD.org">OpenBSD</a>/<a href="https://man.openbsd.org/httpd.8">httpd(8)</a> |