[M3devel] Modula-2 parsing

Rodney M. Bates rodney_bates at lcwb.coop
Tue Aug 4 20:30:47 CEST 2015


On 08/04/2015 02:36 AM, Jay K wrote:
> Procedure.m3:
>
> Do we need this?
> I know it isn't much, but remove it?
>

It looks to me like the comment "accepting" is misleading, since it produces
an error message.  My guess is that this is a specialized syntax error recovery
technique, designed to do a better job of continuing when this particular
error occurs, probably based on experience.  Modula-3 evolved from Modula-2+,
which evolved from Modula-2, and I'll bet there was a lot of code converted
from one language to another.  This would have been a common leftover from
that process.

I'd change the comment, but otherwise leave it.

>
>      ELSIF (cur.token = TK.tSEMI) THEN
>        t.body := NEW (Body, self := t);
>        ProcBody.Push (t.body);
>        (* try accepting the Modula-2 syntax *)
>        Error.ID (id, "expecting \'=\' before procedure body");
>        GetToken (); (* ; *)
>        t.syms  := Scope.PushNew (TRUE, id);
>        t.block := BlockStmt.Parse (FALSE);
>        t.fails := BlockStmt.ExtractFails (t.block);
>        t.end_origin := Scanner.offset;
>        final_id := MatchID ();
>        IF (final_id # id) THEN
>          Error.ID (id, "Initial name doesn\'t match final name");
>        END;
>        Scope.PopNew ();
>        ProcBody.Pop ();
>      ELSE
>
>
> It always errors?
>
> But I guess it errors and checks nicer than it might otherwise?
>
> Why am I looking here?
>
> Tangential:
>
> I'm looking for where/how to model counting TRYs per "procedure"
> and doing the alloca at the start of a "procedure".
>

Are you counting TRYs in the front end, or on the back side of the
cm3 IR?  If the former, try looking at the way "fails" is collected
from Decl.Parse, to BlockStmt.ExtractFails, to Procedure.ParseDecl,
to a field of Procedure.T.  But it has to come out of TryStmt.Parse,
to Stmt.Parse, to BlockStmt.Parse.  And you only need a count, not
a list?

If the latter, aren't you already doing two passes over the IR?

>
> "procedure"'s definition for my context is being worked on.
>   It appears to be three things:
>    1) Things called "PROCEDURE".
>    2) FINALLY blocks, sometimes
>    3) "Module main"
>
>   I was looking for what they have in common already,
>   and it looks like maybe "ProcBody.Push".
>
>   So I was looking all of them.
>
>   - Jay
>
>
>
>
> _______________________________________________
> M3devel mailing list
> M3devel at elegosoft.com
> https://mail.elegosoft.com/cgi-bin/mailman/listinfo/m3devel
>

-- 
Rodney Bates
rodney.m.bates at acm.org



More information about the M3devel mailing list