You are not logged in.    Login    New User    Forum Home    Search  RSS Feed 

Location:
James' Games Site  \  JBPlay.com General  \  General  \  Strolang

Back to Threads

Viewing Thread: Strolang

 

ParaSait

Joined: 26 June 2007
Posts: 1467
24 September 2015 20:58 (UK time)

Strolang

After getting intrigued by and reading lot about theory of computation/automaton theory/compiler design for months, I felt a nagging itch to get active and start coding something up in practice.
I made it my goal to create my own script/programming language, and implement an interpreter, and eventually perhaps even a compiler for it. That's when I came up with this project: Strolang.

And so, the last few months I've been spending lots 'n' lots of spare time coding on up a strolang engine (masuda and spy can confirm this :p). And now, I am about to proudly release a first version of it to the (small) public.

Strolang, at the moment (I'm kinda deciding the syntax bit by bit as I go), is a very c-like language, because I wanted to create a basic, non-specific, turing complete groundwork that I can safely extend upon later. There are not that many features as of yet however. In fact, it's still missing a ton of essential language construct and interpreter features - such as arrays, for loops, arithmetical brackets, and perhaps most importantly, a semantic analyzer (which in human language basically means: it won't check if the grammatically correct stuff you wrote actually makes sense too) is completely non-existent, and thus it'll happily crash to any nonsense.

But this is all planned! My own view on the quality of this first public version is that it's the first version that is not a complete and total abomination. :D

So without further ado, here's Strolang 0.1.4 Hotarun, download it from the attachment!
No formal documentation is included yet, so I'll just give you a quick explanation in this thread.
Happy coding, and please post any cool (and also buggy!) programs. Any feedback is naturally appreciated.
Oh, and also, if someone feels like creating a Strolang syntax highlight configuration for any text editor, like Notepad++ or something, please please do! I'll gladly send you the list of tokens in that case! :)

How to use

First off, here's how to install and run the engine. It's really simple.
1) Make sure Java 8 is installed.
2) Unzip the release somewhere. (and make sure you don't merge a new version with an old one, it will give problems...)
3) Add the directory to your PATH.
4) On unix, make sure strolang/strolang.sh are marked as executable.
5) Open your console and enter the command "strolang". It should work for both unix and windows. As soon as you run it, you'll be given some useful further information, but basically, to run a program just pass the path to your program as the parameter.
strolang /path/to/program.strol

