home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 1
/
GoldFishApril1994_CD1.img
/
d1xx
/
d183
/
pcq
/
source
/
initialize.p
< prev
next >
Wrap
Text File
|
1989-02-25
|
6KB
|
250 lines
external;
{
Initialize.p (of PCQ Pascal)
Copyright (c) 1989 Patrick Quaid.
This routine initializes all the global variables and
enters the standard identifiers.
}
const
{$I "pasconst.i"}
type
{$I "pastype.i"}
var
{$I "pasvar.i"}
function addtype(a, b, c, d, e, f : integer): integer;
forward;
procedure enterspell(s : string);
forward;
function enterstandard(a, b, c, d, e, f, g : integer): integer;
forward;
function AllocString(l : integer): string;
forward;
procedure initstandard;
{
This is a huge routine, but since it's so straightforward I
don't think I'll split it up. It just enters all the standard
identifiers into the identifier table. Note that 'nil' is
considered a standard identifier.
}
var
dummy : integer;
niltype : integer;
spellint : integer;
begin
spellint := integer(adr(spelling)) - 1;
badtype := addtype(vordinal, 0, 0, 0, 4, 0);
idents[badtype].name := string(spellint + spellptr);
enterspell(" ");
inttype := addtype(vordinal, 0, 0, 0, 4, 0);
idents[inttype].name := string(spellint + spellptr);
enterspell("Integer");
shorttype := addtype(vordinal, 0, 0, 0, 2, 0);
idents[shorttype].name := string(spellint + spellptr);
enterspell("Short");
booltype := addtype(vordinal, 0, 0, 0, 1, 0);
idents[booltype].name := string(spellint + spellptr);
enterspell("Boolean");
chartype := addtype(vordinal, 0, 0, 0, 1, 0);
idents[chartype].name := string(spellint + spellptr);
enterspell("Char");
texttype := addtype(vfile, chartype, 0, 0, 18, 0);
idents[texttype].name := string(spellint + spellptr);
enterspell("Text");
stringtype := addtype(vpointer, chartype, 0, 0, 4, 0);
idents[stringtype].name := string(spellint + spellptr);
enterspell("String");
realtype := addtype(vreal, 0, 0, 0, 4, 0);
idents[realtype].name := string(spellint + spellptr);
enterspell("Real");
bytetype := addtype(vordinal, 0, 0, 0, 1, 0);
idents[bytetype].name := string(spellint + spellptr);
enterspell("Byte");
literaltype := addtype(varray, chartype, 1, 1, 1, inttype);
dummy := enterstandard(stanproc, 1, 0, 0, 0, 0, 0);
enterspell("Write");
dummy := enterstandard(stanproc, 2, 0, 0, 0, 0, 0);
enterspell("Writeln");
dummy := enterstandard(stanproc, 3, 0, 0, 0, 0, 0);
enterspell("Read");
dummy := enterstandard(stanproc, 4, 0, 0, 0, 0, 0);
enterspell("Readln");
dummy := enterstandard(stanproc, 5, 0, 0, 0, 0, 0);
enterspell("New");
dummy := enterstandard(stanproc, 6, 0, 0, 0, 0, 0);
enterspell("Dispose");
dummy := enterstandard(stanproc, 7, 0, 0, 0, 0, 0);
enterspell("Close");
dummy := enterstandard(stanproc, 8, 0, 0, 0, 0, 0);
enterspell("Get");
dummy := enterstandard(stanproc, 9, 0, 0, 0, 0, 0);
enterspell("Exit");
dummy := enterstandard(stanproc, 10, 0, 0, 0, 0, 0);
enterspell("Trap");
dummy := enterstandard(stanfunc, 1, inttype, 0, 0, 0, 0);
enterspell("Ord");
dummy := enterstandard(stanfunc, 2, chartype, 0, 0, 0, 0);
enterspell("Chr");
dummy := enterstandard(stanfunc, 3, booltype, 0, 0, 0, 0);
enterspell("Odd");
dummy := enterstandard(stanfunc, 4, inttype, 0, 0, 0, 0);
enterspell("Abs");
dummy := enterstandard(stanfunc, 5, inttype, 0, 0, 0, 0);
enterspell("Succ");
dummy := enterstandard(stanfunc, 6, inttype, 0, 0, 0, 0);
enterspell("Pred");
dummy := enterstandard(stanfunc, 7, booltype, 0, 0, 0, 0);
enterspell("Reopen");
dummy := enterstandard(stanfunc, 8, booltype, 0, 0, 0, 0);
enterspell("Open");
dummy := enterstandard(stanfunc, 9, booltype, 0, 0, 0, 0);
enterspell("Eof");
dummy := enterstandard(constant, -1, booltype, 0, 0, 0, 0);
enterspell("True");
dummy := enterstandard(constant, 0, booltype, 0, 0, 0, 0);
enterspell("False");
dummy := enterstandard(constant, $7FFFFFFF, inttype, 0, 0, 0, 0);
enterspell("MaxInt");
dummy := enterstandard(constant, $7FFF, shorttype, 0, 0, 0, 0);
enterspell("MaxShort");
niltype := addtype(vpointer, badtype, 0, 0, 4, 0);
idents[niltype].name := string(spellint + spellptr);
enterspell("Address");
dummy := enterstandard(constant, 0, niltype, 0, 0, 0, 0);
enterspell("Nil");
dummy := enterstandard(stanfunc, 10, niltype, 0, 0, 0, 0);
enterspell("Adr");
dummy := addtype(varray, chartype, 128, 1, 128, inttype);
dummy := enterstandard(global, 0, dummy, 0, 0, 0, 0);
enterspell("CommandLine");
end;
procedure initreserved();
{
This initializes the array of reserved words. If you mess
around with this, be advised that the symbol numbers defined in
pasconst.i correspond with the indices of these words. Look at
searchreserved in utilities.p to explain the previous sentence.
}
begin
reserved[1] := "AND";
reserved[2] := "ARRAY";
reserved[3] := "BEGIN";
reserved[4] := "BY";
reserved[5] := "CASE";
reserved[6] := "CONST";
reserved[7] := "DIV";
reserved[8] := "DO";
reserved[9] := "DOWNTO";
reserved[10] := "ELSE";
reserved[11] := "END";
reserved[12] := "EXTERNAL";
reserved[13] := "FILE";
reserved[14] := "FOR";
reserved[15] := "FORWARD";
reserved[16] := "FUNCTION";
reserved[17] := "GOTO";
reserved[18] := "IF";
reserved[19] := "IN";
reserved[20] := "LABEL";
reserved[21] := "MOD";
reserved[22] := "NOT";
reserved[23] := "OF";
reserved[24] := "OR";
reserved[25] := "PACKED";
reserved[26] := "PRIVATE";
reserved[27] := "PROCEDURE";
reserved[28] := "PROGRAM";
reserved[29] := "RECORD";
reserved[30] := "REPEAT";
reserved[31] := "RETURN";
reserved[32] := "SET";
reserved[33] := "THEN";
reserved[34] := "TO";
reserved[35] := "TYPE";
reserved[36] := "UNTIL";
reserved[37] := "VAR";
reserved[38] := "WHILE";
reserved[39] := "WITH";
end;
Procedure initglobals;
{
This just puts the startup values into the variables.
}
begin
litlab := 1;
symtext := allocstring(80);
includename := allocstring(80);
eqstart := 0;
eqend := 0;
errorptr := 0;
including := false;
identptr := 1;
spelling[0] := chr(0);
spellptr := 1;
litptr := 1;
errorcount := 0;
lineno := 1;
currsym := 0;
symloc := 0;
currfn := 0;
nxtlab := 1;
rangecheck := false;
end;