Who of us are programmers and what are you working right now?

Varine

And as the moon rises, we shall prepare for war
Reaction score
805
My programs clearly portray my frustration when you go through the source. Especially in the comments once I get too drunk to keep programming.
 

camelCase

The Case of the Mysterious Camel.
Reaction score
362
I've never tried coding while drunk =/ Does it help you solve problems more creatively? =P
 

camelCase

The Case of the Mysterious Camel.
Reaction score
362
Tadah!
First boss of the game.

Edit:
Also, s3rius. I took the time to actually read the thing, play with the example, run it through the debugger and follow it through its execution but I only understood the tokenizer =/

The whole parser thing is alien to me; I half want to blame the horrible naming conventions =P I probably don't get it because I've never learned anything compiler related before =/

Edit:
Okay, I just made another attempt and decided to only implement a very small portion of the parser and I managed to get "4+4+pi*2;" working. Yes, I know that the "proper" parser would fail this statement but I'm only implementing a small portion.

One thing I see repeating again and again is shown in this snippet:
Code:
var prefix = function (id, nud) {
    var s = symbol(id);
    s.nud = nud || function () {
        scope.reserve(this);
        this.first = expression(70);
        this.arity = "unary";
        return this;
    };
    return s;
}

The part I don't get is why [ljass]arity[/ljass] is set when fuction [ljass]nud[/ljass] is called. Why not set the variable when the instance is being instantiated?

Like, why not this?
Code:
var prefix = function (id, nud) {
    var s = symbol(id);
    s.nud = nud || function () {
        scope.reserve(this);
        this.first = expression(70);
        return this;
    };
    this.arity = "unary";
    return s;
}

Also, this being a unary operator, it has a left binding power of 70. However, this value isn't being passed to [ljass]this.lbp[/ljass] at all. Instead, it's being passed as a literal directly to the call to [ljass]expression()[/ljass].. I'm confused..

Edit:
Oh, I just got it an lbp isn't set because symbol() can potentially return an existing instance of a symbol with that id.. And this prefix doesn't want to override that..

Oh... And the arity is modified only when it is used specifically as a unary operator..

I understand now but it doesn't seem like a, I duno, like a good way to handle it..
 

s3rius

Linux is only free if your time is worthless.
Reaction score
130
Oh... And the arity is modified only when it is used specifically as a unary operator..

I understand now but it doesn't seem like a, I duno, like a good way to handle it..

Keep in mind that this is implementation detail. In my implementation I don't have an arity at all.
The key thing is the idea of assigning a nud/led/lbp to each token and parsing different precending levels.

My previous parser was a typical recursive descent parser, and - true to its name - it had to do a lot of recursion and backtracking to get more complex expression right.
This TDOP method on the other hand.. there's hardly any backtracking at all: if a term couldn't be resolved in its first pass, it's malformed.

That's really cool.
 

camelCase

The Case of the Mysterious Camel.
Reaction score
362
I actually spent a lot more time on it and I think I'm finally wrapping my head around it. Some where in the middle, I thought to myself, "Screw it, I'll try following using a strongly typed language".

And I've got progress ;)
You'll see some bugs in the screenshots, I've fixed those since. I just didn't feel like taking another screen shot =/
testRawTokenizer.png
Parser.png

Parser2.png


I've only implemented a small subset of the parser and the tokenizer and deviated from the example given but I think I get what I'm doing (finally). I'm probably getting all the terminology wrong and all, though =P

My take on it is that there are three things:
RawToken
Symbol
Token

A whole bunch of RawToken instances is created from the input code. The Symbol has a nullDenotator() and leftDenotator() method. They both return an instance of Token.

RawToken has the following variables and methods:
+ rawType (literal, name, operator, etc.)
+ value
+ start (I don't use the start variable)
+ end (I do use the end variable for forming the tokens)

Symbol has the following variables and methods:
+ id
+ value
+ leftBindingValue
+ nullDenotator()
+ leftDenotator()

Token has the following variables and methods:
+ arity
+ value
+ first (or left)
+ second (or right)
(Note that I haven't gotten to doing ternary operators yet..)

Now that you mention a lack of arity in your implementation, I can kinda' see why it's redundant.. I think.
Unary: second is null
Binary: first and second not null
Literal: first and second is null

Or am I missing the point? =x
 

s3rius

Linux is only free if your time is worthless.
Reaction score
130
Yea, that's pretty much all that arity is about.

Right now I'm using polymorphism:

Code:
class BinaryNode : public ASTNode{
    BinaryOp m_op;
    ASTNode *m_left, *m_right;
    ....
};
 
class UnaryNode : public ASTNode{
    UnaryOp m_op;
    ASTNode *m_node;
    ....
};
....

If you put all the node processing into the classes itself there's absolutely no need to have an arity variable.

Nice screenies by the way. I'm still using console and txt files :3

jfXeK44.png
 

Mahucharn

I wear a fez now, fezzes are cool.
Reaction score
173
I start Intro to Comp Sci-1 at my school in 2 weeks... that counts, right? Should be learning raquet as well. Oh also, I'm the webmaster's assistant for my school, so I just made a new archive system using HTML and PHP.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top