parse with Happy and add semantics/bindings

82 views Asked by At

Is there a way, whilst parsing source of a statically-scoped nested language such as Pascal (which allows nested subroutines), of maintaining binding information (list of name-value pairs as they are encountered in the source) ? The difficulty is that if there is an outer-level routine containing two nested sub-routines, the second-parsed sub-routine should 'inherit' the bindings established globally or within the outer-level routine, but not those of the first-parsed routine. Thus, it seems to me, you can't handle the problem with a monadic parser but that might be because I don't know how to use them well enough.

procedure outer;
    var somevar : integer;
    procedure inner1;
        var in1 : char;
    begin
        something;
    end;
    procedure inner2;
        var in2 : Boolean;
    begin
        something_else;  (* in1 is not visible here of course *)
    end;
begin
    inner1;
    inner2;
end;

Any ideas ? I hope I explained it sufficiently clearly.

0

There are 0 answers