I'm currently investigating the AST (abstract syntax tree) interface for Parrot. For getting a feeling, how this could look like, I've implemented (some parts) of Yet Another Language (YAL).

The dump below is a visual representation of the AST. The -o (optimize) option does some constant folding and optimizes e.g. C<if> and C<while> for constants.

The question is, if and where I should commit it. Its currently totally standalone, so I can tar and send it per PM too.

Comments welcome,
leo

Some examples:

$ cat a.i
int main()
{
    double x = 4.1 + 2;
    print x + 10;
    if (2 + 1 == 2 + 100) {
        print x;
    }
}

$ ./pir  -o <a.i
.pcc_sub _main prototyped
        .sym float x
        x = 6.1
        add $N1, x, 10
        print $N1
        end
.end

$ ./pir -d -o <a.i

(sub
    (decl
        (const I)
        (id main))
    (block
        (seq
            (seq
                (=
                    (decl
                        (const N)
                        (id x))
                    (const 6.1))
                (print
                    (add
                        (id x)
                        (const 10))))
            (noop))))

$ cat b.i
int main()
{
    var x;
    print x + 10;
}

$ ./pir -o <b.i
.pcc_sub _main prototyped
        new_pad 0
        .sym PerlUndef x
        x = new PerlUndef
        store_lex -1, "x", x
        $P1 = new PerlUndef
        add $P1, x, 10
        print $P1
        pop_pad
        end
.end



Reply via email to