02 Feb, 2010, Tyche wrote in the 21st comment:
Votes: 0
Scandum said:
Tyche said:
No a linklist wouldn't work. At least I've never seen it in any parser I've looked at as the data structure is too simplistic.

A linked list works fine, just need to store the nesting level in each token, so when an if check is false you skip tokens till the level drops back to the current level. Instead of skipping tokens you can add a pointer to the next valid token, which would create a tree. If you know the number of tokens in advance (or as part of the optimization process) it's probably faster to use an array, and for additional speed you can use index numbers instead of pointers to jump ahead.


I think you may be getting ahead to the final output, which could be a bytecode stream. In some simple languages, like assembler, nothing more than a simple transform is required. Most higher level languages, require more complex parsing and the intermediate representation of an AST is much more flexible and amenable to analysis of the code.

Scandum said:
Lolahas a mobprog tokenizer, no idea how it compares to CoolMud's scripting language.


COOL is a cleaned up better version of MOO. I guess you might call it MOO 2.0 ColdC would be MOO 3.5 COOL is probably as functional as LPC, but without all the nice supporting library routines that LPMuds have built up over the years. I don't know how they'd compare to Lola.
02 Feb, 2010, David Haley wrote in the 22nd comment:
Votes: 0
Scandum said:
elanthis said:
And I hold her still. Because using a linked list for an AST is fucking stupid and makes performing any kind of useful semantic analysis or transformation of the AST a pain in the ass compared to just doing it right. But hey, what do I know, it's not like I work on compilers or anythi-oh wait a minute I do. :/

Amazing you have the insight to see that it can be done, this rates you slightly above Haley. Have fun holding her still!

It would be really nicer if you weren't making this personal all the time. I'm not sure that these directly personal insults are helpful or appropriate.

