Giter Club home page Giter Club logo

natscript's Introduction

Hello World ๐Ÿ‘Œ

I am Richard Baltrusch, a German software engineer that likes to build all kinds of stuff, with a faible for Python.

You can contact me using the following links:

Languages

  • Professionally Python, Java and Javascript (previously MATLAB/Simulink).
  • Currently:
    • Developing a full stack web application using Java (Spring Boot) and Javascript.
    • Learning machine learning in Python (with Tensorflow/Keras and from scratch).
    • Using Lua for game development.
    • Tinkering with Julia and Haskell.
  • Interested in Scala, Go and Rust.

Interests

Games

Bullet Sudoku

Bullet Sudoku is a small game I wrote in summer 2020 using my custom made game engine written in Python. A free demo of the game is available on itch.io. It is currently sitting at almost 100 downloads!

Short GIF of Bullet Sudoku gameplay

The source code is currently not open-source, but I plan on releasing a condensed open-source version of the game engine in the near future.

Game jam submissions

Since 2023 I published multiple game jam submissions, with open source code, to try out new technology and new ideas:

Unicast Network Sim: a Python game where you deliver network packets. Placed 16th out of 500 for innovation due to the creative input system.

Unicast network simulator gameplay

Myrkur: a dungeon exploration game written with Love2D in Lua.

Myrkur gameplay

Fungal Whimsy: a 2D precision platformer set in a dense mushroom forest.

Fungal Whimsy gameplay

Uncaved: a reverse cave-exploring game where you control a cave full of traps, written in Java with libGDX.

Uncaved gameplay

Pygame examples

I have a number of small / medium size pygame examples that illustrate a certain technique or explore game concepts, such as particle effects, lighting, events and networking, in more detail. Source code is available here.

Gif of the particle effects Gif of the lighting system Gif of the hexagonal tile map Gif of a red light source

Chess engine(s)

I have developed a semi-complete chess-engine in Python from scratch and done a fair amount of optimization, until realizing a fully optimized chess engine likely would require more speed than Python can offer, so I started work on an implementation in C. The C-code looks less beautiful, but already runs around 70 times faster :)

Here is an AI playing chess against itself using a minimax algorithm (depth 4) using the Python version:

Chess artificial intelligence playing a game

Music

Music analysis

Here's my music analysis tool, which I started building in 2018 and recently built a fancy user interface for:

Screenshot of the analysis GUI

Music generators

Over the years, I have worked on multiple procedural music generators, two of which are open-sourced on Github and available on pypi:

  • My Bach generator generates a transformed version of music input (via midi files) using a machine-learning algorithm optimizing for correlation of the output with the input. This ensures the produced musical transformations are internally consistent.
  • Continuo is a pypi package that procedurally generates music based on a provided set of input parameters.

Tools

Batest

Batest is a lightweight unit testing framework for Windows batchfile scripts. As no testing framework existed when I was learning Batch, I wrote my own ๐Ÿ‘.

It generates simple HTML test reports like this:

Screenshots of the test reports

Meta-programming

Natscript

Natscript is an interpreted programming language with a natural syntax resembling English:

define function main as {
    set squares to []
    for each number in range from 0 to 5 not equal to 3 {
        multiply it by itself, then append it to squares
    }
    return squares
}

# This will output [0, 1, 4, 16] to the console
print result of call main

Although a bit slow, due to its current main implementation being in Python, it is a fully functional language that support procedural and functional programming. Performance issues may be addressed in the future with the C++ version (currently still WIP), or by implementing a LLVM JIT-compiler for the language.

Object oriented batch

For people unfortunate enough to come to Batch with an object oriented background, I wrote an object oriented framework for Batch, including classes and instances, methods and attributes, inheritance, encapsulation, polymorphism and object composition.

As can be seen in the code examples below, the batch OOP syntax is surprisingly clean (for batch):

Simple use of a class instance:

::instantiate new object obj of type MyClass
call new MyClass obj construct

::calling method myMethod of instance obj
call # obj myMethod

::reading obj attribute myAttr
echo !%obj%.myAttr!

::writing obj attribute myAttr
set %obj%.myAttr=1

Simple class definition:

::boilerplate
call class %*
%class%

::this is the constructor, adding one custom attribute attr
:public-construct
    call super %*
    set %self%.attr=0
exit /b

It's probably not very useful, but at least it was fun to make ๐Ÿ’ฏ๐Ÿ’ฏ

Apps

  • I wrote a small shop application to solidify my understanding of SQL and handling confidential data securely in databases.
  • I also made a small chat application to get a good grasp of networking using websockets. The application can be run on a local network.

