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"
|
2019-03-01 17:36:11 +00:00
|
|
|
#include "ch3bin.h"
|
|
|
|
#include "skip.h"
|
|
|
|
#include "error.h"
|
1989-10-23 10:35:56 +00:00
|
|
|
|
2019-03-01 17:36:11 +00:00
|
|
|
void ch3bin(register arith *pval, int *pis_uns, int oper, register arith val, int is_uns)
|
1989-10-23 10:35:56 +00:00
|
|
|
{
|
1993-03-18 13:24:20 +00:00
|
|
|
if (is_uns) *pis_uns = 1;
|
1989-10-23 10:35:56 +00:00
|
|
|
switch (oper) {
|
|
|
|
case '/':
|
1993-03-18 13:24:20 +00:00
|
|
|
if (val == 0) {
|
1989-10-23 10:35:56 +00:00
|
|
|
error("/ by 0");
|
1993-03-18 13:24:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*pis_uns) {
|
2017-10-29 21:01:29 +00:00
|
|
|
*pval /= (unsigned arith) val;
|
1993-03-18 13:24:20 +00:00
|
|
|
}
|
|
|
|
else {
|
1995-03-27 11:46:47 +00:00
|
|
|
*pval = *pval / val;
|
1993-03-18 13:24:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
if (val == 0) {
|
|
|
|
error("%% by 0");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*pis_uns) {
|
2017-10-29 21:01:29 +00:00
|
|
|
*pval %= (unsigned arith) val;
|
1993-03-18 13:24:20 +00:00
|
|
|
}
|
|
|
|
else {
|
1995-03-27 11:46:47 +00:00
|
|
|
*pval = *pval % val;
|
1993-03-18 13:24:20 +00:00
|
|
|
}
|
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:
|
1993-03-18 13:24:20 +00:00
|
|
|
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 '<':
|
1993-03-18 13:24:20 +00:00
|
|
|
{ arith tmp = *pval; *pval = val; val = tmp; }
|
|
|
|
/* fall through */
|
1989-10-23 10:35:56 +00:00
|
|
|
case '>':
|
1993-03-18 13:24:20 +00:00
|
|
|
if (*pis_uns) {
|
2017-10-29 21:01:29 +00:00
|
|
|
*pval = (unsigned arith) *pval > (unsigned arith) val;
|
1993-03-18 13:24:20 +00:00
|
|
|
}
|
|
|
|
else *pval = (*pval > val);
|
1989-10-23 10:35:56 +00:00
|
|
|
break;
|
|
|
|
case LESSEQ:
|
1993-03-18 13:24:20 +00:00
|
|
|
{ arith tmp = *pval; *pval = val; val = tmp; }
|
|
|
|
/* fall through */
|
1989-10-23 10:35:56 +00:00
|
|
|
case GREATEREQ:
|
1993-03-18 13:24:20 +00:00
|
|
|
if (*pis_uns) {
|
2017-10-29 21:01:29 +00:00
|
|
|
*pval = (unsigned arith) *pval >= (unsigned arith) val;
|
1993-03-18 13:24:20 +00:00
|
|
|
}
|
|
|
|
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 ',':
|
1993-03-18 13:24:20 +00:00
|
|
|
*pis_uns = is_uns;
|
1989-10-23 10:35:56 +00:00
|
|
|
*pval = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|