Hotel at day 2 - A nice start?
I guess yesterday was pretty productive, I put in about seven hours or so. And I also read up on some other languages, and investigated parrot for a bit.
I am at a junction though; the code base is growing, is just around a 1000 lines of c now. But I have been writing a parser and evaluator in one. That means that as parser goes over a part of a program it executes it, but what about the false part of a if/else statement? and what about function calls? Time for an AST? I am not sure yet.
My first goal is just to build this thing the fastest way I can. Performance is the lowest priority right now. So I guess what I will do instead, is allow parsing without executing, and calling into scopes will just re-parse and execute the text that defines it.
However, the evaluator should then implement four kinds of parsing: parse and execute, parse only, parse and fill in declarations (new scopes), and parse and evaluate, but skip declarations. Or not ... actually I think I can get away with not doing the last two. But again, some AST intermediate form looks attractive.
Brighter side
What does work is the current scope, I can define as many variables as I like and assign them to each other. Also a simple if statement works, but only if its condition evaluates to true, and there are no operations yet. So it is not terribly exiting.
var x = 10
var y = "foo"
y = x
if (true) print(y) // -> 10
print(x, y, "bar", print) // -> 10, 10, "bar", scope
var newprint = print
newprint(x) // -> 10
I haven't tested that newprint part yet, I thought that up as I type this, but it should work. print is something implemented in c, and it resides as a value in the global scope, that value points the the print scope, which is actually marked as native, so calling it will fill in its arguments list, but then relinquish control to the native function it points to. That function will have to investigate its arguments and execute whatever it wants.
So I do actually have scopes, and I can call them, just the parser cannot produce them yet. This will be my very next goal.
Also the lexer is pretty complete, it cannot handle empty strings or large integers and throws away the fraction part of numbers. It cannot deal with ambiguities like '/' for devision and '/' as start of regex. Also no comments yet. Still, a good start here.
Closing
So the weekend is over, the hotel did grow faster then I thought it would, but I am disappointed I couldn't get parsing scopes to work yet. I know there is still a huge amount of work to do if I ever want it to be as nice as I hope ... I still hope hotel isn't stillborn.
Of-course, that is part of why I am blogging about it as I go: to keep a bit of peer pressure for me to continue working on it.
Unfortunately I know the next two weeks I have little time, except for maybe some evenings ...
Last modified: 2007-11-19 20:18 GMT