Discuss Scratch

Greg8128
Scratcher
500+ posts

Micron v0.3

Presenting: Micron 0.3!

A while back, I presented Micron v0.1 on this forum to generally positive feedback. Since then, I have made considerable improvements to the language, the most recent of which is 0.3.

Micron 0.1 was the first programming language in Scratch to support a C-like type system (featuring pointers, user-defined types, etc.) Micron 0.3 expands on 0.1 by adding a macro system which allows the grammar of the language to be systematically expanded as the programmer sees fit. Several features of Micron (most notably loops) are defined using the macro system.

Below is a guide to the current version. It focuses on breadth over depth, so feel free to ask me additional questions:
Syntax: consists of s-expressions. The first element of the s-expression tells the compiler what to do with it.

Builtin atoms:
true true boolean
false false boolean

Builtin types:
var the basic data type
void used to indicate that function or expression returns nothing
ptr<x> pointer to x
fun<x> function returning x
arr<x><n> array with elements of type x. Has n elements. n must be a number literal

S-expressions:
(first-term ...)
so for example: 1+2+3 is written as (+ 1 2 3)



+ addition (+ and - have overloading behavior for pointers)
- subtraction (inverse if only one element after -)
* multiplication
/ division
mod modulo
join join as strings

not boolean not
> greater than
< less than
>= greater or equal to
<= less or equal to
= equal
!= not equal

get get element of struct array or pointer
adr get pointer to element
drf dereference pointer
iget (indirectly) get element

local define a local variable of a given type
static define a static variable of a given type
set overwrite the value of something in memory
change change value of variable by x

if general-purpose if statement.
Can be used like the ternary operator if there is a default case.
progn do everything inside as one expression. Returns result of last expression.

loop 'forever' loop
break exit current loop
until repeat-until loop
while while loop
for c-like for loop

defun define a function and its output, input and body
return return from a function
*** call function ***, assuming that *** is the name of a function.
*** can also be an expression which evaluates to a function

deftype define a data type (like a struct in c)

msg send a message for other sprites to execute.
arguments can be read by other sprites.

pause force the code to pause. Basically a builtin breakpoint

charat get string's nth letter
cont? string a contains string b?
random pick random a to b

length length of str
sin sine (sin cos and tan take angle in degrees)
cos cosine
tan tangent
floor floor function
ceil ceiling function
round round
sqrt square root
asin arcsine
acos arccosine
atan arctangent
ln natural log
log base 10 log
e^ e^
10^ 10^

Syntax examples:

(defun add2 var ((var a)(var b))
(local var output (+ a b))
(return output)
)
(msg 'say' (add2 3 4) 2)


(deftype 3dpoint-t (
(var x)(var y)(var z)
))
(local 3dpoint-t p1)
(set (get p1 x) 3)


(local var x)
(local var y)
(set x (if
(= y 0) 'zero'
(= y 1) 'one'
(= y 2) 'two'
'unsupported number'
)
)

Macros:
There are a few examples under 'Micron default code'. If you have questions about the macro system, feel free to ask me.
sathvikrias
Scratcher
500+ posts

Micron v0.3

wow!
thatwasdeadsimple
Scratcher
100+ posts

Micron v0.3

Nice! I can imagine this taking a long, long time. Good effort!

Powered by DjangoBB