WORK IN PROGRESS ! ! !
yalex will be a minimalist functional scripting language for embedded systems
Yet another language. Also, I'm Alex. It's worth noting that y is kind of similar to lambda which is popular for indicating functional programming language. What else? To lex is the process of taking text and convert it to tokens. Guess what, yalex does this too!
Yalex uses the reverse polish notation as it's main source of inspiration. You always build up a stack of things and can use operators to modify said stack - and of course produce effects. In yalex, these operators are functions and one function can be the operand of another.
Get the source and build it
git clone https://github.com/AlexanderBrevig/yalex cd yalex mkdir build cd build cmake .. make ./bin/yalex_test_app #-> run tests ./bin/release #-> run REPL
So, let's get right to it! Here's the hello world:
The hello world program
'hello world' print
Call this program some time later by simply issuing this token to the stack
hw and you'll be the hero for printing out this fine text.
Tech Tip: everything is a token
A function, a list, a number, a string, an operator. We are all data. We are all tokens. We are legion. We are many. Expect us.
Define a function that takes 1 argument
"sleep an amount of ms, be sure to prepare stack with at least 1 value" sleepms 1 ( pop delayms )
We can do PORT reads, writes, we can do bit trickery and we can call other functions. This depends on the particular Board Support Package you're running. For this example I assume that PORTA is exposed and handles a port write for the microcontroller.
"blink two leds in a loop" ( PORTA 0b11 PORTA 0b11 read ! write 1000 sleepms ) loop
errors 0 = ( 'no errors' print ) ( errors ' errors' 2 cat print ) ?
errors 2 > ( PORTA LED_RED 1 write ) when
List of tokens
All entries use
b to indicate operands to the operator.
Capital letters designate blocks.
An operand is either a single token, or a block.
... indicate a variable list of operands.
I use this convention for representing status:
not imlemented yet
'this is a string' ok?
12 12.3 -3 are all numbers
a is a variable, or just
'a' if used before it is
a b + => _ plus operator of
a b - => minus operator of
a b / => division of
a b * => multiplication of
a b > => is
a greater than
a b < => is
a lesser than
a b = => is
a ? => force
a to a truthy value where 0 == false, rest is true
a b ! =>
a is not
a b | =>
a b & =>
a b ^ =>
a pop => pop
a off the stack so if [1,2,a] then pop -> [1,2]
a dup => dublicates
a top of stack so if [1,2,a] then dup -> [1,2,a,a]
... clr => clears the stack so if [1,2,a] then clr -> 
a rot => rotate the stack so if [1,2,3] then rot -> [3,2,1]
a b set => set the value of
a to the value of
a b read => read value from
a with bit mask
a b write => write value to
a with bit mask
a b index => indexes a by b places, similar to
a[b] can be followed by a set
... x cat => string concatenate
x number of values off of stack
a print => print
a to UART/radio/stdout
true => a truthy value of 1.0f
false => a falsy value of 0.0f
nop => no operation, empty dummy token (for explicit I DON'T WANT ANYTHING HERE)
a? b? ( => start a block with optional name
a and optional arg length
... ) => end a block
a B when => when event
a is captured then block
B is executed
a X Y ? => if
a then block
X else block
A loop => loop block
A until it is
a kill => kill variable
a if it is user specified, builtins cannot be deleted