diff --git a/C/stdpreds.c b/C/stdpreds.c index be61a07b7..167fc6e70 100644 --- a/C/stdpreds.c +++ b/C/stdpreds.c @@ -2960,6 +2960,22 @@ Yap_IsOp(Atom at) return (!EndOfPAEntr(op)); } +int +Yap_IsOpMaxPrio(Atom at) +{ + OpEntry *op = NextOp(RepOpProp((Prop)(RepAtom(at)->PropsOfAE))); + int max; + + if (EndOfPAEntr(op)) + return 0; + max = (op->Prefix & 0xfff); + if ((op->Infix & 0xfff) > max) + max = op->Infix & 0xfff; + if ((op->Posfix & 0xfff) > max) + max = op->Posfix & 0xfff; + return max; +} + static Int unify_op(OpEntry *op) { diff --git a/C/write.c b/C/write.c index b1c122867..adffe0da6 100644 --- a/C/write.c +++ b/C/write.c @@ -214,12 +214,12 @@ legalAtom(unsigned char *s) /* Is this a legal atom ? */ static int LeftOpToProtect(Atom at, int p) { - return Yap_IsOp(at); + return Yap_IsOpMaxPrio(at) > p; } static int RightOpToProtect(Atom at, int p) { - return Yap_IsOp(at); + return Yap_IsOpMaxPrio(at) > p; } static wtype diff --git a/H/Yapproto.h b/H/Yapproto.h index c22e385f3..65826d352 100644 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -316,6 +316,7 @@ void STD_PROTO(Yap_InitCPreds,(void)); void STD_PROTO(Yap_show_statistics,(void)); void STD_PROTO(Yap_signal,(yap_signals)); void STD_PROTO(Yap_undo_signal,(yap_signals)); +int STD_PROTO(Yap_IsOpMaxPrio,(Atom)); /* sysbits.c */ void STD_PROTO(Yap_set_fpu_exceptions,(int));