ScratchScript 1.0 Help

Language Overview

ScratchScript is a general purpose, strongly typed high-level programming language. That means you can use it for any type of project, however the language was initially created to automate the process of creating emulators and other complex projects.

Intention

This project was started because I wanted to learn programming language design while also doing something unique. It's more of a proof of concept, since the generated Scratch project is not very optimized and may be slower than code that was created manually.

Structure

ScratchScript has three layers:

Features

ScratchScript operates on a stack. This means that some typical programming language structures which aren't native or present in Scratch are replicable:

  • Function return values (return value;)

  • Changing function arguments in-place without cloning them (this will be covered later)

  • Breaking out of control flow structures (break;)

  • Ternary operator (condition ? trueValue: falseValue)

It also includes several QoL improvements, such as:

  • for loops

  • Exponents (**) and binary shifts (<< and >>)

The compiler also includes helpful diagnostics for errors:

warning[W2]: dividing by 0 is not recommended and can lead to issues --> Examples/test.scrs:4:17 4 | let b = 1 / 0; | ^ here For more information about this warning, try `scrs explain W2`. error[E16]: math does not have the function maximum --> Examples/test.scrs:5:13 4 | let b = 1 / 0; 5 | let a = math.maximum(1, 2); | ^^^^ here 6 | } For more information about this error, try `scrs explain E16`. note[N1]: math is declared in this import --> Examples/test.scrs:1:1 1 | import * as math from "std/math"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here
Last modified: 02 мая 2024