Various parser updates and fixes have been implemented (including reintroduced support for the ternary conditional operator ?: ).
Slightly strangely, ?: has very low operator precedence. This means that in the following expression:
y is 0, not 1. The reason for this is that as ?: has low precedence, it gets evaluated after both ++x and --x.
To further confuse issues, before adding ternary operator support to the parser I implemented an if() function, like this:
This was inspired by VB's IIf() function. However, as this function can pick and choose which expressions to evaluate, y becomes 1. This is backwards to convention where the C-style ?: operator is lazy (only executing the successful side) and the BASIC-style if() isn't, executing both sides first.
Multi-line statements are the next area of contention. Currently a statement is terminated with a newline or a \ character. However, in some special cases, this termination is disabled - for example, by the .define directive. Another directive that does this is the .enum directive, which results in syntax like this:
Code: Select all
.enum Days
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
\
/*
This creates the following labels:
Days.Sunday = 0
Days.Monday = 1
Days.Tuesday = 2
...
Days.Saturday = 6
*/
.enum Numbers
Eleven = 11,
Twelve,
Thirteen,
Twenty = 20,
Vingt = 20,
Zwanzig = 20,
TwentyOne,
Four = 4,
Five
\
.echoln Numbers.Eleven ; 11
.echoln Numbers.Twelve ; 12
.echoln Numbers.Thirteen ; 13
.echoln Numbers.Twenty ; 20
.echoln Numbers.Vingt ; 20
.echoln Numbers.Zwanzig ; 20
.echoln Numbers.TwentyOne ; 21
.echoln Numbers.Four ; 4
.echoln Numbers.Five ; 5
I think that using the \ termination character is rather neat. Others may disagree, so I'd like to hear your ideas.
In a similar vein, I've added support for runtime-aliased plugins. This can be used by a user-defined function plugin, so the following is now possible:
Code: Select all
; A recursive function that calculates n!
.function factorial(n)
if(n <= 0, 1, n * factorial(n - 1))
\
; 1.5511210043331E+25
.echoln factorial(25)
Finally, for silliness, I've added a new plugin collection that handles images:
Code: Select all
; Open the image:
img = imgopen("delete.png")
; Loop over each pixel in the image:
.for y = 0, y < imgheight(img), ++y
.for x = 0, x < imgwidth(img), ++x
; Grab the luminosity of each pixel to two bits:
l = imggetpixel(img, x, y, 'l2')
; Convert to an 'ASCII-art' brightness:
c = choose(l + 1, ' ', '.', '+', '#')
.echochar c, c
.loop
.echoln
.loop
/*
....++++....
++++########++..
++######++++++##++..
++++##++++++++++++##++..
..++##++++++++++++++++##..
..##++++++++++++++++++++++..
++##++++############++++++..
++##++++############++++++..
..++++++++++++++++++++++++..
....##++++++++++++++++++..
..++++++++++++++++++++..
..++++++++++++++++..
....++++++++....
........
*/
"l2" in imggetpixel is the pixel format you want - for example, "argb" or "b2g2r2" (if no width is specified, 8 bits is assumed).
It might look useless, but it at least gives me some decent parser testing material.
