avoid recursive calls while parsing lists.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@655 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2002-10-28 17:46:55 +00:00
parent 8c71464b80
commit ad552d04b4

View File

@ -316,31 +316,40 @@ ParseArgs(Atom a)
static Term static Term
ParseList(void) ParseList(void)
{ {
Term t, s; Term t, s, o;
t = ParseTerm(999); CELL *to_store;
o = AbsPair(H);
loop:
to_store = H;
H+=2;
to_store[0] = ParseTerm(999);
if (tokptr->Tok == Ord(Ponctuation_tok)) { if (tokptr->Tok == Ord(Ponctuation_tok)) {
if (((int) tokptr->TokInfo) == ',') { if (((int) tokptr->TokInfo) == ',') {
NextToken; NextToken;
if (tokptr->Tok == Ord(Name_tok) if (tokptr->Tok == Ord(Name_tok)
&& strcmp(RepAtom((Atom)(tokptr->TokInfo))->StrOfAE, "..") == 0) { && strcmp(RepAtom((Atom)(tokptr->TokInfo))->StrOfAE, "..") == 0) {
NextToken; NextToken;
s = ParseTerm(999); to_store[1] = ParseTerm(999);
} else } else {
s = ParseList(); /* check for possible overflow against local stack */
if (H > ASP-4096) {
to_store[1] = TermNil;
ErrorMessage = "Stack Overflow";
FAIL;
} else {
to_store[1] = AbsPair(H);
goto loop;
}
}
} else if (((int) tokptr->TokInfo) == '|') { } else if (((int) tokptr->TokInfo) == '|') {
NextToken; NextToken;
s = ParseTerm(999); to_store[1] = ParseTerm(999);
} else } else {
s = MkAtomTerm(AtomNil); to_store[1] = MkAtomTerm(AtomNil);
t = MkPairTerm(t, s);
/* check for possible overflow against local stack */
if (H > ASP-4096) {
ErrorMessage = "Stack Overflow";
FAIL;
} }
} else } else
FAIL; FAIL;
return (t); return (o);
} }
#ifndef INFINITY #ifndef INFINITY