help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Two-pass parser or AST with Bison?


From: Matthias Kramm
Subject: Two-pass parser or AST with Bison?
Date: Tue, 6 Jan 2009 09:01:38 +0100
User-agent: Mutt/1.5.6i

Hi All,

I'm still busy compiling ActionScript 3.0, which, among
others, supports forward function calls:

    function bar() {
        foo("", 3)
    }
    function foo(s:String, i:int) {
    }

In order to properly resolve these (and check for correct
arguments), I can currently think about three options:
(1) Build an AST, walk that AST two times
(2) Do two LALR passes (i.e. store the flex tokens in memory,
    and run bison over them twice)
(3) back-patch (which I don't want to do)

I guess that (2) will use up less memory than (1), and also 
will be easier to implement.

Still, what are the best practices for AST building or two-pass
compile, if I 

(1) (for the AST:)
    Don't want to spell out every single AST node class explicitly, but 
    rather, if possible, derive these from the grammar?

(2) (for two-pass:)
    Don't want to surround every single rule with an if like this:
    E = E '+' E {
        if(global.pass==1) {
            // do nothing in first pass
        } else {
            code_append(OP_ADD);
        }
    }

Any pointers to best-practices, existing mailing-list threads etc. are
very welcome.

Thanks,

Matthias






reply via email to

[Prev in Thread] Current Thread [Next in Thread]