ch7bin.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* EVALUATION OF BINARY OPERATORS */
  7. #include "LLlex.h"
  8. #include "Lpars.h"
  9. #include <em_arith.h>
  10. void ch7bin(arith *pval, int oper, arith val)
  11. {
  12. switch (oper) {
  13. case '%':
  14. if (val == 0)
  15. error("%% by 0");
  16. else
  17. *pval = *pval % val;
  18. break;
  19. case '/':
  20. if (val == 0)
  21. error("/ by 0");
  22. else
  23. *pval = *pval / val;
  24. break;
  25. case '*':
  26. *pval = *pval * val;
  27. break;
  28. case '+':
  29. *pval = *pval + val;
  30. break;
  31. case '-':
  32. *pval = *pval - val;
  33. break;
  34. case LEFT:
  35. *pval = *pval << val;
  36. break;
  37. case RIGHT:
  38. *pval = *pval >> val;
  39. break;
  40. case '<':
  41. *pval = (*pval < val);
  42. break;
  43. case '>':
  44. *pval = (*pval > val);
  45. break;
  46. case LESSEQ:
  47. *pval = (*pval <= val);
  48. break;
  49. case GREATEREQ:
  50. *pval = (*pval >= val);
  51. break;
  52. case EQUAL:
  53. *pval = (*pval == val);
  54. break;
  55. case NOTEQUAL:
  56. *pval = (*pval != val);
  57. break;
  58. case '&':
  59. *pval = *pval & val;
  60. break;
  61. case '^':
  62. *pval = *pval ^ val;
  63. break;
  64. case '|':
  65. *pval = *pval | val;
  66. break;
  67. case AND:
  68. *pval = (*pval && val);
  69. break;
  70. case OR:
  71. *pval = (*pval || val);
  72. break;
  73. case ',':
  74. *pval = val;
  75. break;
  76. }
  77. }