For the record, my original post said that it would be clunky and confusing but I didn't say it wouldn't "work". (I maintain that it would be rather silly to do so, but that's different.)
02 Feb, 2010, kiasyn wrote in the 23rd comment:
Votes: 0
Scandum said:
David Haley said:
JohnnyStarr said:
So a tree structure in C might just be a list

Please ignore the statement that linked lists work "just fine", you really don't want to go down that route.

I wonder what you do when I don't post for a week, beat your girlfriend?



Scandum said:
elanthis said:
And I hold her still. Because using a linked list for an AST is fucking stupid and makes performing any kind of useful semantic analysis or transformation of the AST a pain in the ass compared to just doing it right. But hey, what do I know, it's not like I work on compilers or anythi-oh wait a minute I do. :/

Amazing you have the insight to see that it can be done, this rates you slightly above Haley. Have fun holding her still!


You are in violation of the following rules:

Illegal content, and direct personal attacks are also not welcome within this forum.

Please cease your personal attacks against David Haley.

David and others: please desist from following this line of conversation, if you have any problems with this ruling start a thread under Moderator Actions
02 Feb, 2010, JohnnyStarr wrote in the 24th comment:
Votes: 0
Thanks all for the input. No doubt there is a new grail for me on the horizon, but I'm pretty young so there's always the next 10 years right? :cool:
I honestly didn't think I could learn as much as I have in the last year and a half, so who knows. @David, if you wouldn't mind uploading or sending
your Java example, I think that would help. I've thought about using Ruby to write my first run to get the ideas down. Yes I'm sure writing a scripting
language out of a scripting language almost defeats the point, but like I said this is just a learning experience. I want to get as much CS under my belt
before I start school here soon.
02 Feb, 2010, David Haley wrote in the 25th comment:
Votes: 0
JohnnyStarr said:
Yes I'm sure writing a scripting language out of a scripting language almost defeats the point

As you said, you are learning, so it most certainly does not defeat the point when the point is to learn. :smile: In fact, it lets you concentrate on your task (learning about languages, parsers etc.) and not be slowed down by your implementation language.

I will upload my code later today or tomorrow. Not sure if it's in a fully workable state, though… :wink:
02 Feb, 2010, Scandum wrote in the 26th comment:
Votes: 0
Tyche said:
I think you may be getting ahead to the final output, which could be a bytecode stream. In some simple languages, like assembler, nothing more than a simple transform is required. Most higher level languages, require more complex parsing and the intermediate representation of an AST is much more flexible and amenable to analysis of the code.

A syntax list with only the nesting level is indeed cumbersome when trying to implement looping. Would be interesting to see some examples of AST generators.

Scandum said:
COOL is a cleaned up better version of MOO. I guess you might call it MOO 2.0 ColdC would be MOO 3.5 COOL is probably as functional as LPC, but without all the nice supporting library routines that LPMuds have built up over the years. I don't know how they'd compare to Lola.

A lot better as Lola only does the mobprog syntax, a better job could be done, but then again, I don't see anyone else doing it.

I'll have to take a look at ColdC sometime.
02 Feb, 2010, David Haley wrote in the 27th comment:
Votes: 0
Basically you would be using a graph, not a linked list, to represent basic block structures, even in bytecode streams, really. The bytecode is not linear, after all. Loops exemplify this non-linearity.

ASTs are naturally generated by the parsing process; yacc/bison/etc. are full of examples. The Java code I have lying around also generates an AST; it happens to also be the tree that is walked at runtime. (I don't do any optimization whatsoever.)

Tyche, is this "COOL" you speak of at all related to the "Classroom Object Oriented Language"? I'm guessing not, but one never knows, do one…
02 Feb, 2010, elanthis wrote in the 28th comment:
Votes: 0
Quote
You've ventured into an area of programming that isn't just fun and games anymor


But… but… but languages and compilers and runtimes are the _most_ fun of all! :(
02 Feb, 2010, David Haley wrote in the 29th comment:
Votes: 0
OK, check out this link. (WARNING: This link might disappear at any notice, and probably will at some point as I clean things up.)
License: the only thing you can do with this is look at it. You cannot redistribute it or use it in your projects unless you get my explicit permission to do so. (I will come up with a better license once I clean it up. The restrictions are meant to keep this messy version temporary.)

Background: this was written in a few days for a larger group project for a class 2005. It was a simple game, kind of like a MUD, but with very simple 2d graphics. It was written in Java, however we added scripting.
I have not provided the rest of the code, in part because I'm not sure I really should be distributing code other people wrote. (This part is all me.)

This code uses flex/bison with some Java thingies to make it work in Java. I think it compiled to C, and then the program "jb" did some magic to make it work in Java. I don't really remember how that part worked and didn't spend time looking into it.

The lexer source is common/scripting/src/lexer.l
The parser source is common/scripting/src/parser.y

The main entry point to the compiler is common/scripting/Compiler.java
There are a few (trivial) examples in there.

The top-most node of a program is a list of event handlers. The scripting language is entered into by "triggering" an event. (So, when you parse a script, you get back an EventHandlers tree node, and to run a script, you 'trigger' the event. (Note that a function can also be considered an 'event', and can take and return parameters.)

The runtime environment is as simple as it possibly could be. It implements no garbage collection, although stuff is implicitly garbage-collected by the greater Java runtime environment.

To run this thing, you need to subclass a ScriptingRuntimeEnvironment (or something like that) which defines a list of built-in functions made available to all scripting environments.

Here is an example script:
// Called when a connection is made
on connection(conn)
{
conn.sendDialogOk("Welcome to BUNNY WORLD!");

local char = null;

while ( char == null )
{
local name = conn.promptText("Select your character name: ('quit' to cancel)");
//local name = "Fred";

if ( name == "quit" )
{
conn.sendText("server: Goodbye!");
conn.disconnect();
return;
}

char = LoadCharacter(name, conn);

// Success?
if ( char != null )
break;

// No: report failure and try again
conn.sendText("Sorry, you can't have the name '" + name + "'");
}

RegisterNewCharacter(conn, char);
}

// Called when ch is created
on create_character(ch, conn)
{
ch.setHp(100);
ch.setMaxHp(100);

//// Prompt the player for an avatar
//ch.setAvatar( conn.promptText("Pick an avatar:") );
// Default the character to a duck - they're sent to the avatar picking room
ch.setAvatar( "duck.gif" );

// OK, all done, woot woot
}

// Called when ch first spawns
on spawn_player(ch)
{
// Stick the character in the default starting room
local room = GetRoom("BunnyWorld/AvatarRoom");
ch.moveToRoom(room);
}


on takeoff(ch)
{
local planet = ch.promptPlanetId();
ch.moveToPlanet( GetPlanet(planet) );
}




Some disclaimers:
- I wrote this almost five years ago. I would do many things differently. I have taken several compilers courses since. While code feedback is always appreciated, please keep this in mind.
- Even when I wrote it, there was no thought of making a SuperAwesomeLanguage. It was a class project, a relatively small part of a much larger four-person project, and as such needed to be done under tight deadlines with lots of other stuff to do. So the language, while much nicer than e.g. mudprog (it actually supports function calls, full conditionals, loops, etc.) is nonetheless rather simple, and doesn't do a lot of the things you might expect of a 'proper' language. (It is impossible to create objects without using built-ins, for example.) It was also written in just a few days, and not looked at since.
- You will have to figure out how to compile/run this stuff yourself. I have not cleaned it up at all, and it won't compile. In fact, it's missing other classes (like the resource manager). You will probably need to acquire the 'jb' program/library as well. At some point, if I feel like it, I might clean it up into a nicer, fully packaged state.
03 Feb, 2010, Runter wrote in the 30th comment:
Votes: 0
JohnnyStarr said:
Yes I'm sure writing a scripting
language out of a scripting language almost defeats the point, but like I said this is just a learning experience.


What point do you think it would be defeating exactly? That point may be defeated regardless if it involves building a better mousetrap.

However, if your point is to have fun and learn–as already stated above–that's an extremely good place to venture.
03 Feb, 2010, David Haley wrote in the 31st comment:
Votes: 0
I'd completely forgotten about this thread on Nick Gammon's forums about an expression parser. IIRC, he uses a top-down parser so that will give you a complete example of parsing with a top-down parser. I don't think he builds an AST, though, because it's just an expression language without loops or other control flow. It does have simple variable handling, though.


EDIT: Johnny, would you mind if a mod renamed the the thread to something like "language design brainstorming"? It'll make it easier to search for, and to know what the thread is about from the thread list. (Not sure if it's too late for you to change the topic yourself)
03 Feb, 2010, Tyche wrote in the 32nd comment:
Votes: 0
Scandum said:
A syntax list with only the nesting level is indeed cumbersome when trying to implement looping. Would be interesting to see some examples of AST generators.


There's a simple example in TeensyMud. My FARTS language is very similar to MOBPROGS and is implemented usign a racc parser (i.e. yacc in ruby) that creates an AST. Interpretive execution is done directly from the AST. Obviously, compiling and executing on the fly every time a trigger is called isn't ideal. It was just a quick and dirty exercise of racc.
20.0/32