Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Introducing TeaScript script language

Hello community! 🙂

I am developing a new script language TeaScript I would like to share and introduce here.

TeaScript is a Multi-Paradigm script language. Direct available already is easy to use Functional programming, Lambda functions, higher order functions, Uniform Definition Syntax, “Types are Values”, Type-Safe programming, generic programming, in-string evaluation, automatic number to- and from-string conversion, simple text file processing, time measurement, random number generator, arithmetic operations, … and many more!

It is written in C++ and can use the full power of a C++ environment. Actually, the Host Application is available for Windows only.
You can use it for FREE, download link below. Later there will be also a C++ Library (usable for free in private, noncommercial projects) as a header-only library (this implies with including source code).

At the end of the post I show you source code written in TeaScript for demonstrate its power which is already available. The same source code is included in the download package, so that it can be easily tested and tried.

Some basics:
TeaScript is close to C++ syntax but differ in some aspects.
A few important changes are:
  • No semicolon ; for end a statement
  • curly brackets {} for if-statements/loops are mandatory, also if there is only one inner statement.
  • assignment is :=, compare is ==, a single = is a syntax error (avoiding the common bug of forget one = )
  • No &&. ||, !. Use and, or, not
  • a repeat loop (additional forall loop coming with next release)
  • implicit return the last statement.
  • blocks, if-statements, etc. can be assigned.
  • ...
A good overview and the most impressive highlights can be found on my webpage:
https://tea-age.solutions/teascript/overview-and-highlights/

as well as the language documentation:
https://tea-age.solutions/teascript/teascript-language-documentation/


Now I post a TeaScript file which will demonstrate its already available power.
Try to read and understand the source code. I hope, you will easily see what it does and get an idea what other things could be done already.

The same script file and other examples are included in the download package.

You can try and use TeaScript for free (currently Windows 10/11 64 bit only, more to follow).
It is a portable version, so there is no installation required! - Just download, unpack and use it!

Download and try it here: https://tea-age.solutions/downloads/

Please, let me know any concerns or problems. A basic instruction is available in the link above as well as in the readme.txt of the package.
I can provide more detailed instructions if you wish.

(A slightly better syntax highlighting can be found on my webpage)
C++:
/*
 * SPDX-FileCopyrightText: Copyright (c) 2022 Florian Thake (tea-age.solutions). All rights reserved. (Of course permission granted by me to post it in codeforum.org)
 */
 
// This is a file io test for the TeaScript Core Library written in TeaScript for versions >= 0.8.
// The test will create files and write data into the temp directory which is reported
// by the tempdir() CoreLibrary function of TeaScript. The files will not be removed and remain there.
 
// NOTE: assuming core library test 1 and 2 passed 100%!
 
const some_str := "TEST"
 
const hello_world_tea := "// This is a hello world TeaScript file\n" %
                         "// created by the fileio_test01.tea script\n" %
                         "// for testing purposes. \n\n" %
                         "const str := \"Hello World!\"\n" %
                         "println( str )\n\n" %
                         "str\n\n"
                          
_out( "Start testing file io of TeaScript Core Library ...\n" )
 
const dir := tempdir()
if( _strlen( dir ) == 0 ) {
    fail_with_message( "tempdir() returned an empty string!" )
}
 
println( "using tempdir: \"%(dir)\"" )
 
func make_filename()
{
    def time_str := timetostr(clock_utc(), true)
    // windows does not allow : in file name...
    repeat {
        if( not strreplacefirst( time_str, ":", "-" ) ) { stop }
    }
    strreplacefirst( time_str, ".", "_" )
    "teascript_fileio_test_utc%(time_str)_r%(random(1000,9999)).tea"
}
 
const filename01 := make_filename()
 
println( "using filename01: \"%(filename01)\"" )
 
//                                                 no overwrite, write bom
if( not writetextfile( dir % filename01, hello_world_tea, false, true ) ) {
    fail_with_message( "writetextfile() failed for %(dir % filename01)!" )
}
 
const fsize := file_size( dir % filename01 )
 
println( "file \"%(dir % filename01)\" written with size %(fsize) (bytes)." )
 
def read_str := readtextfile( dir % filename01 )
 
if( read_str is Bool and not read_str ) {
    fail_with_message( "readtextfile() failed for %(dir % filename01)!" )
}
 
if( read_str != hello_world_tea ) {
    println( "readtextfile() did not read back same content:" )
    print( read_str )
    _out( "\n\n" )
    fail_with_message( "file io test failed!" )
}
 
strreplacefirst( read_str, "World", some_str )
 
println("Now excuting read back and slightly modified file content ... \n\n" )
 
const x  := eval( read_str )
 
if( x == "Hello TEST!" ) {
    println( "\n=== TEST FINISHED ===" )
} else {
    println( "\n !!! TEST FAILED !!! " )
}

I still have tons of features and ideas which I want to realize in some next pre-release.

For the very next pre-releases will come:
  • built in arrays and tuples
  • forall loop
  • Linux support (Ubuntu at least)
  • C++ Library
  • better and more file io capabilities
  • Parallel syntax (multi-threading build into the core language syntax)
  • Pipe Syntax like in Unix/Linux shells.
Also, I have ideas for direct integrate TOML, JSON and maybe some SQL (sqlite). There will be a network API as well as a console text API for easily manipulate the console screen buffer and many more.


What is your impression of it? Please, don't hesitate to write a comment.
 
Recently I created a benchmark for testing and comparing TeaScript and its competitor ChaiScript by computing the Fibonacci number of 25 recursively. The (pretty amazing) result is shown below. Shorter is better/faster, longer is slower. More in the blog post.

202301_Benchmark_Fibonacci_Graph.png