Gif of the application GUI

Stats

rbaltrusch's GitHub stats

natscript's People

Contributors

dependabot[bot] avatar rbaltrusch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

natscript's Issues

Input arguments and return values

Functions currently do not support input arguments or return values, which significantly limit their usefulness.

Function definitions should optionally include required input arguments or keyword arguments, e.g.

define function my_function taking arg1 and arg2 as {
...
}

Function calls should optionally include passed arguments, e.g.:

call my_function for arg1

A bug found when trying to execute conditionals.nat example

Describe the bug
Index out of range exception raised

To Reproduce
Steps to reproduce the behavior:

  1. Copy examples\conditionals.nat to test.nat for proper executing
  2. Run python interpreter\main.py
  3. See error

Expected behavior
A character '6' printed to console was expected.

Screenshots
image

If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows NT 10 Home
  • Browser: I dont think this is needed.
  • Version: current sources (trunk)

Smartphone (please complete the following information):
I don't think this is neded.

Additional context
I think that that the 1 should be replaced with -1 in this snippet:

        while self.token_stack and self.token_stack[1].satisfied:
            yield self.token_stack.pop()

(lines 39-40 in parse() in interpreter\parsing.py), because it works then and the rest of scripts that had worked before work too.

Blank lines throw errors

Extra blank lines between statements produce errors.

The following code runs fine:

set a to 1
print it

The following code throws an Interpreter error:

set a to 1
//(blank line)
print it
- InterpreterError: The following block had no type to be interpreted: Syntax Tree containing [Token(LINEBREAK, None), Token(PRINT, None)]!

Extra blank lines should not cause the interpreter to not be able to parse the *.nat file anymore and should instead be ignored.

Windows 10.

File I/O

The language currently does not support file input or output commands. Even simple file handling, such as open, read, write and close would significantly add to the usefulness and useability of the language.

Example implementation:

open example.txt and read it
close it
open example.txt as file
write my_data to file
close it

It would be ideal if files would automatically close once the file action is successfully done and the file handle is no longer needed (or an error occured), similar to how context managers work in Python.

Language documentation

Currently there is no documentation of the language features, besides some example scripts.

Language features should be documented in the wiki to elaborate on the details of the language.

Support lists and iteration

Currently, the language only supports scalar integer and float types. Lists and iteration through them via a for-loop, for-each or a map statement would significantly increase the flexibility and usefulness of the language.

Clauses do not have access to outer scopes

Inner scopes do not have access to variables defined in outer scopes. This makes it impossible to access global variables, define closures or even call a function inside another function defined elsewhere, e.g.

define function a as {
    print 1
}

define function b as {
    #this will fail because it doesnt have access to outer scope
    call a
}

To reproduce this example, run the following code, which assigns 1 to a global variable b, then tries to access this variable b to print it inside an inner scope.

set b to 1
set a to {print b} and call it

The example above results in the following exception:

Traceback (most recent call last):

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\main.py", line 25, in <module>
!    inter.interpret(syntax_block)

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\interpreter.py", line 26, in interpret
!    raise e

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\interpreter.py", line 23, in interpret
!    token.run(self)

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\token_.py", line 75, in run
!    function(interpreter)

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\tokens.py", line 188, in _run
!    function.get_value()(interpreter)

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\tokens.py", line 164, in run_tokens
!    token.run(interpreter)

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\token_.py", line 75, in run
!    function(interpreter)

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\tokens.py", line 73, in _run
!    print(value.get_value())

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\token_.py", line 152, in get_value
!    raise exceptions.UndefinedVariableException(self)

- UndefinedVariableException: Line 2: Tried to access undefined variable b!

Tested with Python 3.8.3, Win10.

Float values are not parsed properly

Float values in the example script example2.nat are not parsed properly, as source code strings, such as "1.5", are preprocessed by the lexer and split into three parts ("1", ".", "5"), which then cannot be recognized as a proper float value. As a result the script fails, as it contains an unexpected token (".").

To Reproduce

  1. Run example2.nat
  2. See error:
Traceback (most recent call last):

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\main.py", line 23, in <module>
!    tokens = list(lex.lex(file_contents))

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\lexer.py", line 16, in lex
!    token = self.token_factory.create_token(s)

  File "D:\Alle_Dateien\Code\Python\NatScript Interpreter\interpreter\token_.py", line 35, in create_token
-    raise exceptions.LexError(token, self.line_number)

LexError: Line 8: . was not expected at this time!

Expected behavior
Float values shouldnt be split by the preprocessing logic in the Lexer.

Occurs on main branch (commit 60a8bf9).

The bug should be caused by commit 96b8248.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.