perm filename POV1.2[EAL,HE] blob
sn#676475 filedate 1982-09-27 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00009 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 {$NOMAIN Auxilliary statement parsers }
C00025 00003 { Externally defined routines from elsewhere: }
C00028 00004 function assignParse(st: statementp): boolean external
C00034 00005 function ifParse(st: statementp): boolean external
C00037 00006 function forParse(st: statementp): boolean external
C00043 00007 function whileParse(st: statementp): boolean external
C00045 00008 function untilParse(st: statementp): boolean external
C00047 00009 function caseParse(st: statementp): boolean external
C00054 ENDMK
C⊗;
{$NOMAIN Auxilliary statement parsers }
const
(* Constants from EDIT; need these for the constants section *)
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 }
vectorp = ↑vector;
transp = ↑trans;
strngp = ↑strng;
eventp = ↑event;
framep = ↑frame;
statementp = ↑statement;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
tokenp = ↑token;
reswordp = ↑resword;
(* 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;
cursorp = array[1..4] of 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;
u = (used,free);
vector = record case u of
used: (refcnt: integer; val: array [1..3] of real);
free: (next: vectorp);
end;
trans = record case u of
used: (refcnt: integer; val: array [1..3,1..4] of real);
free: (next: transp);
end;
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;
event = record
next: eventp; (* all events are on one big list *)
count: integer;
waitlist: dump;
end;
frame = record
vari: varidefp; (* back pointer to variable name & info *)
calcs: nodep; (* affixment info *)
case ftype: boolean of (* frame = true, device = false *)
true: (valid: integer; val, fdepr: transp; dcntr: integer; dev: framep);
false: (mech: integer; case sdev: boolean of
true: (sdest: real); false: (tdest,appr,depr: transp));
(* sdev = true for scalar devices, false for frames *)
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);
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);
calltype,
assigntype: (what, aval: nodep);
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: vectorp);
transtype: (t: transp);
strngtype: (length: integer; str: strngp) ); (* also used by commentnodes *)
listnode: (lval: nodep);
clistnode: (cval: integer; stmnt: statementp; clast: nodep);
colistnode: (prev: nodep; cstmnt: statementp);
forvalnode: (fvar: dump; fstep: scalar); {dummy}
arrivalnode:(evar: varidefp);
deprnode,
apprnode,
destnode: (loc: nodep; code: statementp);
viaptnode: (vlist: boolean; via,duration,velocity: nodep; vcode: statementp);
durnode: (durrel: reltypes; durval: nodep);
sfacnode,
wobblenode,
swtnode: (clval: nodep);
nullingnode,
wristnode,
cwnode: (notp: boolean); (* true = nonulling/zero wrist/counter_clockwise *)
ffnode: (ff: nodep; csys, pdef: boolean); (* true = world, false = hand *)
forcenode: (ftype: forcetypes; frel: reltypes; fval, fvec, fframe: nodep);
stiffnode: (fv, mv, coc: nodep);
gathernode: (gbits: integer);
cmonnode: (cmon: statementp; errhandlerp: boolean);
errornode: (eexpr: nodep);
calcnode: (rigid, frame1: boolean; other: framep; case tvarp: boolean of
false: (tval: transp); true: (tvar: dump) ); {dummy}
arraydefnode: (numdims: 1..10; bounds: nodep; combnds: boolean);
bnddefnode: (lower, upper: nodep);
bndvalnode: (lb, ub, mult: integer);
waitlistnode: (who: dump; when: integer);
procdefnode:(ptype: datatypes; level: 0..255;
pname, paramlist: varidefp; body: statementp);
tlistnode: (tok: tokenp);
dimnode: (time, distance, angle, dforce: integer);
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;
(* 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;
endOfLine, backup, expandmacros, flushcomments, dimCheck: boolean;
semiseen, shownline: boolean;
eofError: boolean;
inMove,inCoblock: boolean;
curtoken: token;
file1,file2,file3,file4,file5: atext;
line: linestr;
(* From INTERP *)
(* curInt, activeInts, readQueue, allPdbs: pdbp;
curEnv, sysEnv: envheaderp;
clkQueue: nodep;
allEvents: eventp;
STLevel: integer;
etime: integer;
curtime: integer;
stime: integer;
msg: messagep;
inputp: integer;
debugLevel: integer; *)
d1: array[1..15] of dump;
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 dump;
ppLines: array [1..maxPPLines] of dump;
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: dump;
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: framep;
(* Various constant pointers *)
xhat,yhat,zhat,nilvect: vectorp;
niltrans: transp;
bpark, ypark, gpark, rpark: transp; (* arm park positions *)
{ Externally defined routines from elsewhere: }
(* From ALLOC *)
procedure relNode(n: nodep); external;
function newNode: nodep; external;
(* From FREE *)
procedure freeStatement(s: statementp); external;
(* From PROOT *)
procedure errprnt; external;
procedure getToken; external;
procedure getDelim(char: ascii); external;
procedure ppFlush; external;
function ov1StmntParse: statementp; external;
function ov1ExprParse: nodep; external;
(* From PAUX1 *)
procedure appendEnd(s,so: statementp); external;
function getDtype(n: nodep): datatypes; external;
function checkArg(n: nodep; d: datatypes): nodep; external;
(* From PAUX2 *)
procedure relExpr(n: nodep); external;
function evalOrder(what,last: nodep; pcons: boolean): nodep; external;
function matchdim(d1,d2: nodep; exactp: boolean): boolean; external;
function getdim(n: nodep; var d: nodep): nodep; external;
(* Display-related Routines *)
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 pOv1Get; external;
procedure pOv1Get; begin end;
function assignParse(st: statementp): boolean; external;
function assignParse;
var d1,d2: datatypes; b: boolean; n1,n2,dim1,dim2: nodep;
begin (* assignment statement *)
b := false;
st↑.stype := assigntype;
st↑.aval := nil;
backup := true;
st↑.what := ov1ExprParse; (* what do we have? *)
with st↑.what↑ do
begin
n1 := nil;
if (ntype = leafnode) and (ltype = varitype) then n1 := st↑.what
else b := not ((ntype = exprnode) and
((op = callop) or (op = arefop) or (op = dacop)) );
if b and (ntype = exprnode) and
((op = tposop) or (op = torientop) or (op = deproachop)) then
if (arg1↑.ntype = leafnode) and (arg1↑.ltype = varitype) then
begin b := false; n1 := arg1 end
else b := not ((arg1↑.ntype = exprnode) and (arg1↑.op = arefop));
if n1 <> nil then (* make sure it's not a device *)
if n1↑.vari↑.level = 0 then
b := n1↑.vari↑.offset in [0,2,4,6,8,10,12,14,16,20];
(* offsets: arms: 0,4,8,12 hands: 2,6,10,14 driver/vise: 16,20 *)
if b then
begin (* no good *)
if n1 = nil then
begin pp20L('Can''t start a statem',20); pp20('ent this way ',12) end
else begin pp20L('Can''t assign values ',20); pp10('to devices',10) end;
errprnt;
end
else if (ntype = exprnode) and ((op = callop) or (op = dacop)) then
begin
if op = callop then st↑.stype := calltype;
st↑.exprs := evalOrder(st↑.what,nil,true);
end
else
begin
getToken; (* look for the ":=" *)
if (curToken.ttype <> reswdtype) or (curToken.rtype <> stmnttype) or
(curToken.stmnt <> assigntype) then
begin
b := true; (* no good *)
pp20L('Expecting a ":=" her',20); pp5('e. ',2); ppFlush;
errprnt;
relExpr(st↑.what);
end
else
begin (* so far so good *)
st↑.aval := ov1ExprParse;
d1 := getdtype(st↑.what);
d2 := getdtype(st↑.aval);
if d1 = undeftype then
begin
if (d2 = transtype) and (st↑.aval↑.ntype = exprnode) then
with st↑.aval↑ do (* check if it shouldn't really be a frame *)
if (op = constrop) or (op = fmakeop) then d2 := frametype
else if (ttmulop <= op) and (op <= tvsubop) then d2 := getDtype(arg1);
d1 := d2;
if st↑.what↑.ntype = leafnode then st↑.what↑.vari↑.vtype := d1
else st↑.what↑.arg1↑.vari↑.vtype := d1;
end;
if d2 = undeftype then
begin
d2 := d1;
if st↑.aval↑.ntype = leafnode then st↑.aval↑.vari↑.vtype := d2
else st↑.aval↑.arg1↑.vari↑.vtype := d2;
end;
if (d1 = frametype) or (d1 = rottype) then d1 := transtype;
if (d2 = frametype) or (d2 = rottype) then d2 := transtype;
if d1 <> d2 then
begin (* no good *)
b := true;
pp20L('Can''t assign a ',15); ppDtype(d2);
pp10(' to a ',6); ppDtype(d1);
ppChar('.'); ppFlush;
errprnt;
relExpr(st↑.what);
relExpr(st↑.aval);
end
else
begin (* determine order to evaluate expressions *)
if ntype = leafnode then n1 := nil
else if op = arefop then n1 := arg2
else if arg1↑.ntype = leafnode then n1 := nil else n1 := arg1↑.arg2;
if n1 = nil then n2 := nil
else n2 := evalorder(n1,nil,true); (* deal with subscripts *)
st↑.exprs := evalorder(st↑.aval,n2,true);
dim1 := nil; (* now check that dimensions match *)
dim2 := nil;
if not matchdim(getdim(st↑.aval,dim1),getdim(st↑.what,dim2),dimCheck) then
begin
pp20L('Dimensions don''t mat',20); pp20('ch in assignment sta',20);
pp10('tement ',6);
errprnt;
end;
relNode(dim1);
relNode(dim2);
end;
end;
end;
end;
assignParse := b;
end;
function ifParse(st: statementp): boolean; external;
function ifParse;
var b: boolean;
begin (* if statement *)
b := false;
with st↑ do
begin
icond := checkarg(ov1ExprParse,svaltype); (* get the if condition *)
exprs := evalOrder(icond,nil,true);
getToken; (* look for the "then" *)
if (curToken.ttype <> reswdtype) or (curToken.rtype <> filtype) or
(curToken.filler <> thentype) then
begin
b := true; (* no good *)
pp20L('Expecting a "THEN" h',20); pp5('ere. ',4); ppFlush;
errprnt;
relExpr(st↑.icond);
end
else
with curToken do
begin
st↑.thn := ov1StmntParse; (* get the then clause *)
st↑.thn↑.last := st; (* set up a back pointer *)
appendEnd(st,st↑.thn);
getToken; (* look for the "else" *)
if (ttype = delimtype) and (ch = ';') then
begin
semiseen := true;
getToken; (* peek past the ";" *)
end;
if (ttype = reswdtype) and (rtype = filtype) and
(filler = elsetype) then
begin
if semiseen then
begin
pp20L('Deleting extraneous ',20); pp20('";" before "ELSE" ',17);
errprnt;
end;
st↑.els := ov1StmntParse;
st↑.els↑.last := st; (* set up a back pointer *)
st↑.els↑.next := st↑.thn↑.next; (* and one to the END *)
end
else begin backup := true; st↑.els := nil end;
end;
end;
ifParse := b;
end;
function forParse(st: statementp): boolean; external;
function forParse;
var b: boolean; lexp,dim1,dim2: nodep;
begin (* for statement *)
b := false;
dim1 := nil;
dim2 := nil;
with st↑ do
begin
forvar := checkarg(ov1ExprParse,svaltype); (* get the for variable *)
initial := nil;
step := nil;
final := nil;
with forvar↑ do (* make sure it's a variable *)
if not (((ntype = leafnode) and (ltype = varitype)) or
((ntype = exprnode) and (op = arefop))) then
begin (* no good *)
b := true;
pp20L('Need a scalar variab',20); pp10('le here. ',8); ppFlush;
errprnt;
end
else
begin
dim1 := getdim(forvar,dim1);
getToken; (* look for the ":=" *)
if (curToken.ttype <> reswdtype) or (curToken.rtype <> stmnttype) or
(curToken.stmnt <> assigntype) then
begin
b := true; (* no good *)
pp20L('Expecting a ":=" her',20); pp5('e. ',2); ppFlush;
errprnt;
end
else
begin (* so far so good *)
initial := checkarg(ov1ExprParse,svaltype); (* get the initial value *)
if not matchdim(dim1,getdim(initial,dim2),dimCheck) then
begin
pp20L('Dimensions don''t mat',20); pp20('ch in FOR statement ',19);
errprnt;
end;
getToken; (* look for the "STEP" *)
if (curToken.ttype <> reswdtype) or (curToken.rtype <> filtype) or
(curToken.filler <> steptype) then
begin
b := true; (* no good *)
pp20L('Expecting a "STEP" h',20); pp5('ere. ',4); ppFlush;
errprnt;
end
else
begin (* still good *)
step := checkarg(ov1ExprParse,svaltype); (* get the step value *)
if not matchdim(dim1,getdim(step,dim2),dimCheck) then
begin
pp20L('Dimensions don''t mat',20); pp20('ch in FOR statement ',19);
errprnt;
end;
getToken; (* look for the "TO" *)
if (curToken.ttype <> reswdtype) or (curToken.rtype <> filtype) or
(curToken.filler <> untltype) then
begin
b := true; (* no good *)
pp20L('Expecting an "UNTIL"',20); pp10(' here. ',6); ppFlush;
errprnt;
end
else
begin (* almost got it *)
final := checkarg(ov1ExprParse,svaltype); (* get the final value *)
if not matchdim(dim1,getdim(final,dim2),dimCheck) then
begin
pp20L('Dimensions don''t mat',20); pp20('ch in FOR statement ',19);
errprnt;
end;
with forvar↑ do
if ntype = leafnode then lexp := nil
else lexp := evalOrder(arg2,nil,true); (* push array subscripts *)
lexp := evalOrder(initial,lexp,true);
lexp := evalOrder(step,lexp,true);
exprs := evalOrder(final,lexp,true);
getToken; (* look for the "do" *)
if (curToken.ttype <> reswdtype) or (curToken.rtype <> filtype) or
(curToken.filler <> dotype) then
begin
b := true; (* no good *)
pp20L('Expecting a "DO" her',20); pp5('e. ',2); ppFlush;
errprnt;
end
else
begin
fbody := ov1StmntParse; (* finally - get the body of the for *)
fbody↑.last := st; (* set up a back pointer *)
appendEnd(st,fbody);
end;
end;
end;
end;
end;
if dim1 <> nil then relNode(dim1);
if dim2 <> nil then relNode(dim2);
if b then (* bad statement - clean up a bit *)
begin
relExpr(forvar);
if initial <> nil then relExpr(initial);
if step <> nil then relExpr(step);
if final <> nil then relExpr(final);
backup := true;
end;
end;
forParse := b;
end;
function whileParse(st: statementp): boolean; external;
function whileParse;
var b: boolean;
begin (* while statement *)
b := false;
with st↑ do
begin
cond := checkarg(ov1ExprParse,svaltype); (* get the while condition *)
exprs := evalOrder(cond,nil,true);
getToken; (* look for the "do" *)
if (curToken.ttype <> reswdtype) or (curToken.rtype <> filtype) or
(curToken.filler <> dotype) then
begin
b := true; (* no good *)
pp20L('Expecting a "DO" her',20); pp5('e. ',2); ppFlush;
errprnt;
relExpr(st↑.cond);
end
else
begin
st↑.body := ov1StmntParse; (* get the body of the while *)
st↑.body↑.last := st; (* set up a back pointer *)
appendEnd(st,st↑.body);
end;
end;
whileParse := b;
end;
function untilParse(st: statementp): boolean; external;
function untilParse;
var b: boolean;
begin (* until statement *)
st↑.stype := untiltype;
b := false;
st↑.body := ov1StmntParse; (* get the body of the until *)
st↑.body↑.last := st; (* set up a back pointer *)
appendEnd(st,st↑.body);
getToken; (* look for the "until" *)
if (curToken.ttype = delimtype) and (curToken.ch = ';') then
begin
semiseen := true;
getToken; (* peek past the ";" *)
end;
if (curToken.ttype <> reswdtype) or (curToken.rtype <> filtype) or
(curToken.filler <> untltype) then
begin
b := true; (* no good *)
pp20L('Expecting an "UNTIL"',20); pp10(' here. ',6); ppFlush;
errprnt;
freeStatement(st↑.body); (* reclaim the body of the until *)
end
else
with st↑ do
begin
if semiseen then
begin
pp20L('Deleting extraneous ',20); pp20('";" before "UNTIL" ',18);
errprnt;
end;
cond := checkarg(ov1ExprParse,svaltype); (* get the until condition *)
exprs := evalOrder(cond,nil,true);
end;
untilParse := b;
end;
function caseParse(st: statementp): boolean; external;
function caseParse;
var b,numcase,done: boolean; i,maxrange: integer;
co,cp,cn: nodep; endp: statementp;
procedure addClistnode(i: integer; sp: boolean);
var cln: nodep;
begin
cln := newNode;
with cln↑ do
begin
ntype := clistnode;
next := nil;
cval := i;
if sp then
begin
stmnt := ov1StmntParse;
if semiseen then semiseen := false
else
begin (* look for the separating ";" *)
getToken;
with curToken do
if (ttype <> delimtype) or (ch <> ';') then (* not there *)
begin
backup := true;
if (ttype <> reswdtype) or (rtype <> stmnttype) or
(stmnt <> endtype) then
begin
pp20L('Inserting missing se',20); pp10('micolon ',7);
errprnt;
end;
end;
end;
stmnt↑.last := st; (* set up a back pointer *)
stmnt↑.next := endp; (* & a pointer to the end *)
while co <> nil do
begin
co↑.stmnt := stmnt; (* multiple labels for this statement *)
co := co↑.next;
end;
st↑.ncases := st↑.ncases + 1;
end
else
begin
stmnt := nil;
if co = nil then co := cln; (* need to fill in stmnt ptr later *)
end;
if cp = nil then begin st↑.caselist := cln; clast := nil end
else begin cp↑.next := cln; clast := cp end;
end;
cp := cln;
end;
begin {caseParse} (* case statement *)
b := false;
with curToken, st↑ do
begin
index := checkarg(ov1ExprParse,svaltype); (* get the case index *)
caselist := nil;
getToken; (* look for the "of" *)
if (ttype <> reswdtype) or (rtype <> filtype) or (filler <> oftype) then
begin
b := true; (* no good *)
pp20L('Expecting an "OF" he',20); pp5('re. ',3); ppFlush;
errprnt;
relExpr(st↑.index);
end
else
begin
getToken; (* look for the "begin" *)
if (ttype <> reswdtype) or (rtype <> stmnttype) or (stmnt <> blocktype) then
begin (* no good *)
backup := true;
pp20L('Expecting a "BEGIN" ',20); pp5('here.',5);
errprnt;
end;
(* *** ??? maybe should allow a block id here ??? *** *)
appendEnd(st,st); (* get an END statement *)
endp := next;
next := nil;
getToken; (* see what type of case we have *)
backup := true;
if ((ttype = delimtype) and (ch = '[')) or
((ttype = reswdtype) and (rtype = filtype) and (filler = elsetype)) then
numcase := true (* it's a numbered case statement *)
else numcase := false; (* regular type *)
maxrange := 0;
co := nil;
cp := nil;
done := false;
repeat
getToken;
if (ttype = reswdtype) and (rtype = stmnttype) and (stmnt = endtype) then
done := true
else if numcase then (* numbered case statement *)
if (ttype = delimtype) and (ch = '[') then
begin
cn := checkarg(ov1ExprParse,svaltype); (* get constant value *)
if cn↑.ntype <> leafnode then
begin
pp20L('Must have a constant',20); pp5(' here',5);
errprnt;
i := -2;
end
else i := round(cn↑.s);
if i > maxrange then maxrange := i;
relExpr(cn);
getDelim(']'); (* get closing ']' *)
getToken; (* peek ahead now *)
backup := true;
if ((ttype = delimtype) and (ch = '[')) or
((ttype = reswdtype) and (rtype = filtype) and
(filler = elsetype)) then addClistnode(i,false)
else addClistnode(i,true)
end
else if (ttype = reswdtype) and (rtype = filtype) and
(filler = elsetype) then addClistnode(-1,true)
else
begin
pp20L('Need a case number h',20); pp5('ere. ',4);
errprnt;
backup := true;
addClistnode(-2,true); (* use a garbage one & clean up *)
end
else (* regular case statement *)
begin
if (ttype <> delimtype) or (ch <> ';') then
begin
backup := true;
addClistnode(maxrange,true);
end;
maxrange := maxrange + 1;
end
until done;
if numcase then range := -maxrange else range := maxrange - 1;
exprs := evalOrder(index,nil,true);
end;
(* *** ??? block id with the end too ??? *** *)
end;
caseParse := b;
end;