back to compiler

reference

reference

this is a reference if you want to write stuff in parserlang

amount of whitespace (including newlines) is not significant, and there are no semicolons or other statement delimiters

there are only single line comments with #

string literals are double quoted

there are a few escape sequences: \\, \", \n, \x## (hex escape code)

functions / generators

all functions are like generators

there are two ways to call a function: direct (normal function call) and using the gcall() builtin

a direct call acts like a normal function call - it returns one value at a time - and it adds a backtracking marker so the rest of the code is run with each value yielded from the call

a gcall() call returns a generator / iterator instead

statements

variable definition and assignment

variables are declared and defined at the same time using the keyword def: def <variable> = <value>

variable assignment is (as usual) <variable> = <value>

yield and return

return may have a value or not

it yields a value if it has one and then ends the execution of the function

yield always has a value

it yields the value and does not end the function

control flow

block statement is just a list of statements enclosed by {}

if statement is if <condition> then <body (statement or block)>

the condition does not need parentheses

there is no else or else if statement... :/

for statement is for <variable> in <expression (iterable)> do <body (statement or block)>

while statement is while <condition> do <body (statement or block)>

function definition

a function definition is fn <name>(<argument names>) <body (always a block)>

fun fact: i may have decided on no parentheses in if and while and defining functions with fn before i got into rust

scopes

all variables are confined to their scope, which starts at the definition and ends at the surrounding brackets (except in cases like if condition then def var = 3, where var's scope ends after the if statement (this is useless (why would you do this))

function definitions are also scoped like variables, but they are hoisted to the top of their scope like in javascript

builtins

there are a few builtin functions right now