Re: Compiling forward references





"Robert" <no@xxxxxx> wrote in message
news:s69cd3pnb0j1b3dpqqht8thtl8osesjji7@xxxxxxxxxx
Does this look like a worst case?

01 a LIKE b.
01 b LIKE c.
01 c LIKE d.
...
01 y LIKE z.
01 z PIC X.

A simple-minded compiler would take 25 forward sequential scans to resolve
a. If the
compiler ran every other scan backwards, definitions would be resolved in
two passes, but
that's not a good solution either.

The right solution would put the names a, b, c ... z into a tree or hash
table, with a
link to definitions in the source program. Think of it as a dictionary, if
that helps.
Then the resolution is not done by multiple sequential passes of the whole
source code but
rather by high speed lookups.

Compilers already do that. When they compile MOVE a TO b, do you think
they find a and b
by sequentially reading through the source? Of course not.

Given that compilers already have a tool for rapidly finding names,
resolving meta
references can be done with recursive invocation of that tool. When a
needs the definition
of b, push the context, search for b, receive b's definition, pop context,
replace LIKE
phrase with definition.

If the stack overflows, you've got a circular reference.

I don't understand why such a simple problem is causing heartburn.

Neither do I. :-)

That means that either, there are people here who would rather have a
problem than a solution (it adds meaning to their lives, perhaps...:-)), or,
the rest of us simply don't understand the problem...

Pete.
--
"I used to write COBOL...now I can do anything."


.



Relevant Pages

  • Compiling forward references
    ... A simple-minded compiler would take 25 forward sequential scans to resolve a. ... of b, push the context, search for b, receive b's definition, pop context, replace LIKE ... you've got a circular reference. ...
    (comp.lang.cobol)
  • Re: Why cant overloads take into account the return type.
    ... The compiler is going to need to know the return type anyway. ... instant complexity at the base level of the ... > impossible to resolve scenarios. ... > return type overloading, IMHO, requires a mechanism to manually select the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Why cant overloads take into account the return type.
    ... > The compiler is going to need to know the return type anyway. ... its utility verse complexity. ... type overloading provides minimal utliity with significant complexity. ... > I'm sure it can get complex but in any case it can't resolve the call it ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ?PAIRS
    ... Control Structures with Compiler Security" by Marc Perkel. ... RESOLVE Resolves forward branch and leaves a gap. ... on the stack was indeed left by>MARK. ... they figure the zero could have been left by>MARK. ...
    (comp.lang.forth)
  • Integrated theorem prover in compiler
    ... interested in this topic might be interested in RESOLVE. ... www.cs.clemson.edu/~resolve for a current version of RESOLVE verifier ... checked by the compiler, ... exception is thrown if any assertion is violated, ...
    (comp.compilers)