perm filename PCLAUS.2[EAL,HE] blob
sn#676478 filedate 1982-09-27 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00004 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 {$NOMAIN Parser auxilliary routines for Motion statements }
C00025 00003 { Externally defined routines from elsewhere: }
C00028 00004 (* aux functions for motion clauses: thencode & clauseParse *)
C00042 ENDMK
C⊗;
{$NOMAIN Parser auxilliary routines for Motion statements }
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 }
strngp = ↑strng;
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;
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
affixtype,
unfixtype: (frame1, frame2, byvar, atexp: nodep; rigid: boolean);
cmtype: (oncond: nodep; conclusion: statementp;
deferCm, exprCm: boolean; cdef: varidefp);
signaltype,
waittype: (event: nodep);
enabletype,
disabletype: (cmonlab: varidefp);
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 *)
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: dump; case tvarp: boolean of
false: (tval: dump); 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: dump;
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: 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;
function newStatement: statementp; external;
(* From PROOT *)
procedure errprnt; external;
procedure getToken; external;
procedure getDelim(char: ascii); external;
function clStmntParse: statementp; external;
function clExprParse: nodep; external;
(* From PAUX1 *)
function makeNewVar(vartype: datatypes; vid: identp): varidefp; external;
procedure appendEnd(s,so: statementp); external;
function getDtype(n: nodep): datatypes; external;
function checkArg(n: nodep; d: datatypes): nodep; external;
(* From PAUX2 *)
procedure checkdim(n,d: 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 pClauseGet; external;
procedure pClauseGet; begin end;
(* aux functions for motion clauses: thencode & clauseParse *)
function thencode(evp: boolean): statementp; external;
function thencode;
var s, st: statementp; n: nodep; v: varidefp;
begin
s := clStmntParse; (* get THEN code *)
if s↑.stype = signaltype then st := s (* treat signal specially *)
else
begin
st := newStatement;
with st↑ do (* make a cmon to execute the code *)
begin
stype := cmtype;
deferCm := false;
exprCm := false;
conclusion := s;
appendEnd(st,s);
n := newNode;
oncond := n;
end;
v := makeNewVar(cmontype,nil); (* make a variable for the cmon *)
v↑.s := st;
st↑.cdef := v;
if evp then (* do we need to make an event variable? *)
begin
with n↑ do
begin
ntype := leafnode;
ltype := varitype;
vari := makeNewVar(eventtype,nil);
vid := nil;
end;
end;
end;
thencode := st;
end;
function clauseParse(absSeen: boolean): nodep; external;
function clauseParse;
var cl,nv,vdim: nodep; b: boolean; dummyrel: reltypes; bits,i: integer; d: datatypes;
function relParse: reltypes;
begin
getToken; (* get the relation *)
with curToken do
if (ttype = reswdtype) and (rtype = optype) and (op <= sgtop) then
relParse := op
else
begin
pp20L('Need a relational op',20); pp20('erator here ',11);
errprnt;
backup := true;
relParse := seqop;
end;
end;
begin
getToken;
with curToken do
begin
if (ttype = identtype) then b := id↑.name↑.ch = 'SPEED_FACT' else b := false;
if b then
begin
cl := newNode;
with cl↑ do
begin
ntype := sfacnode;
dummyrel := relParse; (* skip over the "=" *)
clval := checkarg(clExprParse,svaltype);
checkdim(clval,nodim↑.dim);
end;
end
else if (ttype <> reswdtype) or (rtype <> clsetype) then
begin
cl := nil;
backup := true;
pp20L('Not a valid clause ',18);
errprnt;
end
else
begin
cl := newNode;
with cl↑ do
case clause of
durationtype:
begin
ntype := durnode;
durrel := relParse;
durval := checkarg(clExprParse,svaltype);
checkdim(durval,timedim↑.dim);
end;
wobbletype,
stopwaittimetype:
begin
if clause = wobbletype then
begin
ntype := wobblenode;
vdim := angledim↑.dim;
end
else
begin
ntype := swtnode;
vdim := timedim↑.dim;
end;
dummyrel := relParse;
clval := checkarg(clExprParse,svaltype);
checkdim(clval,vdim);
end;
nullingtype,
nonullingtype:
begin
ntype := nullingnode;
if clause = nonullingtype then notp := true else notp := false;
end;
cwtype,
ccwtype:
begin
ntype := cwnode;
if clause = cwtype then notp := false else notp := true;
end;
approachtype,
departuretype:
begin
if clause = approachtype then ntype := apprnode else ntype := deprnode;
dummyrel := relParse;
getToken; (* check for NILDEPROACH *)
if (ttype = reswdtype) and
(rtype = clsetype) and (clause = nildeproachtype) then loc := nil
else
begin (* need to get deproach value *)
backup := true;
loc := clExprParse; (* can be scalar, vector or trans *)
checkdim(loc,distancedim↑.dim);
end;
getToken; (* now look for THEN *)
if (ttype = reswdtype) and
(rtype = filtype) and (filler = thentype) then
begin
code := thencode(true);
end
else
begin code := nil; backup := true; end;
end;
forcewristtype:
begin
ntype := wristnode;
getToken;
if (ttype = reswdtype) and (rtype = optype) and
(curToken.op = notop) then
begin
notp := true;
getToken;
end
else notp := false;
if (ttype <> reswdtype) or (rtype <> filtype) or
(filler <> zeroedtype) then
begin
backup := true;
pp20L('Garbage clause ',14);
errprnt;
end
end;
forceframetype:
begin
ntype := ffnode;
if not absSeen then dummyrel := relParse;
ff := checkarg(clExprParse,transtype);
checkdim(ff,distancedim↑.dim);
csys := true; (* assume WORLD if not specified *)
getToken;
if (ttype = reswdtype) and (rtype = filtype) and (filler = intype) then
begin (* see whether WORLD or HAND coord sys *)
getToken;
if (ttype = reswdtype) and (rtype = filtype) and
(filler = handtype) then csys := false (* use HAND coords *)
else if (ttype <> reswdtype) or (rtype <> filtype) or
(filler <> worldtype) then (* better be WORLD coords *)
begin
backup := true;
pp20L('Need HAND or WORLD h',20); pp5('ere ',3);
errprnt;
end
end
else backup := true;
end;
forcetype,
torquetype,
angularvelocitytype:
begin
ntype := forcenode;
if clause = forcetype then
begin ftype := force; vdim := forcedim↑.dim end
else if clause = torquetype then
begin ftype := torque; vdim := torquedim↑.dim end
else begin ftype := angvelocity; vdim := angveldim↑.dim end;
if absSeen then ftype := succ(ftype);
getToken;
if (ttype = delimtype) and (ch = '(') then (* short form *)
begin
b := true;
fvec := checkarg(clExprParse,vectype);
getDelim(')'); (* get closing ")" *)
getToken;
end
else b := false; (* long form *)
if absSeen then
begin
if (ttype <> reswdtype) or (rtype <> optype) or
(curToken.op <> absop) then
begin
backup := true;
pp20L('Need closing "|" her',20); ppChar('e');
errprnt;
end;
end
else backup := true;
frel := relparse;
fval := checkarg(clExprParse,svaltype);
checkdim(fval,vdim);
with curMotion↑ do
if (stype = opentype) or (stype = closetype) or (stype = operatetype) then
begin
b := true; (* so we don't look for a vector specification *)
cl↑.fvec := nil;
end;
if not b then
begin
getToken;
if (ttype <> reswdtype) or (rtype <> filtype) or
((filler <> abouttype) and (filler <> alongtype)) then
begin
backup := true;
pp20L('Need ALONG or ABOUT ',20); pp5('here ',4);
errprnt;
end;
fvec := checkarg(clExprParse,vectype);
end;
getToken; (* check for force frame *)
backup := true;
if (ttype = reswdtype) and (rtype = filtype) and (filler = oftype) then
begin
rtype := clsetype; (* make curToken look like forceframe clause *)
clause := forceframetype;
fframe := clauseParse(true);
end
else fframe := nil;
end;
stiffnesstype:
begin
ntype := stiffnode;
dummyrel := relParse; (* skip over the "=" *)
getDelim('('); (* now look for the "(" *)
fv := clExprParse; (* get the first stiffness component *)
if getDtype(fv) = svaltype then (* see if it's 6 scalars or 2 vectors *)
for i := 1 to 2 do
begin
nv := newNode;
with nv↑ do
begin
ntype := exprnode;
op := vmakeop;
if i = 2 then arg1 := checkarg(clExprParse,svaltype) else arg1 := cl↑.fv;
getDelim(',');
arg2 := checkarg(clExprParse,svaltype);
getDelim(',');
arg3 := checkarg(clExprParse,svaltype);
end;
if i = 1 then begin fv := nv; getDelim(',') end else mv := nv;
end
else
begin (* two vectors *)
fv := checkarg(fv,vectype);
getDelim(','); (* now look for the separating "," *)
mv := checkarg(clExprParse,vectype);
end;
checkdim(fv,fvstiffdim);
checkdim(mv,mvstiffdim);
getDelim(')'); (* now look for the ")" *)
getToken; (* is a center of compliance given? *)
if (ttype = reswdtype) and (rtype = filtype) and (filler = abouttype) then
coc := checkarg(clExprParse,transtype)
else begin coc := nil; backup := true; end;
end;
gathertype:
begin
ntype := gathernode;
dummyrel := relParse; (* skip over the "=" *)
getDelim('('); (* now look for the "(" *)
b := false;
gbits := 0;
repeat
bits := 0;
getToken; (* get component to gather *)
if (ttype <> reswdtype) or (rtype <> clsetype) then b := true
else
case clause of
fxtype: bits := 1B;
fytype: bits := 2B;
fztype: bits := 4B;
mxtype: bits := 10B;
mytype: bits := 20B;
mztype: bits := 40B;
t1type: bits := 100B;
t2type: bits := 200B;
t3type: bits := 400B;
t4type: bits := 1000B;
t5type: bits := 2000B;
t6type: bits := 4000B;
tbltype: bits := 10000B;
otherwise {do nothing};
end;
if bits = 0 then b := true; (* bad clause *)
gbits := gbits + bits; (* really need to logically or these *)
if b then
begin
pp20L('Expecting a force co',20); pp20('mponent here ',12);
errprnt;
end
else getToken; (* pick up the "," or ")" *)
until (ttype <> delimtype) or (ch <> ',') or b;
backup := true;
getDelim(')'); (* now look for the ")" *)
end;
otherwise {do nothing};
end {case};
end;
end;
clauseParse := cl;
end;