ack/lang/cem/cpp.ansi/ch3bin.c

106 lines
1.8 KiB
C
Raw Normal View History

1989-10-23 10:35:56 +00:00
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
1994-06-24 14:02:31 +00:00
/* $Id$ */
1989-10-23 10:35:56 +00:00
/* EVALUATION OF BINARY OPERATORS */
#include "Lpars.h"
#include "arith.h"
ch3bin(pval, pis_uns, oper, val, is_uns)
1989-10-23 10:35:56 +00:00
register arith *pval, val;
int oper, is_uns, *pis_uns;
1989-10-23 10:35:56 +00:00
{
if (is_uns) *pis_uns = 1;
1989-10-23 10:35:56 +00:00
switch (oper) {
case '/':
if (val == 0) {
1989-10-23 10:35:56 +00:00
error("/ by 0");
break;
}
if (*pis_uns) {
*pval /= (unsigned arith) val;
}
else {
1995-03-27 11:46:47 +00:00
*pval = *pval / val;
}
break;
case '%':
if (val == 0) {
error("%% by 0");
break;
}
if (*pis_uns) {
*pval %= (unsigned arith) val;
}
else {
1995-03-27 11:46:47 +00:00
*pval = *pval % val;
}
1989-10-23 10:35:56 +00:00
break;
case '*':
*pval = *pval * val;
break;
case '+':
*pval = *pval + val;
break;
case '-':
*pval = *pval - val;
break;
case LEFT:
*pval = *pval << val;
break;
case RIGHT:
if (val == 0) break;
if (*pis_uns) {
*pval = (*pval >> 1) & ~arith_sign;
*pval = *pval >> (val - 1);
}
else *pval = *pval >> val;
1989-10-23 10:35:56 +00:00
break;
case '<':
{ arith tmp = *pval; *pval = val; val = tmp; }
/* fall through */
1989-10-23 10:35:56 +00:00
case '>':
if (*pis_uns) {
*pval = (unsigned arith) *pval > (unsigned arith) val;
}
else *pval = (*pval > val);
1989-10-23 10:35:56 +00:00
break;
case LESSEQ:
{ arith tmp = *pval; *pval = val; val = tmp; }
/* fall through */
1989-10-23 10:35:56 +00:00
case GREATEREQ:
if (*pis_uns) {
*pval = (unsigned arith) *pval >= (unsigned arith) val;
}
else *pval = (*pval >= val);
1989-10-23 10:35:56 +00:00
break;
case EQUAL:
*pval = (*pval == val);
break;
case NOTEQUAL:
*pval = (*pval != val);
break;
case '&':
*pval = *pval & val;
break;
case '^':
*pval = *pval ^ val;
break;
case '|':
*pval = *pval | val;
break;
case AND:
*pval = (*pval && val);
break;
case OR:
*pval = (*pval || val);
break;
case ',':
*pis_uns = is_uns;
1989-10-23 10:35:56 +00:00
*pval = val;
break;
}
}