perm filename EPAR3C.2[EAL,HE]1 blob
sn#674805 filedate 1982-09-27 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00005 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 {$NOMAIN Editor: Aux parsing routines }
C00023 00003 { Externally defined routines from elsewhere: }
C00027 00004 (* aux routines: declarationp, getEDeclarations *)
C00044 00005 (* eVarParse & eProcParse *)
C00059 ENDMK
C⊗;
{$NOMAIN Editor: Aux parsing routines }
const
(* Constants from EDIT *)
maxLines = 28; (* smaller on the 11 than on the 10 *)
maxPPLines = 18;
maxBpts = 25;
maxTBpts = 20; (* max could be exceeded by huge case stmnt *)
listinglength = 2000; (* Length of Listingarray *)
(* Random type declarations for OMSI/SAIL compatibility *)
type
byte = 0..255; (* doesn't really belong here, but... *)
ascii = char;
atext = text;
{ Define all the pointer types here }
strngp = ↑strng;
statementp = ↑statement;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
tokenp = ↑token;
reswordp = ↑resword;
linerecp = ↑linerec;
cursorpp = ↑cursorp; {Ron's style, not mine}
(* This one is used whenever a pointer is needed for which the *)
(* definition is missing from this file; naturally, all *)
(* pointers use the same space *)
dump = ↑integer;
(* datatype definitions *)
datatypes = (pconstype, varitype, svaltype, vectype, rottype, transtype,
frametype, eventtype, strngtype, labeltype, proctype, arraytype,
reftype, valtype, cmontype, nulltype, undeftype,
dimensiontype, mactype, macargtype, freevartype);
scalar = real;
cstring = packed array [1..10] of ascii;
c4str = packed array [1..4] of ascii;
c5str = packed array [1..5] of ascii;
c20str = packed array [1..20] of ascii;
linestr = packed array [1..130] of ascii;
strng = record
next: strngp;
ch: cstring;
end;
(* statement definitions *)
stmntypes = (progtype, blocktype, coblocktype, endtype, coendtype,
fortype, iftype, whiletype, untiltype, casetype,
calltype, returntype,
printtype, prompttype, pausetype, aborttype, assigntype,
signaltype, waittype, enabletype, disabletype, cmtype,
affixtype, unfixtype,
movetype, operatetype, opentype, closetype, centertype,
stoptype, retrytype,
requiretype, definetype, macrotype, commenttype, dimdeftype,
setbasetype, wristtype, tovaltype, declaretype, emptytype);
(* more??? *)
statement = packed record
next, last: statementp; (* ↑ to lexical tokens? *)
stlab: varidefp;
exprs: nodep; (* any expressions used by this statement *)
nlines: integer;
bpt: boolean;
case stype: stmntypes of
progtype: (pcode: statementp; errors: integer);
blocktype,
declaretype,
endtype,
coendtype: (bcode, bparent: statementp; blkid: identp;
level, numvars: 0..255; variables: varidefp);
coblocktype: (threads: nodep; nthreads: integer; cblkid: identp);
fortype: (forvar, initial, step, final: nodep; fbody: statementp);
whiletype,
untiltype: (cond: nodep; body: statementp);
casetype: (index: nodep; range, ncases: integer; caselist: nodep);
iftype: (icond: nodep; thn, els: statementp);
pausetype: (ptime: nodep);
prompttype,
printtype,
aborttype: (plist: nodep; debugLev: integer);
returntype: (retval, rproc: nodep);
calltype,
assigntype: (what, aval: nodep);
affixtype,
unfixtype: (frame1, frame2, byvar, atexp: nodep; rigid: boolean);
signaltype,
waittype: (event: nodep);
movetype,
operatetype,
opentype,
closetype,
centertype,
stoptype: (cf, clauses: nodep);
retrytype: (rcode, rparent: statementp; olevel: integer);
cmtype: (oncond: nodep; conclusion: statementp;
deferCm, exprCm: boolean; cdef: varidefp);
enabletype,
disabletype: (cmonlab: varidefp);
requiretype: (rfil: boolean; rfils: strngp; rfilen: integer);
definetype: (macname,mpars: varidefp; macdef: tokenp);
commenttype: (len: integer; str: strngp; cbody: statementp);
dimdeftype: (dimname: varidefp; dimexpr: nodep);
setbasetype,
wristtype: (fvec, tvec: nodep);
tovaltype: (vstr: strngp; vlen: integer; waitp: boolean);
end;
(* auxiliary definitions: variable, etc. *)
varidef = packed record
next,dnext: varidefp;
name: identp;
level: 0..255; (* environment level *)
offset: 0..255; (* environment offset *)
dtype: varidefp; (* to hold the dimension info *)
tbits: 0..15; (* special type bits: array = 1, proc = 2, ref = 4 & ? *)
dbits: 0..15; (* for use by debugger/interpreter *)
case vtype: datatypes of
arraytype: (a: nodep);
proctype: (p: nodep);
labeltype,
cmontype: (s: statementp);
mactype: (mdef: statementp);
macargtype: (marg: tokenp);
pconstype: (c: nodep);
dimensiontype: (dim: nodep);
end;
(* definition of the ubiquitous NODE record *)
nodetypes = (exprnode, leafnode, listnode, clistnode, colistnode, forvalnode,
deprnode, viaptnode, apprnode, destnode, durnode,
sfacnode, wobblenode, swtnode, nullingnode, wristnode, cwnode,
arrivalnode, departingnode,
ffnode, forcenode, stiffnode, gathernode, cmonnode, errornode,
calcnode, arraydefnode, bnddefnode, bndvalnode,
waitlistnode, procdefnode, tlistnode, dimnode, commentnode);
exprtypes = ( svalop, (* scalar operators *)
sltop, sleop, seqop, sgeop, sgtop, sneop, (* relations *)
notop, orop, xorop, andop, eqvop, (* logical *)
saddop, ssubop, smulop, sdivop, snegop, sabsop, (* scalar ops *)
sexpop, maxop, minop, intop, idivop, modop,
sqrtop, logop, expop, timeop, (* functions *)
sinop, cosop, tanop, asinop, acosop, atan2op, (* trig *)
vdotop, vmagnop, tmagnop,
vecop, (* vector operators *)
vmakeop, unitvop, vaddop, vsubop, crossvop, vnegop,
svmulop, vsmulop, vsdivop, tvmulop, wrtop,
tposop, taxisop,
transop, (* trans operators *)
tmakeop, torientop, ttmulop, tvaddop, tvsubop, tinvrtop,
vsaxwrop, constrop, ftofop, deproachop, fmakeop, vmkfrcop,
ioop, (* i/o operators *)
queryop, inscalarop,
specop, (* special operators *)
arefop, callop, grinchop, macroop, vmop, adcop, dacop,
badop,
addop, subop, negop, mulop, divop, absop); (* for parsing *)
leaftypes = pconstype..strngtype;
reltypes = sltop..sgtop;
forcetypes = (force,absforce,torque,abstorque,angvelocity);
node = record
next: nodep;
case ntype: nodetypes of
exprnode: (op: exprtypes; arg1, arg2, arg3: nodep; elength: integer);
leafnode: (case ltype: leaftypes of
varitype: (vari: varidefp; vid: identp);
pconstype: (cname: varidefp; pcval: nodep);
svaltype: (s: scalar; wid: integer);
vectype: (v: dump);
transtype: (t: dump);
strngtype: (length: integer; str: strngp) ); (* also used by commentnodes *)
deprnode,
apprnode,
destnode: (loc: nodep; code: statementp);
arrivalnode:(evar: varidefp);
viaptnode: (vlist: boolean; via,duration,velocity: nodep; vcode: statementp);
durnode: (durrel: reltypes; durval: nodep);
swtnode: (clval: nodep);
ffnode: (ff: nodep; csys, pdef: boolean); (* true = world, false = hand *)
gathernode: (gbits: integer);
cwnode: (notp: boolean); (* true = nonulling/zero wrist/counter_clockwise *)
forcenode: (ftype: forcetypes; frel: reltypes; fval, fvec, fframe: nodep);
stiffnode: (fv, mv, coc: nodep);
listnode: (lval: nodep);
clistnode: (cval: integer; stmnt: statementp; clast: nodep);
colistnode: (prev: nodep; cstmnt: statementp);
forvalnode: (fvar: dump; fstep: scalar);
cmonnode: (cmon: statementp; errhandlerp: boolean);
errornode: (eexpr: nodep);
arraydefnode: (numdims: 1..10; bounds: nodep; combnds: boolean);
bnddefnode: (lower, upper: nodep);
bndvalnode: (lb, ub, mult: integer);
procdefnode:(ptype: datatypes; level: 0..255;
pname, paramlist: varidefp; body: statementp);
end;
(* records for parser: ident, token, resword *)
ident = record
next: identp;
length: integer;
name: strngp;
predefined: varidefp;
end;
tokentypes = (reswdtype, identtype, constype, comnttype, delimtype, labeldeftype,
macpartype);
constypes = svaltype..strngtype;
reswdtypes = (stmnttype, filtype, clsetype, decltype, optype, edittype);
filtypes = (abouttype,alongtype,attype,bytype,defertype,dotype,elsetype,
errmodestype,fromtype,handtype,intype,nonrigidlytype,rigidlytype,
sourcefiletype,steptype,thentype,totype,untltype,viatype,
withtype,worldtype,zeroedtype,oftype,wheretype,nowaittype,
ontype,offtype,ppsizetype,collecttype,alltype,lextype);
clsetypes = (approachtype,arrivaltype,departuretype,departingtype,durationtype,
errortype,forcetype,forceframetype,forcewristtype,gathertype,
nildeproachtype,nonullingtype,nullingtype,stiffnesstype,
torquetype,velocitytype,wobbletype,
cwtype,ccwtype,stopwaittimetype,angularvelocitytype,
fxtype,fytype,fztype,mxtype,mytype,mztype,
t1type,t2type,t3type,t4type,t5type,t6type,tbltype);
edittypes = (getcmd,savecmd,insertcmd,renamecmd,startcmd,gocmd,proceedcmd,
stepcmd,sstepcmd,nstepcmd,gstepcmd,executecmd,setcmd,tracecmd,
breakcmd,unbreakcmd,tbreakcmd,definecmd,markcmd,unmarkcmd,
popcmd);
token = record
next: tokenp;
case ttype: tokentypes of
constype: (cons: nodep);
comnttype: (len: integer; str: strngp);
delimtype: (ch: ascii);
reswdtype: (case rtype: reswdtypes of
stmnttype: (stmnt: stmntypes);
filtype: (filler: filtypes);
clsetype: (clause: clsetypes);
decltype: (decl: datatypes);
optype: (op: exprtypes);
edittype: (ed: edittypes) );
identtype: (id: identp);
labeldeftype: (lab: varidefp);
macpartype: (mpar: varidefp);
end;
resword = record
next: reswordp;
length: integer;
name: strngp;
case rtype: reswdtypes of
stmnttype: (stmnt: stmntypes);
filtype: (filler: filtypes);
clsetype: (clause: clsetypes);
decltype: (decl: datatypes);
optype: (op: exprtypes);
edittype: (ed: edittypes);
end;
(* print related records: *)
cursorp = record
cline,ind: integer;
case stmntp: boolean of
true: (st: statementp);
false: (nd: nodep);
end;
linerec = record
next: linerecp;
start,length: integer
end;
listingarray = packed array [0..listinglength] of ascii;
(* Global variables *)
var
(* From ALMAIN *)
b:boolean;
ch:ascii;
ltime: real;
(* From PARSE *)
reswords: array [0..26] of reswordp;
idents: array [0..26] of identp;
macrostack: array [1..10] of tokenp;
curmacstack: array [1..10] of varidefp;
macrodepth: integer;
curchar, maxchar, curline: integer;
curBlock,newDeclarations: statementp;
curProc: varidefp;
pnode: nodep;
nodim, distancedim, timedim, angledim,
forcedim, torquedim, veldim, angveldim: varidefp;
fvstiffdim, mvstiffdim: nodep;
(* filedepth: integer;
curpage: integer;
sysVars,unVars: varidefp;
errcount: integer;
outerBlock: statementp;
curVariable: varidefp;
curMotion: statementp;
endOk,coendOk: integer;
moveLevel: integer;
curErrhandler, curCmon: statementp; *)
d1: array[1..13] of dump;
endOfLine, backup, expandmacros, flushcomments, dimCheck: boolean;
(* semiseen, shownline: boolean;
eofError: boolean;
inMove,inCoblock: boolean; *)
d2,d3,d4,d5,d6: boolean;
curtoken: token;
file1,file2,file3,file4,file5: atext;
line: linestr;
(* From INTERP *)
curInt, activeInts, readQueue, allPdbs: dump;
curEnv, sysEnv: dump;
clkQueue: nodep;
allEvents: dump;
STLevel: integer;
etime: integer;
curtime: integer;
stime: integer;
msg: dump;
inputp: integer;
debugLevel: integer;
tSingleThreadMode: boolean;
resched, running, escapeI, singleThreadMode: boolean;
msgp: boolean; (* flag set if any messages pending *)
inputReady: boolean;
inputLine: array [1..20] of ascii;
(* From EDIT *)
lines: array [1..maxLines] of linerecp;
ppLines: array [1..maxPPLines] of linerecp;
marks: array [1..20] of integer;
cursorStack: array [1..15] of cursorp;
bpts: array [1..maxBpts] of statementp;
tbpts: array [1..maxTBpts] of statementp;
debugPdbs: array [0..10] of dump;
screenheight,dispHeight: integer;
ppBufp,oppBufp,ppOffset,ppSize,nmarks: integer;
lbufp,cursor,ocur,cursorLine,fieldnum,lineNum,findLine,pcLine: integer;
firstDline,topDline,botDline,firstLine,lastLine: integer;
freeLines,oldLines: linerecp;
findStmnt: statementp;
nbpts,ntbpts: integer;
eCurInt: dump;
dProg: statementp;
smartTerminal: boolean;
setUp,setExpr,setCursor,dontPrint,outFilep,newVarOk,collect: boolean;
eBackup: boolean;
eSingleThreadMode: boolean;
listing: packed array [0..listinglength] of ascii;
lbuf: array [1..160] of ascii;
ppBuf: array [1..100] of ascii;
outFile: atext;
eCurToken: token;
(* Various device & variable pointers *)
speedfactor: dump;
barm: dump;
(* Various constant pointers *)
xhat,yhat,zhat,nilvect: dump;
niltrans: dump;
bpark, ypark, gpark, rpark: dump; (* arm park positions *)
{ Externally defined routines from elsewhere: }
(* From ALLOC *)
function newNode: nodep; external;
procedure relNode(n: nodep); external;
function newVaridef: varidefp; external;
procedure relVaridef(n: varidefp); external;
function newStatement: statementp; external;
procedure relStatement(n: statementp); external;
(* From EROOT: Inter-overlay calls *)
function e3cExprParse: nodep; external;
procedure e3cReParse(st: statementp); external;
(* From PAUX1 *)
function copyExpr(n: nodep; lcp: boolean): nodep; external;
procedure appendEnd(s,so: statementp); external;
(* From PAUX2 *)
function matchdim(d1,d2: nodep; exactp: boolean): boolean; external;
procedure relExpr(n: nodep); external;
(* From EAUX1A *)
function eVarLookup(id: identp): varidefp; external;
function eMakeVar(vartype: datatypes; vid: identp): varidefp; external;
(* From EPUT *)
procedure putChar(ch: ascii); external;
procedure putLine; external;
(* From EAUX2A *)
procedure flushVar(oldvar: varidefp); external;
procedure eMakeNewVar(newvar: varidefp); external;
(* From EAUX2C *)
procedure deleteLines(start,number,coff: integer); external;
procedure insertLines(start,number,coff: integer); external;
(* From EEXPED *)
function exprEditor(line,lstart,llength,estart: integer;
var elength: integer; off: integer): ascii; external;
(* From ETOKEN *)
procedure eGetToken; external;
procedure eGetDelim(char: ascii); external;
(* From EPUTST *)
procedure putstmnt(s: statementp; indent, plevel: integer); external;
(* From PP *)
procedure ppLine; external;
procedure ppOutNow; external;
procedure ppChar(ch: ascii); external;
procedure pp5(ch: c5str; length: integer); external;
procedure pp10(ch: cstring; length: integer); external;
procedure pp10L(ch: cstring; length: integer); external;
procedure pp20(ch: c20str; length: integer); external;
procedure pp20L(ch: c20str; length: integer); external;
procedure ppInt(i: integer); external;
procedure ppReal(r: real); external;
procedure ppStrng(length: integer; s: strngp); external;
procedure ppDtype(d: datatypes); external;
procedure ppDelChar; external;
procedure ePar3cGet; external;
procedure ePar3cGet; begin end;
(* aux routines: declarationp, getEDeclarations *)
function declarationp: boolean; external;
function declarationp;
var b: boolean; v: varidefp;
begin
b := false;
eGetToken;
with eCurToken do
if ttype = reswdtype then
begin
if rtype = decltype then b := true
else if (rtype = optype) and ((op = vmakeop) or (op = vsaxwrop) or
(op = tmakeop) or (op = fmakeop)) then
begin
b := true;
rtype := decltype;
if op = vmakeop then decl := vectype
else if op = vsaxwrop then decl := rottype
else if op = tmakeop then decl := transtype else decl := frametype;
end
else if ((rtype = clsetype) and
((clause = forcetype) or (clause = torquetype) or
(clause = angularvelocitytype) or (clause = velocitytype))) then
begin
b := true;
ttype := identtype;
if clause = forcetype then id := forcedim↑.name
else if clause = torquetype then id := torquedim↑.name
else if clause = velocitytype then id := veldim↑.name
else id := angveldim↑.name;
end
end
else if ttype = identtype then
begin
v := eVarLookup(id);
if v <> nil then b := v↑.vtype = dimensiontype else b := false;
end;
if not b then eBackup := true;
declarationp := b;
end;
function getEDeclarations(pdef: boolean; lev: integer;
var vo: varidefp; var numvars: integer): varidefp; external;
function getEDeclarations;
var vhdr,va,vp,vdim: varidefp; off,tb,i: integer; d: datatypes;
endlist,b: boolean; no,n: nodep; idname: identp;
begin
numvars := 0;
if vo = nil then off := 0 else off := vo↑.offset + 1;
vhdr := nil;
with eCurToken do
begin
flushcomments := true; (* don't allow comments here *)
b := true;
if pdef then
if (ttype = reswdtype) and (rtype = decltype) and
((decl = reftype) or (decl = valtype)) then
begin (* "reference" or "value" procedure args *)
if decl = valtype then tb := 0 else tb := 4;
b := declarationp; (* get dimension or base type *)
end
else tb := 4 (* pass by "reference" is the default *)
else tb := 0;
if (ttype = identtype) and b then
begin (* deal with dimension info *)
vdim := eVarLookup(id); (* save it for later *)
b := declarationp; (* get base datatype *)
end
else vdim := nil;
if (not b) or (ttype <> reswdtype) or (rtype <> decltype) or
(decl > arraytype) then
begin (* not a valid basic datatype *)
pp20L(' Need a basic dataty',20); pp10('pe here ',7); ppLine;
while (ttype <> delimtype) or (ch <> ';') do eGetToken; (* flush tokens *)
end
else
begin
if decl <> arraytype then d := decl
else
begin
d := undeftype; (* define it later *)
eBackup := true;
pp20L(' Need to specify bas',20); pp20('e type of array - wi',20);
pp20('ll try to define it ',20); pp5('later',5); ppLine;
end;
if d <> proctype then eGetToken; (* is this really an array or procedure? *)
if (ttype = reswdtype) and (rtype = decltype) and (decl = proctype) then
begin (* new procedure definition *)
eGetToken; (* get the procedure's name *)
if ttype <> identtype then
begin (* garbage *)
pp20L(' Expecting an identi',20); pp10('fier here ',9); ppLine;
eBackup := true;
idname := nil;
end
else idname := id;
vp := newVaridef;
if vhdr = nil then vhdr := vp;
if vo <> nil then vo↑.next := vp; (* add to list *)
vo := vp;
with vo↑ do
begin
next := nil;
dnext := nil;
name := idname;
level := lev;
offset := off;
off := off + 1;
numvars := numvars + 1;
tbits := 2;
if d = proctype then vtype := nulltype else vtype := d;
dtype := vdim;
n := newNode;
p := n;
end;
with n↑ do
begin
ntype := procdefnode;
ptype := vo↑.vtype;
level := lev + 1;
pname := vo;
paramlist := nil;
eGetToken; (* see if procedure has any parameters *)
if (ttype = delimtype) and (ch = '(') then (* yup - get 'em *)
begin
va := nil;
while declarationp do (* get parameters *)
begin
vdim := getEDeclarations(true,level,va,i);
if paramlist = nil then paramlist := vdim;
if (ttype = delimtype) and (ch = ';') then eBackup := false;
end;
va := paramlist;
while va <> nil do
with va↑ do begin dnext := next; va := next end;
flushcomments := true; (* don't allow comments again *)
eGetDelim(')'); (* look for closing ")" *)
eGetToken; (* get separating ";" *)
end;
body := newStatement; (* no body yet - make a Begin-End block *)
appendEnd(body,body);
with body↑ do
begin stype := blocktype; bparent := curBlock; blkid := nil; nlines := 2;
level := lev + 2; numvars := 0; bcode := next; variables := nil end;
insertLines(cursorLine+1,2,0); (* fix up display *)
curLine := cursorLine;
firstLine := curLine + 1;
lastLine := curLine + 2;
putStmnt(body,cursorStack[cursor].ind + 2,99);
putchar(';');
putLine; (* force last line to be written out *)
body↑.next := newStatement; (* append a return, just in case *)
with body↑.next↑ do
begin
stype := returntype;
retval := nil;
exprs := nil;
last := n↑.body;
rproc := n;
end;
end;
end
else
begin
if (ttype = reswdtype) and (rtype = decltype) and (decl = arraytype) then
begin
tb := tb + 1; (* we've got an array specification *)
va := nil; (* for list of arrays sharing common bounds list *)
if pdef and (tb = 1) then
begin
tb := 5;
pp20L('Can''t pass arrays by',20); pp20(' value - changing to',20);
pp10(' reference',10); ppLine;
end
end
else
begin
eBackup := true;
if pdef and (tb = 0) and (d = eventtype) then
begin
tb := 4;
pp20L('Can''t pass events by',20); pp20(' value - changing to',20);
pp10(' reference',10); ppLine;
end
end;
if vdim <> nil then (* check that dimension applies to base type *)
if (d = rottype) and not matchdim(vdim↑.dim,angledim↑.dim,true) then
begin
vdim := nil;
pp20L(' Rotations must be o',20); pp20('f dimension ANGLE ',17);
ppLine;
end
else if (d = frametype) and
not matchdim(vdim↑.dim,distancedim↑.dim,true) then
begin
vdim := nil;
pp20L(' Frames must be of d',20); pp20('imension DISTANCE ',17);
ppLine;
end;
repeat
endlist := true; (* assume this is last one *)
eGetToken; (* declare the new variables *)
if ttype <> identtype then
begin (* garbage *)
pp20L(' Expecting an identi',20); pp10('fier here ',9); ppLine;
eBackup := true;
end
else
begin
vp := newVaridef;
if vhdr = nil then vhdr := vp;
if vo <> nil then
with vo↑ do begin next := vp; dnext := vp end; (* add to list *)
vo := vp;
if id↑.predefined <> nil then
if id↑.predefined↑.vtype = pconstype then
begin
pp20L('Redefining predeclar',20); pp20('ed constant - not a ',20);
pp10('good idea ',9); ppLine;
end;
with vp↑ do
begin
next := nil;
dnext := nil;
name := id;
level := lev;
offset := off;
off := off + 1;
numvars := numvars + 1;
tbits := tb;
vtype := d;
dtype := vdim;
if d = labeltype then s := nil;
end;
if odd(tb) then
begin (* look for array bounds *)
eGetToken; (* looking for a "[" *)
if (ttype <> delimtype) or (ch <> '[') then
begin (* not yet *)
eBackup := true;
vp↑.a := nil; (* no bounds info yet *)
if va = nil then va := vp; (* so we can fill things in later *)
if (ttype = delimtype) and (ch = ';') then
begin (* we aren't going to get one *)
va := nil;
if not pdef then
begin
pp20L(' Expecting an array ',20); pp20('bounds list here ',16);
ppLine;
end
end
end
else
begin (* got one *)
vp↑.a := newNode;
vp↑.a↑.ntype := arraydefnode;
vp↑.a↑.combnds := false;
no := nil;
i := 0;
repeat
n := newNode;
i := i + 1;
with n↑ do
begin
ntype := bnddefnode;
next := nil;
lower := e3cExprParse; (* get lower bound definition *)
eGetDelim(':'); (* looking for separating ":" *)
upper := e3cExprParse; (* get upper bound definition *)
eGetToken; (* looking for final "]" or separating "," *)
if (ttype <> delimtype) or ((ch <> ',') and (ch <> ']')) then
begin
pp20L(' Expecting a "," or ',20); pp10('"]" here ',8); ppLine;
eBackup := true;
end;
if no = nil then vp↑.a↑.bounds := n else no↑.next := n;
no := n;
end
until ((ttype = delimtype) and ((ch = ']') or (ch = ';'))) or
(ttype = reswdtype);
vp↑.a↑.numdims := i;
while va <> nil do (* now we can fill things in *)
begin
va↑.a := copyexpr(vp↑.a,false); (* copy bounds info *)
va := va↑.next;
if va↑.next = nil then va := nil; (* we already got this one *)
end
end
end;
eGetToken; (* looking for "," or ";" or ")" *)
if ttype = delimtype then
begin
if ch = ',' then endlist := false (* more to get *)
else if pdef and (ch = ')') then eBackup := true
else if (ch <> ';') and (ch <> chr(15B)) then
begin
pp20L(' Expecting a "," or ',20); pp10('";" here ',8); ppLine;
end
end
else
begin
eBackup := true;
pp20L(' Inserting missing "',20);
if ttype = identtype then (* user defined dimension type? *)
begin
vp := eVarLookup(id);
if vp = nil then endlist := false
else if vp↑.vtype <> dimensiontype then endlist := false;
end;
if endlist then ppChar(';') else ppChar(',');
ppChar('"'); ppLine;
end
end
until endlist;
end
end;
flushcomments := false; (* comments are ok again *)
end;
eBackup := true;
getEDeclarations := vhdr;
end;
(* eVarParse & eProcParse *)
function eVarParse(st: statementp; indent,l: integer): ascii; external;
function eVarParse;
var b,reparsep: boolean; i,j,elen,onumvars: integer; ch: ascii;
v,vhdr,vp,vo: varidefp;
oldvars,newvars: array [1..40] of varidefp; (* 40 should be more than enough... *)
begin
v := st↑.variables;
onumvars := 0;
while v <> nil do
begin (* save pointers to old variable defs *)
onumvars := onumvars + 1;
oldvars[onumvars] := v;
v := v↑.dnext;
end;
(* *** might check if variable was previously undefined, but now is defined
& if so update line on screen with correct info *** *)
with lines[l]↑ do
begin (* edit it *)
elen := length - indent + 1;
if listing[start+length-1] = ';' then begin elen := elen - 1; b := true end
else b := false;
ch := exprEditor(l-firstDline+1,start,length,indent,elen,0);
end;
if b then maxChar := maxChar + 1;
if not declarationp then
begin
pp20L(' Need a declaration ',20); pp5('here ',4); ppLine;
end
else
begin
vhdr := getEDeclarations(false,curBlock↑.level,v,i);
st↑.numvars := i; (* remember # of variables *)
reparsep := false;
v := vhdr;
for i := 1 to st↑.numvars do
begin (* see if old or new variable *)
j := 0;
b := false;
repeat
j := j + 1;
if oldvars[j] <> nil then b := v↑.name = oldvars[j]↑.name;
until b or (j >= onumvars);
if b then
begin (* an old one *)
with oldvars[j]↑ do (* note any changes *)
begin
if dtype <> v↑.dtype then (* see if dimension has changed *)
begin dtype := v↑.dtype; reparsep := true end;
if vtype <> v↑.vtype then (* see if base type has changed *)
begin
vtype := v↑.vtype;
reparsep := true;
(* *** if active block need to change environment entry for variable *** *)
end;
if odd(tbits) then
if a↑.combnds then relNode(a) (* free up any old array bounds *)
else relExpr(a);
if tbits <> v↑.tbits then (* ditto for tbits *)
begin tbits := v↑.tbits; reparsep := true end;
if odd(tbits) then
begin
a := v↑.a; (* copy new array bounds *)
(* *** if active block need to re-evaluate array bounds
& maybe change array size *** *)
end
else if tbits = 2 then
begin (* need to do special stuff for procedure??? *)
p := v↑.p; (* *** deal with proc def ??? *** *)
(* *** if active block need to change environment entry for variable *** *)
end;
end;
newvars[i] := oldvars[j];
oldvars[j] := nil;
end
else
begin (* a new one *)
newvars[i] := eMakeVar(v↑.vtype,v↑.name);
with newvars[i]↑ do
begin (* copy relevant fields *)
dtype := v↑.dtype;
tbits := v↑.tbits;
if odd(tbits) then a := v↑.a (* copy array bounds *)
else if tbits = 2 then
begin (* need to do special stuff for procedure??? *)
p := v↑.p; (* *** deal with proc def ??? *** *)
p↑.pname := vp;
end;
end;
eMakeNewVar(newvars[i]); (* if active block need to make env entry for var *)
reparsep := true;
end;
vp := v↑.dnext;
relVaridef(v); (* all done with the duplicate varidef now *)
v := vp;
if i > 1 then newvars[i-1]↑.dnext := newvars[i];
end;
if st↑.numvars > 0 then
begin
newvars[st↑.numvars]↑.dnext := nil;
st↑.variables := newvars[1];
end
else
begin (* flush declaration *)
with st↑.last↑ do (* splice us out of list *)
if st↑.stype = blocktype then bcode := st↑.next
else next := st↑.next;
st↑.next↑.last := st↑.last;
cursorStack[cursor].st := st↑.next;
deleteLines(cursorLine,1,1);
relStatement(st);
end;
for i := 1 to onumvars do
if oldvars[i] <> nil then flushVar(oldvars[i]);
if reparsep then
begin (* need to reparse block *)
e3cReParse(curBlock);
end;
end;
eVarParse := ch;
end;
function eProcParse(n: nodep; indent,l: integer): ascii; external;
function eProcParse;
var b,reparsep: boolean; i,j,elen,numvars,onumvars,off: integer; ch: ascii;
v,vhdr,vp: varidefp; d: datatypes;
oldvars,newvars: array [1..40] of varidefp; (* 40 should be more than enough... *)
begin
v := n↑.paramlist;
onumvars := 0;
off := 0;
while v <> nil do
begin (* save pointers to old variable defs *)
onumvars := onumvars + 1;
oldvars[onumvars] := v;
if v↑.offset > off then off := v↑.offset; (* find offset for new vars *)
v := v↑.dnext;
end;
(* *** might check if procedure was previously undefined, but now is defined
& if so update line on screen with correct info *** *)
with lines[l]↑ do
begin (* edit it *)
elen := length - indent;
ch := exprEditor(l-firstDline+1,start,length,indent,elen,0);
end;
maxChar := maxChar + 1;
reparsep := false;
with eCurToken do
begin
flushcomments := true; (* don't allow comments here *)
b := declarationp; (* get the base type *)
if (ttype = identtype) and b then
begin (* deal with dimension info *)
v := eVarLookup(id); (* save it for later *)
b := declarationp; (* get base datatype *)
end
else v := nil;
if v <> n↑.pname↑.dtype then (* has the dimension changed? *)
begin n↑.pname↑.dtype := v; reparsep := true end;
if (not b) or (ttype <> reswdtype) or (rtype <> decltype) then
begin (* not a valid basic datatype *)
pp20L(' Need a basic dataty',20); pp10('pe here ',7); ppLine;
end
else
begin
if decl = proctype then d := nulltype else d := decl;
if d <> n↑.pname↑.vtype then (* same base type? *)
begin n↑.pname↑.vtype := d; reparsep := true end;
end;
if d <> nulltype then eGetToken; (* get procedure token *)
if (ttype <> reswdtype) or (rtype <> decltype) or (decl <> proctype) then
begin
pp20L(' Expecting "procedur',20); pp20('e" here - good luck!',20); ppLine;
eBackup := true; (* *** maybe should do something smart here??? *** *)
end;
eGetToken; (* get the procedure's name *)
if ttype <> identtype then
begin (* garbage *)
pp20L(' Expecting an identi',20); pp10('fier here ',9); ppLine;
eBackup := true;
end
else if n↑.pname↑.name <> id then
begin (* change the procedure's name *)
n↑.pname↑.name := id; (* *** for now change name & all references to it *** *)
reparsep := true;
end;
eGetToken; (* see if any parameters *)
numvars := 0;
n↑.paramlist := nil;
if (ttype = delimtype) and (ch = '(') then (* yup - get 'em *)
begin
v := nil;
j := n↑.pname↑.level + 1;
while declarationp do (* get parameters *)
begin
vhdr := getEDeclarations(true,j,v,i);
numvars := numvars + i; (* remember # of parameters *)
if n↑.paramlist = nil then n↑.paramlist := vhdr;
if (ttype = delimtype) and (ch = ';') then eBackup := false;
end;
flushcomments := true; (* don't allow comments again *)
eGetDelim(')'); (* look for closing ")" *)
end;
end;
v := n↑.paramlist;
for i := 1 to numvars do
begin (* see if old or new variable *)
j := 0;
b := false;
repeat
j := j + 1;
if oldvars[j] <> nil then b := v↑.name = oldvars[j]↑.name;
until b or (j >= onumvars);
if b then
begin (* an old one *)
with oldvars[j]↑ do (* note any changes *)
begin
if dtype <> v↑.dtype then (* see if dimension has changed *)
begin dtype := v↑.dtype; reparsep := true end;
if vtype <> v↑.vtype then (* see if base type has changed *)
begin
vtype := v↑.vtype;
reparsep := true;
(* *** if active procedure need to change environment entry for variable *** *)
end;
if odd(tbits) then relExpr(a); (* free up any old array bounds *)
if tbits <> v↑.tbits then (* ditto for tbits *)
begin tbits := v↑.tbits; reparsep := true end;
if odd(tbits) then
begin
a := v↑.a; (* copy new array bounds *)
end;
end;
newvars[i] := oldvars[j];
oldvars[j] := nil;
vp := v↑.next;
relVaridef(v); (* all done with the duplicate varidef now *)
v := vp;
end
else
begin (* a new one *)
newvars[i] := v;
off := off + 1;
v↑.offset := off;
(* *** if active procedure need to create environment entry for variable *** *)
reparsep := true;
v := v↑.next;
end;
if i > 1 then
with newvars[i-1]↑ do begin next := newvars[i]; dnext := next end;
end;
if numvars > 0 then
begin
newvars[numvars]↑.next := nil;
newvars[numvars]↑.dnext := nil;
n↑.paramlist := newvars[1];
(* if not active-now then *)
begin (* renumber variable offsets *)
for i := 1 to numvars - 1 do
with newvars[i]↑ do
begin
next := newvars[i+1];
offset := i-1;
end;
newvars[numvars]↑.next := nil;
end;
end
else n↑.paramlist := nil;
for i := 1 to onumvars do
if oldvars[i] <> nil then
with oldvars[i]↑ do
begin (* flush old unused variables *)
(* *** if active procedure flush its value *** *)
if odd(tbits) then relExpr(a); (* free up old array bounds list *)
relVaridef(oldvars[i]);
end;
if reparsep then
begin (* need to reparse procedure body *)
e3cReParse(n↑.body);
end;
eProcParse := ch;
end;