TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: STEVE LEGG
from: JAMSHID KHOSHRANGI
date: 1995-09-18 00:19:00
subject: Oops

Like a fool, I shot off at the mouth and said...
JK>I use it quite often, and will use it more in the future.  If you turn
JK>it on, it effectively turns the compiler into a one pass compiler,
JK>rather than a two pass compiler.  Try turning it on for a trivial
JK>program, and watch the "pass" meter during the compile.
I tried this myself and it still did two passes.  I was thinking of
another compiler when I wrote this.  In theory, the declarations COULD
make for a one pass compiler, since the first pass of a two pass
compiler very often determines what is called an Id Table or symbol
table.
That is why:
DEFINT A-Z
a = b + 1
c
SUB c ()
END SUB
a and b are understood to be variables of integer type, yet c is
"magically" understood to be a SUB.  In the above, the "c" on the line
by itself is known as a forward reference, and a single pass compiler
has no way of knowing what on earth that little c refers to.  In a
two-pass compiler (which PowerBASIC is...), the first pass comes across
the "c" and either ignores it altogether, or flags the line as needing
resolution (depending on how the designers implemented it).  Some
compilers might make a huge list of unresolved lines, for later
compilation.  Then, when the pass reaches SUB c ... etc., the compiler
says to itself "AHA! I know what C is now!"  Some compilers will then
immediatlely pop their stack of unresolved lines, whereas others will
simply add c to the symbol table and wait for the second pass.
During the second pass, that "c" -- being resolved to mean SUB c...
well, it gets called.
Turning declarations on forces us to do this:
DECLARE SUB c ()
Thus, on the very first pass, the compiler knows that if it encounters a
single "c" -- it is a SUB that takes no parameters.  That is why, I
suppose, I assumed that PowerBASIC would make only one pass with
declaration mode turned on.  I was wrong.
If you think about it, the strongly typed program that requires DIM's
and DECLARE's is much simpler to parse in one pass, whereas two pass
compilers are much more lenient and therefore... easier to write sloppy
programs in.  The declaration mode of PowerBASIC is a happy medium.  All
the power of a two pass compiler... with strong typing.
Jamshid
--- Maximus/2 2.01wb
---------------
* Origin: Sound Stage BBS - Live Via Satellite - (604)944-6476 (1:153/7070)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.