Re: Compiling forward references
- From: "Rick Smith" <ricksmith@xxxxxxx>
- Date: Thu, 30 Aug 2007 00:54:18 -0400
"Robert" <no@xxxxxx> wrote in message
news:s69cd3pnb0j1b3dpqqht8thtl8osesjji7@xxxxxxxxxx
Does this look like a worst case?
Not to me!
01 a LIKE b.
01 b LIKE c.
01 c LIKE d.
...
01 y LIKE z.
01 z PIC X.
The LIKE attribute is PL/I, COBOL uses the
SAME AS clause and does so similarly. <g>
A simple-minded compiler would take 25 forward sequential scans to resolvea. If the
compiler ran every other scan backwards, definitions would be resolved intwo passes, but
that's not a good solution either.table, with a
The right solution would put the names a, b, c ... z into a tree or hash
link to definitions in the source program. Think of it as a dictionary, ifthat helps.
Then the resolution is not done by multiple sequential passes of the wholesource code but
rather by high speed lookups.they find a and b
Compilers already do that. When they compile MOVE a TO b, do you think
by sequentially reading through the source? Of course not.resolving meta
Given that compilers already have a tool for rapidly finding names,
references can be done with recursive invocation of that tool. When aneeds 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.
Indirect forward references require two scans of the
data division; one to build a table of definitions and
one to process the text. Both scans have a number of
similarities; thus, substantial duplication. Furthermore,
the first scan must operate reasonably well in the
presence of syntax errors because syntax processing
is done in the second scan. [The second scan handles
substitutions and the syntax must be correct after the
substitution.]
Indirect backward references require only one scan
without any duplication and all saved definitions will
have been checked for syntax errors before substitution.
That, I think is a reasonable start toward discussing
the problem. But the problem, as I see it, does not
include how to accomplish the scans, look-ups, or
substitutions.
Does that help?
.
- References:
- Compiling forward references
- From: Robert
- Compiling forward references
- Prev by Date: Re: CONSTANT ENTRY (was "forward" references (was: COBOL subscript range checking))
- Next by Date: Re: SAME AS ('02 Standard) Clause - and circulatiy
- Previous by thread: Re: Compiling forward references
- Index(es):
Relevant Pages
|