(the extension doesn't really matter, but .strol is the officialish file extension for strolang source files :))

Syntax (as of v0.1 Hotarun)

Keep in mind, this is all more or less c-like. It'll probably not all that unfamiliar if you ever coded in c.

Comments take the form of
// single line
/* multiline */


A program is simply a set of function definitions. That means that at the absolute top level, nothing except for function definitions is allowed. So no includes, or global vars etc (yet).
The entry point that the engine will look for is the function int main(), with NO arguments (it's gonna be a string array in later versions for params, but right now it's nothing because there are no arrays yet in the language! :p)

There are 2 types of functions: internal and external.
Usually you'll be writing internal functions, they have a header and a body block.
void function(int argument) {
...
}

An external function - though not really applicable yet as of now, since you there's no way to bind libraries yet - only has a header and a reference to an api id, and is written like so (and notice the semicolon here):
void function(int argument) -> some_api;


A block (such as the internal function bodies) is a list of statements surrounded by curly brackets. Any statement that is not a nested block must end with a semicolon.
{ statement; statement{} statement; }


A statement can be either of the following:
- A function call        : awesome();
- A variable declaration : int val; (declarations can have an inline assignment clause as well - however you can't chain multiple declarations inline with a comma yet)
- A variable assignment : val = 5;
- An if block : if(val == 5) { ... }
- A while loop block : while(val < 10) { ... }
- A return statement : return val; (the value, in fact even the whole return statement, can be omitted if your function is a void)

As of now, the if and while MUST have a block. There's no single statement version yet.

An expression can be a variable reference, a literal, a function call, an assignment, or an operation.

The following types are supported and work pretty much as you'd expect:
bool val = false;
int val = 5;
dec val = 5.3; (same thing as a float, but I like calling it a "decimal" more, hence...)
char val = 'a'; (char literal = single quotes!)
string val = "strol"; (string literal = double quotes!)

... and a function can also have the special type "void".

The following operators are supported so far (some of them have extra secondary functions, such as + for concatenating strings, but that's a topic on it's own that I'll write about in the more elaborate docs :p). They also work pretty much as you'd expect.
Arithmetic : + - * / %
Logical : ! && ||
Comparison : == != < <= > >=
Assignment : = ++ -- (the increment and decrement work both as prefix and postfix)


And finally: right now, there is one hardcoded simple barebones api for io. And keep in mind that these functions ONLY work for strings thus far, I'm fully aware that that's a major hindrance, but hey... it's v0.1. :)
string in()
void out(string message)
void err(string message)


Okay, I might've forgot to mention a few things, but that's basically it so far. Happy coding!! (well, mainly bug reporting) :choc(^^,)
Attached Files
 strolang-0.1.4.zip (1509.2 KB) 1.4.ZIP File



This link is dead. It's only still here because, err... yknow, it's some sort of... memorial.


Edited: 24 September 2015 21:21


You need to login to create posts in this thread.

Spy

Joined: 05 October 2007
Posts: 1028
24 September 2015 21:20 (UK time)

STROL! :D

For the record, the term "strol" was coined by me somewhere around 2009. I, for some reason (probably boredom), started repeating the phrase "trol, roll and strol" in school and it sort of got stuck in my head, so then when I logged in on IRC and on #jbgames (or #jbplay, can't remember what the heck it was lol), I typed it in there too.
Eventually it just became an inside joke that has lasted up to this day, and it eventually (sort of) developed a meaning as well, although it's somewhat difficult to describe. Something like silly, erratic and/or parodic behavior would come pretty close, I guess. :p
I was known as Naval War before.
I love and mod Amnesia: The Dark Descent.


You need to login to create posts in this thread.

masuda
 Official Sponsor

Joined: 06 February 2005
Posts: 797
24 September 2015 21:22 (UK time)


Well, here's my first program in Strolang then! :D It's pretty much just a random mess, but it works! :D So here, take a look. (^^,)

//hotarun.strol

int main()
{
out("");
out("Enter text to hotarunify (use caps for best result :D)");
string text = in();
int i = 0;
while (i < 10)
{
hotarunify(i, text);
++i;
}
out(i++ + ++i+"");
return 0;
}

void hotarunify(int i, string s)
{
out(++i + " " + s + 5 * "E");
if (i % 2 == 0)
{
out("suchuruu~");
}
}

kawaii-chan益田せいじ / Masuda Seiji / PetiX

Meteor FE+ This version has 'Close FE after starting a mod' option.


Edited: 08 February 2016 01:26


You need to login to create posts in this thread.

me_mantis

Joined: 26 September 2003
Posts: 1144
14 October 2015 22:06 (UK time)

This seems cool even though I have no idea what I'd do with it! Cheers!

You need to login to create posts in this thread.

masuda
 Official Sponsor

Joined: 06 February 2005
Posts: 797
17 October 2015 08:16 (UK time)

Another epic masterpiece for use with strolang 0.2 :D
//sosuns.strol

int main(string[] args)
{
int r;
for (int i = 0; i < 25; ++i)
{
r = rng(50);
if (i < 10)
out("0");
if (r % 6 == 0)
{
outln(i + " -> SOSUNS" + r * 'A' + (i % 6) * '!');
}
else
{
out(i + " -> KOO" + r * 'E');
if (r % 7 == 0)
out(" suchuruu~");
outln("");
}
}
return 0;
}


And an updated ver of hotarunify enhanced with strolang 0.2 features
//hotarun.strol

int main(string[] args)
{
string text;
if (len(args) == 0)
{
out("Enter text to hotarunify (use caps for best result :D)");
text = in();
}
else
{
text = args[0];
}

int i = 0;
while (i < 10)
{
hotarunify(i, text);
++i;
}
return 0;
}

void hotarunify(int i, string s)
{
out(++i + " " + s + 5 * "E");
if (rng(3) % 3 == 0)
out(" suchuruu~");
outln("");
}


And finally testing arrays and elif
//array.strol

int main(string[] args)
{
int[] a;
int l = 10;

for (int i = 0; i < l; ++i)
a[i] = rng(100);

list(a);
a = order(a);
outln("");
list(a);

return 0;
}


void list(int[] a)
{
int l = len(a);

for (int i = 0; i < l; ++i)
{
out(a[i] ->string);
if (a[i] % 3 == 0)
outln(" KOOEEEEE");
elif (a[i] % 3 == 1)
outln(" suchuruu~");
else
outln(" SOSUNSAAAA!!");
}
}

int[] order(int[] a)
{
int swap;
int l = len(a);

for (int i = 0; i < l-1; ++i)
for (int j = i; j < l; ++j)
if (a[i] > a[j])
{
swap = a[i];
a[i] = a[j];
a[j] = swap;
}

return a;
}

kawaii-chan益田せいじ / Masuda Seiji / PetiX

Meteor FE+ This version has 'Close FE after starting a mod' option.


Edited: 17 October 2015 13:03


You need to login to create posts in this thread.

ParaSait

Joined: 26 June 2007
Posts: 1467
18 October 2015 00:14 (UK time)

^ awesome, these all work great in the latest alpha I just built. :choc

It's-a comin' soon...! :p


This link is dead. It's only still here because, err... yknow, it's some sort of... memorial.


You need to login to create posts in this thread.

ParaSait

Joined: 26 June 2007
Posts: 1467
19 October 2015 23:20 (UK time)

Strolang 0.2 Konochan
aka: the array version

Well, here it is! This version is a lot cooler than the previous one. You can actually, like do things with it.

Grab it here.

Now, what's new?

Features

Arrays
Aha! Konochan's creme de la creme new feature.
Here's a little demo of how arrays work in Strolang. It's a bit non-standard, but not that much.

int[] arr = int{2, 4, 6, 8, 10};
outln(len(arr) + " is 5, the size of our array.");
outln(arr[2] + " is 6. Note that the index starts at 0.");
arr[2] = 7;
outln(arr[2] + " is 7 now.");
outln(arr[5] + " is 0, because the element is not defined.");
arr[5] = 12;
outln(arr[5] + " is 12 now.");
outln(len(arr) + " is 6 now, since the last operation on element 5 extended the array size.");
int[] otherArr = arr;
otherArr[0] = 3;
outln(otherArr[0] + " is 3.");
outln(arr[0] + " is still 2. This means that arrays are assigned by value, not by reference.");
arr = int{};
outln(len(arr) + " is 0, since we made it an empty array now.");


for loops
An essential language feature that goes hand in hand with arrays. It's the classic for loop that takes an initializer, a loop condition and an iterator, separated by a semicolon.
Enhanced for (aka "foreach") is not supported, yet.

string[] fruits = string{"apples", "oranges", "grapes", "prickly pears", "durians"};
for(int i = 0; i < len(fruits); i++) {
unless(i == 4)
outln("I like " + fruits[i]);
else
outln("I freaking hate " + fruits[i] + ". Screw those.");
}


Single statement structures
In Hotarun, if and while structures only took blocks as their body, even if you want it to do only one thing. In Konochan you can attach either a block or a single statement to structures.

if(1 + 1 == 2) out("Good thing math still works!"); else out("WE'RE ALL GONNA DIE!!");
while(1 + 1 == 2) out("Math is still not broken... could happen any time now...");


elif/else clauses
In Hotarun there was only an if statement. An if statement can now also take elif and else clauses. You can tack on as many elifs as you want, as long as they're between if and else, and else is optional.
Elif is a shorthand for "else if", which is also fine to use.

if(a)
aStuff();
elif(b)
bStuff();
else
otherStuff();


unless/until structures
These are the dark twin brothers of if and while. They work in the same way, but the value of their condition is negated.
One other notable difference, though, is that unless does not take elif clauses (but does optionally take an else clause).

unless(1 + 1 != 2) out("1 + 1 is still none other than 2!");
until(1 + 1 != 2) out("the world will stay intact.");


break/continue statements
Control statements for loops (works for while, until and for).
break will end the execution of the loop and get out before the loop condition is satisfied.
continue will end the execution of the loop's current iteration and go on to the next one.

while(1 == 1) {
outln("This statement will be reached");
break;
outln("This statement won't be reached");
}
outln("This statement will be reached even though 1 won't ever be anyhing other than 1. Unless the law of identity breaks.");
outln("Who knows what it might be then. Maybe it will be 3. Maybe it will be 43848. Maybe it will be a cat sometimes.");

for(int i = 0; i < 5; i++) {
outln("This statement will be reached 5 times.");
continue;
outln("This statement won't ever be reached.");
}


Brackets
The brackets that your know from math class, to be explicit about your precedence.

1 + 2 * 3 == 7
(1 + 2) * 3 == 9


New arithmetic operators
Strolang now features the power operator, as well it's counterpart, the (unique!) root operator. Do you know any other programming language with a root operator? Yeah, didn't think so.

2 ** 3 == 8
8 \ 3 == 2


Arithmetic assignments
These are just the little shorthands of the general form (a = a <op> b) <=> (a <op>= b). There's one for each kind of arithmetic operation. Pretty straightforward and nothing unique ('cept for the root variation).

a += b
a -= b
a *= b
a /= b
a %= b
a **= b
a \= b


New logical operators
While Hotarun already featured the basic and/or/not operators, Konochan also features the pretty unique nand/nor/xor/xnor.
Xor and xnor are almost the same thing as != and ==; the only difference is slightly higher operator precedence (same level as the other logical operators), as well as being a more clear expression of your intent in some situations.

a !& b // nand
a !| b // nor
a ^^ b // xor
a !^ b // xnor


Conversion operator
Unique to Strolang, it's comparable to typecasting in other languages, but it's a bit smarter. It converts values to another type. How this conversion goes varies on a case by case basis.
Note that Konochan can NOT convert to and/or from arrays yet. This will be added in the future, though.

"123"->int == 123
123->string == "123"
true->int == 1
1->bool->string == "true"


There's a lot more where that came from, but I'm not gonna be listing all of them. You get the idea. :)

Extended standard library
It contains some more essential functions. Refer to the apidoc.txt file for more information.

main arguments
While in Hotarun there was the function int main() as the entry point, Konochan looks for int main(string[]). The string array contains the arguments passed from the command line. I couldn't add this previously, because there was no such thing as an array yet. :)

int main(string[] args) {
outln("You passed the following arguments to this program:");
for(int i = 0; i < len(args); i++)
out(args[i] + ", ");
}


Meanwhile on the command line...

strolang argsdemo.strol one two three




And that is all for now. Once again, have fun coding some strol programs. :choc
Attached Files
 strolang-0.2.zip (1555.7 KB) 2.ZIP File



This link is dead. It's only still here because, err... yknow, it's some sort of... memorial.


Edited: 19 October 2015 23:41


You need to login to create posts in this thread.

masuda
 Official Sponsor

Joined: 06 February 2005
Posts: 797
21 October 2015 12:54 (UK time)

First actually useful program written in strolang 0.2.1! A BrainFuck interpreter. :D
//bf.strol

int main(string[] args)
{
//getting the BrainFuck source

char[] source;
outln("Type in your BrainFuck source code or press Enter to use the one in bf.strol");
outln("");
string typedSource = in();
if (typedSource != "")
source = typedSource->char[];
else
source = "++++++[>+++[>++++<-]<-]>>.>++++++++[>++++++++<-]>+." ->char[]; //type your code here


//init

int endOfCode = len(source);
int[] arr;
int minRange = 0;
int maxRange = 255;
int arrLength = 30000;
int dp = 0; //data pointer
int ip = 0; //instruction pointer
for (int i = 0; i < arrLength; ++i)
arr[i] = 0;


//interpreting

while (ip < endOfCode)
{
if (source[ip] == '+')
++arr[dp];

if (source[ip] == '-')
--arr[dp];

if ((source[ip] == '<') && (dp > 0))
--dp;

if ((source[ip] == '>') && (dp < arrLength))
++dp;

if (source[ip] == '.')
out(arr[dp]->char->string);

if (source[ip] == ',')
arr[dp] = in()->int;

if ((source[ip] == '[') && (arr[dp] == 0))
{
int match = 1;
while (match != 0)
{
++ip;
if (source[ip] == '[')
++match;
elif (source[ip] == ']')
--match;
}
}

if ((source[ip] == ']') && (arr[dp] != 0))
{
int match = 1;
while (match != 0)
{
--ip;
if (source[ip] == '[')
--match;
elif (source[ip] == ']')
++match;
}
}

if (arr[dp] < minRange)
arr[dp] = maxRange;

if (arr[dp] > maxRange)
arr[dp] = minRange;

++ip;
}

return 0;
}


Alternatively you can also pipe a brainfuck source like this:
strolang bf.strol < brainfuck.src
kawaii-chan益田せいじ / Masuda Seiji / PetiX

Meteor FE+ This version has 'Close FE after starting a mod' option.


Edited: 21 October 2015 15:03


You need to login to create posts in this thread.

masuda
 Official Sponsor

Joined: 06 February 2005
Posts: 797
03 November 2015 12:42 (UK time)

And now something that even non-programmers can use! A game of 21 :D

//21.strol

int main(string[] args)
{
/////////// init
//string[] type = string{"spade", "club", "heart", "diamond"};
string[] value = string{"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};

int drawnCard;
bool[] drawn;
for (int i = 0; i < 52; ++i)
drawn[i] = false;

string[] player;
string[] dealer;
int pi = 0;
int di = 0;

int win = 0;

string action = "";


/////////// main

outln("stop - s | draw - almost anything else :D | dealer must draw on 16 and below");
outln("");

//new game's initial hand
drawnCard = draw(drawn);
drawn[drawnCard] = true;
player[pi] = value[drawnCard % 13];
++pi;

drawnCard = draw(drawn);
drawn[drawnCard] = true;
dealer[di] = value[drawnCard % 13];
++di;

drawnCard = draw(drawn);
drawn[drawnCard] = true;
player[pi] = value[drawnCard % 13];
++pi;

drawnCard = draw(drawn);
drawn[drawnCard] = true;
dealer[di] = value[drawnCard % 13];
++di;

outln("Dealer has: * " + dealer[1]);
outln("");
out("You have: ");
showCards(player);

win = check(player, dealer);

if (win == 0)
{
out("action: ");
action = in();
}

//player's turn
while ((win == 0) && (action != "s"))
{
drawnCard = draw(drawn);
drawn[drawnCard] = true;
//outln(type[drawnCard / 13] + " " + value[drawnCard % 13]);
player[pi] = value[drawnCard % 13];
++pi;

outln("");
out("You have: ");
showCards(player);

win = check(player, dealer);
if (win != 0) break;

out("action: ");
action = in();
}

//dealer's turn
while ((win == 0) && (sum(dealer) <= 16))
{
drawnCard = draw(drawn);
drawn[drawnCard] = true;
dealer[di] = value[drawnCard % 13];
++di;
win = check(player, dealer);
}

outln("");
out("Dealer has: ");
showCards(dealer);

//final evaluation
if (win == 1) outln("You won!");
elif (win == -1) outln("You lost!");
elif ((win == 0) && (sum(player) > sum(dealer))) outln("You won!");
elif ((win == 0) && (sum(player) < sum(dealer))) outln("You lost!");
else outln("Tie");
}


int draw(bool[] drawn)
{
int card = rng(52);

while (drawn[card])
card = rng(52);

return card;
}


int check(string[] p, string[] d)
{
int psum = sum(p);
int dsum = sum(d);

if (psum > 21) return -1;
if (dsum > 21) return 1;
if (len(p) == 2)
{
if ((psum == 21) && (dsum == 21)) return 483;
if (psum == 21) return 1;
if (dsum == 21) return -1;
}
return 0;
}


int sum(string[] hand)
{
int s = 0;
int Acnt = 0;
int l = len(hand);

for (int i = 0; i < l; ++i)
{
if (hand[i] == "2") s += 2;
elif (hand[i] == "3") s += 3;
elif (hand[i] == "4") s += 4;
elif (hand[i] == "5") s += 5;
elif (hand[i] == "6") s += 6;
elif (hand[i] == "7") s += 7;
elif (hand[i] == "8") s += 8;
elif (hand[i] == "9") s += 9;
elif (hand[i] == "10") s += 10;
elif (hand[i] == "J") s += 10;
elif (hand[i] == "Q") s += 10;
elif (hand[i] == "K") s += 10;
elif (hand[i] == "A") ++Acnt;
else outln("You shouldn't see this lol");
}

if (Acnt != 0)
{
if (Acnt > 1)
s += Acnt - 1;
if (s + 11 > 21)
++s;
else
s += 11;
}

return s;
}


void showCards(string[] hand)
{
int l = len(hand);
for (int i = 0; i < l; ++i)
out(" " + hand[i]);
outln(" => " + sum(hand));
}

kawaii-chan益田せいじ / Masuda Seiji / PetiX

Meteor FE+ This version has 'Close FE after starting a mod' option.


Edited: 03 November 2015 13:13


You need to login to create posts in this thread.

masuda
 Official Sponsor

Joined: 06 February 2005
Posts: 797
15 December 2015 18:02 (UK time)

This time I made a simple mandelbrot set. :D
                                                 . .
. **.
.*******
.* *.*******......
************************.
.**************************.
.. * *****************************.
.********. .*******************************
. .******************************************.
**********************************************************.
. .******************************************.
.********. .*******************************
.. * *****************************.
.**************************.
************************.
.* *.*******......
.*******
. **.
. .

And here's the code for it:
//fractal.strol
int main(string[] args)
{
int w = 79;
int h = 23;
int cycles = 25;
dec minR = -2.0;
dec maxR = 1.0;
dec minI = -1.2;
dec maxI = 1.2;
dec rFact = (maxR - minR) / (w - 1);
dec iFact = (maxI - minI) / (h - 1);
dec r;
dec i;
dec Zr;
dec Zi;
dec Zr2;
dec Zi2;

for (int y = 0; y < h; ++y)
{
i = maxI - y * iFact;

for (int x = 0; x < w; ++x)
{
r = minR + x * rFact;
Zr = r;
Zi = i;

int n = 0;
while ((n < cycles) && (Zr * Zr + Zi * Zi < 4.0))
{
Zr2 = Zr * Zr;
Zi2 = Zi * Zi;

Zi = 2.0 * Zr * Zi + i;
Zr = Zr2 - Zi2 + r;
++n;
}

if (n == cycles)
out("*");
elif (n > cycles / 2)
out(".");
else
out(" ");
}
outln("");
}
}


There's also a much better looking fractal I made in Javascript attached to this post. Feel free to check it out. (^^,)
Attached Files
 yuki.zip (0.9 KB) ZIP File Archive

kawaii-chan益田せいじ / Masuda Seiji / PetiX

Meteor FE+ This version has 'Close FE after starting a mod' option.


You need to login to create posts in this thread.

ParaSait

Joined: 26 June 2007
Posts: 1467
15 December 2015 19:56 (UK time)

Very cool one - and thanks for the two bug reports you dug up while making this one :D

After a short hiatus I've picked up the work on strolang again a couple weeks ago.
It's coming along fine, and seeing as how it's going to contain a few more advanced features as well as how the code health has been vastly improved compared to 0.2 I have a feeling it's gonna be an awesome version... stay tuned! :choc:choc:choc


EDIT: oh yea, I forgot to publicly release that 0.2.1 version from way back. Not gonna bother making a big announcement over it, it was made solely for supporting masuda's brainfuck interpreter, so you'll need it if you wanna run that one.

From the yet unreleased changelog:

v0.2.1 Konochan+
================
[ADD] string to char[] conversion
[ADD] char[] to string conversion
[MOD] conditional expression values are implicitly converted to booleans


Get it in the attachment below.
Attached Files
 strolang-0.2.1.zip (1556.5 KB) 2.1.ZIP File



This link is dead. It's only still here because, err... yknow, it's some sort of... memorial.


Edited: 07 February 2016 17:15


You need to login to create posts in this thread.

masuda
 Official Sponsor

Joined: 06 February 2005
Posts: 797
07 February 2016 17:39 (UK time)

A strol little program to 'welshify' a given text (according to Para's specifications :D) for strolang 0.3
Y sstrol llitttle prryggrram tto 'wellshiffyy' y ggivyn ttexxtt (yccccyrddynng tto PPyrry'ss speccyffycytionss :DD) ffyrr ssttrryllyng 0.3

//welshifier.strol

int main(string[] args)
{
string src;
char[] welsh;
int wi = 0;
int rnd;
char c;
string vowels = "aiueo";
string consonants = "qrtzpsdfghjklyxcvbnm";

outln("Enter text to welshify.");
src = in();
int l = len(src);

for (int i = 0; i < l; i++)
{
c = charAt(src, i);
rnd = rng(0, 2);

// w -> ŵ
if (c == 'w' && rnd)
{
welsh[wi] = 'ŵ';
wi++;
}

// W -> Ŵ
elif (c == 'W' && rnd)
{
welsh[wi] = 'Ŵ';
wi++;
}

// small vowels -> y
elif (indexOfChar(vowels, c) != -1 && rnd)
{
welsh[wi] = 'y';
wi++;
}

// capital vowels -> Y
elif (indexOfChar(toUpperCase(vowels), c) != -1 && rnd)
{
welsh[wi] = 'Y';
wi++;
}

// consonants -> 2x
elif ((indexOfChar(consonants, c) != -1 || indexOfChar(toUpperCase(consonants), c) != -1) && rnd)
{
welsh[wi] = c;
wi++;
welsh[wi] = c;
wi++;
}

// rng fails and others
else
{
welsh[wi] = c;
wi++;
}
}

outln(join(welsh));
return 0;
}


///////////////////////////////////////////////////

int indexOfChar(string s, char c)
{
char[] str = explode(s);
int pos = -1;
int l = len(str);
int i = 0;

while (pos == -1 && i < l)
{
if (c == str[i])
pos = i;
i++;
}

return pos;
}

char charAt(string s, int i)
{
char[] str = explode(s);
return str[i];
}

string toUpperCase(string s)
{
char[] str = explode(s);
int l = len(str);

for (int i = 0; i < l; i++)
{
if (str[i]->int >= 97 && str[i]->int <= 123)
str[i] = (str[i]->int - 32)->char;
}

return join(str);
}

kawaii-chan益田せいじ / Masuda Seiji / PetiX

Meteor FE+ This version has 'Close FE after starting a mod' option.


Edited: 07 February 2016 17:40


You need to login to create posts in this thread.

ParaSait

Joined: 26 June 2007
Posts: 1467
07 February 2016 19:01 (UK time)

Strolang 0.3 Honokachin
aka: the expressive version

It's been a while, but here it finally is. This version has had a huge focus on internal refactoring (especially on the implementation of arrays and operators), but there are quite a few new features and fixes as well, some of them being extremely useful.

Snatch it here.

Okay, here's what's new.

Alternate number systems for int literals
Prior to this version, integer values could only be expressed in the decimal number system. Now, they can also be written in binary, octal and hexadecimal. The notations for these conform to the c convention (I experimented with some rebellious new notations at first, but trust me, it sucked :D)...

42 // decimal
0b101010 // binary
052 // octal
0x2A // hexadecimal


Underscores in int and dec literals
This is a bit of syntactic sugar. In int and dec literals you can now write _'s anywhere. This doesn't mean anything to the interpreter, it's just there to improve the readability of long numbers for your own convenience.
(note: just don't put an underscore as the first character, since that will make it a variable name by definition :))

123_456_789
12_34.67_89


Escape sequences in char/string literals
You can now use escape sequences in chars and strings. This allows you to express characters that wouldn't otherwise be easily expressable:

\n = newline
\r = carriage return
\t = tab
\' = single quote
\" = double quote
\\ = backslash


Declaring multiple variables in a single statement
You can declare multiple variables of the same type in a single statement by separating the list of names (and their optional initializer) by commas.

int first, second, third;
int first = 1, second = 2, third = 3;


Bitwise operators
Aside from the logical operators, you can now use bitwise operators. For now, these only work on integers though. Most of these operators once again are from c, but there are a couple unique Strolang ones as well.
They have assignment versions too!
Note: it's relevant to say at this point that integers are 32bit in Strolang.

0b101100 << 2 == 0b10110000 // left bitshift
0b101100 >> 2 == 0b001011 // right bitshift
~0b1010 == 0b11111111_11111111_11111111_11110101 // bitwise NOT
0b1010 & 0b1100 == 0b1000 // bitwise AND
0b1010 ~& 0b1100 == 0b11111111_11111111_11111111_11110111 // bitwise NAND
0b1010 | 0b1100 == 0b1110 // bitwise OR
0b1010 ~| 0b1100 == 0b11111111_11111111_11111111_11110001 // bitwise NOR
0b1010 ^ 0b1100 == 0b0110 // bitwise XOR
0b1010 ~^ 0b1100 == 0b11111111_11111111_11111111_11111001 // bitwise XNOR


Multidimensional arrays
Prior to this version, array could have only 1 dimension. Now they can have pretty much as many as you fancy.

int[][] twodim = int[]{
int{1, 2, 3},
int{4, 5, 6},
int{7, 8, 9}};

twodim[1][2] = 0;
out(twodim[1][2]);


explode and join functions
The basic api (I guess we can start calling it a bit of a standard library at this point :)) has two new useful functions: explode and join. This replaces the string to char[] and char[] to string conversions from 0.2.1.

explode("strol") == char{'s', 't', 'r', 'o', 'l'}
join(char{'s', 't', 'r', 'o', 'l'}) == "strol"


Alternate argument types for out/outln/err/errln
These functions now also take arguments that aren't strings, or in the case of the -ln functions, no argument at all.

outln(true); // true
outln(42); // 42
outln(42.1); // 42.1
outln('a'); // a
outln(); // (blank, just the newline)


Comparing ints to decs
This wasn't possible in previous versions.

42 == 42.0
42 != 42.1


Truthy and falsey
Logical operators and conditional statements can now handle non-boolean expressions. It checks if the value is "truthy" or "falsey". For example, 0 is falsey, and another integer is truthy, an empty string is falsey, a non-empty string is truthy, ...

0 || "" == false
while(1) {...} // holy cow, infinite loop!


c/java style operator precedence
Operator precedence was a little messed up in previous versions. I've made it more c/java-like now, so you don't need to write so many brackets anymore.

->
x++ x--
++x --x +x -x ~ !
** \
* / %
+ -
<< >>
< > <= >=
== !=
& ~&
^ ~^
| ~|
&& !&
^^ !^
|| !|
= += -= *= /= %= **= \= <<= >>= &= |= ^= ~&= ~|= ~^=




Alrighty, well I'm fully aware that my "documentation" on all this is kinda wonky so far, I'll try to do something about that in the next version maybe. For now, if you got questions, don't be afraid to ask.
Happy coding boys! :choc
Attached Files
 strolang-0.3.zip (2155.7 KB) 3.ZIP File



This link is dead. It's only still here because, err... yknow, it's some sort of... memorial.


Edited: 07 February 2016 23:35


You need to login to create posts in this thread.

masuda
 Official Sponsor

Joined: 06 February 2005
Posts: 797
07 February 2016 19:52 (UK time)

All the strols so far updated to strolang 0.3
Attached Files
 strols.zip (291.7 KB) ZIP File Archive

kawaii-chan益田せいじ / Masuda Seiji / PetiX

Meteor FE+ This version has 'Close FE after starting a mod' option.


You need to login to create posts in this thread.

ParaSait

Joined: 26 June 2007
Posts: 1467
08 February 2016 00:03 (UK time)

Here's a new one written by me. It's a little hangman game. It took 20 minutes to code, and 30 to find one little bug. :p (I definitely need to make debugging Strolang programs easier in the next version lol)

EDIT: It's still a bit bugged on the whole game over thing but whatever. Feel free to fix and mod edit the code P. :D

MOD: it should work now //masuda

// hangman.strol

int main(string[] args)
{
string[] dictionary = string {
"strol",
"kalja",
"mulju"
};

string[] stages = string {
" \n" +
" \n" +
" \n" +
" \n" +
"____ \n",

" \n" +
" |\n" +
" |\n" +
" |\n" +
"____|\n",

" --+\n" +
" |\n" +
" |\n" +
" |\n" +
"____|\n",

" ,--+\n" +
" |\n" +
" |\n" +
" |\n" +
"____|\n",

" ,--+\n" +
" O |\n" +
" |\n" +
" |\n" +
"____|\n",

" ,--+\n" +
" O |\n" +
" | |\n" +
" |\n" +
"____|\n",

" ,--+\n" +
"_O |\n" +
" | |\n" +
" |\n" +
"____|\n",

" ,--+\n" +
"_O_ |\n" +
" | |\n" +
" |\n" +
"____|\n",

" ,--+\n" +
"_O_ |\n" +
" | |\n" +
"/ |\n" +
"____|\n",

" ,--+\n" +
"_O_ |\n" +
" | |\n" +
"/ \\ |\n" +
"____|\n"
};

char[] options = char {
'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y',
'z', ' '};

char hiddenLetter = '-';

string word = dictionary[rng(len(dictionary))];

startGame(word, stages, options, hiddenLetter);

return 0;
}

bool startGame(string word, string[] stages, char[] options, char hiddenLetter)
{
char[] hits = char{};
char[] misses = char{};
string displayWord;
bool missFlag = false;
char guess;
bool validGuessFlag;

outln("Welcome to hangman. Guess the word, or else you will DIE.");
outln();

while(indexOfChar(displayWord = determineDisplayWord(word, hits, hiddenLetter), hiddenLetter) != -1)
{
if(missFlag)
{
outln(stages[len(misses) - 1]);
if(len(misses) == len(stages))
break;
else
missFlag = false;
}

outln(displayWord);
outln("Hits: " + join(hits));
outln("Misses: " + join(misses));

guess = 0->char;
validGuessFlag = false;
while(!validGuessFlag)
{
out("Guess a letter: ");
guess = in()->char;
if(indexOfChar(hits, guess) != -1 || indexOfChar(misses, guess) != -1)
outln("You already tried that one.");
else if(indexOfChar(options, guess) == -1)
outln("That's not an option.");
else
validGuessFlag = true;
}

if(indexOfChar(word, guess) != -1)
hits[len(hits)] = guess;
else
{
misses[len(misses)] = guess;
missFlag = true;
}
}

if(len(misses) == len(stages))
{
outln("Aww snap, you lost!");
return false;
}
else
{
outln("Grats, you won!");
return true;
}
}

string determineDisplayWord(string word, char[] hits, char hiddenLetter)
{
char[] wordChars = explode(word);
char[] displayChars = char{};

for(int i = 0; i < len(wordChars); i++)
{
char letter = wordChars[i];
if(indexOfChar(hits, letter) == -1)
displayChars[i] = hiddenLetter;
else
displayChars[i] = letter;
}

return join(displayChars);
}

int indexOfChar(char[] str, char c)
{
int pos = -1;
int l = len(str);
int i = 0;

while (pos == -1 && i < l)
{
if (c == str[i])
pos = i;
i++;
}

return pos;
}

int indexOfChar(string s, char c)
{
return indexOfChar(explode(s), c);
}



This link is dead. It's only still here because, err... yknow, it's some sort of... memorial.


Edited: 08 February 2016 01:23


You need to login to create posts in this thread.



Forums system (C) 1999, 2016 by James Bunting.

Terms of Use