draves@endor.harvard.edu (Richard Draves) (07/27/86)
I don't believe a (reasonable) one-pass compiler for Modula-2
is possible.  The reason is that identifiers used in statements
may be declared anywhere in the containing scopes, above or below.
In particular, forward declarations are no longer necessary because
you can use a procedure before declaring it.  The problems this causes
for calling sequences can be overcome with difficulty.  However,
it does get worse.  Consider:
    MODULE test;
      TYPE
	type = INTEGER;
      PROCEDURE outer();
	PROCEDURE inner();
	  VAR
	    var: type;
	
	BEGIN
	  var := type(0)	(* this is incorrect!! *)
	END inner;
	TYPE
	  type = REAL;
	
      BEGIN
      END outer;
    BEGIN
    END test.
References to non-local variables also can't be trusted.
What I find particularly despicable about this "feature"
is that PROCEDURE inner looks perfectly correct if one
doesn't examine its surrounding context.  I think this
violates the spirit of static scoping in a big way.
Rich
	"a picture in the head is a gory murder in an art gallery"
					-- Stephen Kosslynpolish@lexington.columbia.edu (Nathaniel Polish) (07/28/86)
In fact the one pass modula-2 compiler is by Wirth himself. I read an early manuscript of a paper that he wrote on the compiler. He grew frustrated with slow compilers and just sat down and wrote a small clean compiler which is available from Springer. Besides, you can always (I think) make a single pass compiler given enough memory. Nat Polish@cs.columbia.edu