Here is the the source code (in C++) of the benchmark:

C++:
/*
 * SPDX-FileCopyrightText: Copyright (C) 2023 Florian Thake (tea-age.solutions). All rights reserved.
 * (permission granted by me to publish in codeforum.org)
 */
 
 
#include <cstdlib> // EXIT_SUCCESS
#include <cstdio>
#include <iostream>
#include <chrono>
 
#include <teascript/Parser.hpp>
#include <teascript/CoreLibrary.hpp>
 
#include <chaiscript/chaiscript.hpp>
 
// recursive fibonacci function in TeaScript
constexpr char tea_code[] = R"_SCRIPT_(
func fib( x ) {
   if( x == 1 or x == 0 ) {
      x
   } else {
      fib( x - 1 ) + fib( x - 2 )
   }
}
 
fib(25)
)_SCRIPT_";
 
// recursive fibonacci function in ChaiScript
constexpr char chai_code[] = R"_SCRIPT_(
def fib( x )
{
    if( x == 0 || x == 1 ) {
        return x;
    } else {
        return fib( x - 1 ) + fib( x - 2 );
    }
}
 
fib(25);
)_SCRIPT_";
 
auto Now()
{
    return std::chrono::steady_clock::now();
}
 
double CalcTimeInSecs( auto s, auto e )
{   
    std::chrono::duration<double> const  timesecs = e - s;
    return timesecs.count();
}
 
double exec_tea()
{
    teascript::Context c;
    teascript::CoreLibrary().Bootstrap( c );
    teascript::Parser  p;
    auto ast = p.Parse( tea_code );
    try {
        auto start  = Now();
        auto teares = ast->Eval( c );
        auto end    = Now();
 
        std::cout << "value: " << teares.GetAsLongLong() << std::endl;
 
        return CalcTimeInSecs( start, end );
 
    } catch( teascript::exception::runtime_error const &ex ) {
        teascript::util::pretty_print( ex );
    } catch( std::exception const &ex ) {
        puts( ex.what() );
    }
 
    return -1.0;
}
 
double exec_chai()
{
    chaiscript::ChaiScript chai;
    auto ast = chai.parse( chai_code );
    try {
        auto start = Now();
        auto chres = chai.eval( *ast );
        auto end   = Now();
 
        std::cout << "value: " << chaiscript::boxed_cast<int>(chres) << std::endl;
 
        return CalcTimeInSecs( start, end );
        
    } catch( chaiscript::Boxed_Value const &bv ) {
        puts( chaiscript::boxed_cast<chaiscript::exception::eval_error const &>(bv).what() );
    } catch( std::exception const &ex ) {
        puts( ex.what() );
    }
 
    return -1.0;
}
 
// recursive fibonacci function in C++
long long fib( long long x )
{
    if( x == 0 || x == 1 ) {
        return x;
    } else {
        return fib( x - 1 ) + fib( x - 2 );
    }
}
 
double exec_cpp()
{
    try {
        auto start = Now();
        auto res   = fib( 25 );
        auto end   = Now();
 
        std::cout << "value: " << res << std::endl;
 
        return CalcTimeInSecs( start, end );
 
    } catch( std::exception const &ex ) {
        puts( ex.what() );
    }
 
    return -1.0;
}
 
int main()
{
    std::cout << std::fixed;
    std::cout << std::setprecision( 8 );
 
    std::cout << "Benchmarking TeaScript and ChaiScript in calculating Fibonacci of 25...\n";
    std::cout << "... and C++ as a reference ... \n";
 
    std::cout << "\nStart Test C++" << std::endl;
    for( int i = 3; i != 0; --i ) {
        auto secs = exec_cpp();
        std::cout << "Calculation took: " << secs << " seconds." << std::endl;
    }
 
    std::cout << "\nStart Test TeaScript" << std::endl;
    for( int i = 3; i != 0; --i ) {
        auto secs = exec_tea();
        std::cout << "Calculation took: " << secs << " seconds." << std::endl;
    }
 
    std::cout << "\nStart Test ChaiScript" << std::endl;
    for( int i = 3; i != 0; --i ) {
        auto secs = exec_chai();
        std::cout << "Calculation took: " << secs << " seconds." << std::endl;
    }
 
    puts( "\n\nTest end." );
 
    return EXIT_SUCCESS;
}
 
Hi.

What is the reason for not using semicolong at the end of statement? I mean, is it not allowed or not required?
It is superfluous and can be easily forgotten. A statement/expression ends logically at the new line, except if it is still open (e.g., no closing parenthesis yet, or RHS of an operator is missing).

At the moment a semeicolon is not used in the TeaScript syntax at all. So, placing a semicolon anywhere will be a syntax error.

BTW: TeaScript 0.10.0 is out which is a really huge release. It comes with Tuples, Named Tuples which can be uses as C-like structs, list and dictionaries as well! Additionally it comes with Passthrough type, fine grained CoreLib config and more:
TeaScript 0.10.0 Release News
 
Ok.

Im kind of dirrerent here lol. I think semicolon at the end is a good thing. Not that i would not survive without. Several years with BASIC dialects wnet just fine without semicolons. I just wonder why its so big issue is there or is there not. Afaik, js neither require semicolons.
 
Ok.

Im kind of dirrerent here lol. I think semicolon at the end is a good thing. Not that i would not survive without. Several years with BASIC dialects wnet just fine without semicolons. I just wonder why its so big issue is there or is there not. Afaik, js neither require semicolons.

Well, I think for a script languages and especially for people who are not so familiar with programming a mandatory semicolon is more annoying than useful.
And I don't like optional syntax in this case. It will only confuse people if sometimes there is a semicolon and then not.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom