home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 338_02 / pop.c < prev    next >
Text File  |  1989-11-30  |  18KB  |  803 lines

  1. /* pop.c - the operand field parser...
  2.  *    (C) Copyright 1982 Steve Passe
  3.  *    All Rights Reserved
  4.  * 
  5.  * version 1.00
  6.  * created 11/8/82
  7.  * 
  8.  * version 1.01
  9.  *
  10.  *   8/30/83 modified for Aztec ver. 1.05g   smp
  11.  *   12/23/83 modified '*' to evaluate according to rorg smp
  12.  *
  13.  */
  14.  
  15. /* begincode */
  16.  
  17. /* includes */
  18.  
  19. #include <stdio.h>
  20. #include "as68.h"
  21.  
  22. #define    RTERM        0x0100
  23. #define    SLASH        0x0101
  24. #define    HYPHEN        0x0102
  25.  
  26. #define    PC_VALUE    0x0103
  27. #define    IMD        0x0104
  28. #define    COMMA        0x0105
  29. #define    POINT        0x0106
  30. #define    VALUE        0x0107
  31. #define    LVALUE        0x0108
  32. #define    FWRD_REF    0x0109
  33.  
  34. #define    TOP        0x0200
  35. #define    BOTTOM        0x0201
  36. #define    LP        0x0202
  37. #define    RP        0x0203
  38. #define    PLUS        0x0204
  39. #define    MINUS        0x0205
  40. #define    MULT        0x0206
  41. #define    DIV        0x0207
  42. #define    LAND        0x0208
  43. #define    LOR        0x0209
  44. #define    LSHIFT        0x020a
  45. #define    RSHIFT        0x020b
  46. #define    NEGATE        0x020c
  47. #define    LIM_C        1
  48. #define    LM_C        2
  49. #define    RXP        0x0303        /* signals a forced short address */
  50.  
  51. /* externals */
  52.  
  53. extern struct _oprnd op1, op2;      /* structs to hold operand val */
  54. extern struct _symbol *symtbl;
  55. extern char pass;
  56. extern long loc_counter;
  57. extern FLAG abs_long;            /* default to absolute long add.*/
  58. extern FLAG rorg;
  59. extern char statement[STMNT_SIZE];    /* statement line buffer */
  60. extern char *opfld_ptr;
  61. extern long lex_val;
  62. extern char *p;
  63. static FLAG lv = 0;
  64.  
  65. static unsigned reg_num = 0;
  66. static int last_typ = 0;
  67.  
  68. long val_stk[10] = {0L};
  69. int opr_stk[10] = {BOTTOM};
  70. static int val_sp = 0;
  71. static int opr_sp = 0;
  72.  
  73. op_clear(op)
  74. register struct _oprnd *op;
  75. {
  76.     op->_long_val = op->_inxl = op->_rel_lbl = NULL;
  77.     op->_typ = NULL;
  78.     op->_regtyp    = op->_iregtyp = op->_reg = op->_ireg = NULL;
  79. }
  80.  
  81. op_eval(op)
  82. register struct _oprnd *op;
  83. {
  84. /** register int r; */
  85.     register int shorty = NULL;        /* force short address this line */
  86.     long val_push();
  87.  
  88.     last_typ = NULL; 
  89.     opr_sp = val_sp = 0;
  90.     reg_num = NULL;
  91.  
  92. /** this only works if nextfield doesn't eat up all the tabs! **/
  93.     switch (*opfld_ptr)    {
  94.     case '\t':
  95.     case '\n':
  96.     case ' ':
  97.     case NULL:
  98.     return (op->_typ = _none);
  99.     case ',':
  100.     ++opfld_ptr;
  101.     }
  102. top:
  103.     switch (/**r =**/ op_scan(op)) {
  104.     case COMMA:
  105.     case NULL:          /* determine operand type, finalize    values in op */
  106.     reduce(TOP);        /* get into one value */
  107.     switch (op->_typ) {
  108.     case _imd:
  109.         op->_data = val_stk[1];
  110.         return _imd;
  111.     case _reglst:
  112.         return _reglst;
  113.     default:
  114.         if (abs_long) op->_long_val    = TRUE;
  115.         if (shorty)    op->_long_val = FALSE;    /* shorty overrides abs_long
  116.                         AND long values in expression */
  117.         op->_addr = val_stk[1];
  118.         if (!op->_long_val && pass == 2) { /* pass 2/short,    check range */
  119.         if (op->_addr & ~0xffff) {
  120.             op->_addr = 0;
  121.             return (op->_typ = LBL_RANGE);
  122.         }
  123.         }
  124.         return (op->_typ = _address);
  125.     }
  126.     case PLUS:
  127.     reduce(PLUS);
  128.     break;
  129.     case MINUS:
  130.     reduce(MINUS);
  131.     break;
  132.     case MULT:
  133.     reduce(MULT);
  134.     break;
  135.     case DIV:
  136.     reduce(DIV);
  137.     break;
  138.     case LAND:
  139.     reduce(LAND);
  140.     break;
  141.     case LOR:
  142.     reduce(LOR);
  143.     break;
  144.     case LSHIFT:
  145.     reduce(LSHIFT);
  146.     break;
  147.     case RSHIFT:
  148.     reduce(RSHIFT);
  149.     break;
  150.     case NEGATE:
  151.     reduce(NEGATE);
  152.     break;
  153.     case RXP:
  154.     reduce(RP);
  155.     if (val_sp != 1) return (op->_typ = OPRND_EVAL);
  156.     shorty = TRUE;
  157.     break;
  158.     case RP:
  159.     reduce(RP);
  160.     break;
  161.     case LP:
  162.     opr_push(LP);
  163.     break;
  164.     case PC_VALUE:
  165.     if (rorg) op->_rel_lbl = TRUE;
  166.     val_push(loc_counter);
  167.     break;
  168.     case IMD:
  169.     op->_typ = _imd;
  170.     break;
  171.     case LVALUE:
  172.     op->_long_val = TRUE;
  173.     case VALUE:
  174.     val_push(lex_val);
  175.     break;
  176.     case FWRD_REF:
  177. /** op->_forward = TRUE; ? */
  178.     val_push(lex_val);
  179.     break;
  180.     case _an:
  181.     return (op->_typ = _an);
  182.     case _dn:
  183.     return (op->_typ = _dn);
  184.     case _pd_ani:
  185.     return (op->_typ = _pd_ani);
  186.     case _ani_pi:
  187.     return (op->_typ = _ani_pi);
  188.     case _ani:
  189.     if (val_sp == 0) {
  190.         return (op->_typ = _ani);
  191.     }
  192.     if (reduce(TOP)    != 1) return (op->_typ = OPRND_EVAL);
  193.     op->_displ = val_stk[1];
  194.     return (op->_typ = _d16_ani);
  195.     case _pc:
  196.     if (reduce(TOP)    != 1) return (op->_typ = OPRND_EVAL);
  197.     op->_displ = val_stk[1];
  198.     return (op->_typ = (op->_iregtyp ? _labeli : _label));
  199. /**    return (op->_typ = _labeli); **/
  200.     case _an_inx:
  201.     if (reduce(TOP)    != 1) return (op->_typ = OPRND_EVAL);
  202.     op->_displ = val_stk[1];
  203.     return (op->_typ = _d8_anx);
  204.     case _ccr:      return (op->_typ = _ccr);
  205.     case _sr:       return (op->_typ = _sr);
  206.     case _usp:      return (op->_typ = _usp);
  207.     case _reglst:   return (op->_typ = _reglst);
  208.  
  209.     case ERROR:
  210.     default:
  211.     return (op->_typ = OPRND_EVAL);
  212.     }
  213.     goto top;
  214. }
  215.  
  216. reduce(tkn)
  217. int tkn;
  218. {
  219.     long val_push(), val_pop();
  220.     long temp;
  221.  
  222.     while (opr_stk[opr_sp] >= (tkn & ~1)) {
  223.     switch (opr_stk[opr_sp--]) {
  224.     case PLUS:
  225.         val_push(val_pop() + val_pop());
  226.         continue;
  227.     case MINUS:
  228.         temp = val_pop();
  229.         val_push(val_pop() - temp);
  230.         continue;
  231.     case MULT:
  232.         val_push(val_pop() * val_pop());
  233.         continue;
  234.     case DIV:
  235.         temp = val_pop();
  236.         val_push(val_pop() / temp);
  237.         continue;
  238.     case LAND:
  239.         val_push(val_pop() & val_pop());
  240.         continue;
  241.     case LOR:
  242.         val_push(val_pop() | val_pop());
  243.         continue;
  244.     case LSHIFT:
  245.         temp = val_pop();
  246.         val_push(val_pop() << temp);
  247.         continue;
  248.     case RSHIFT:
  249.         temp = val_pop();
  250.         val_push(val_pop() >> temp);
  251.         continue;
  252.     case NEGATE:
  253.         val_push(-1    * val_pop());
  254.         continue;
  255.     case LP :
  256.         return val_sp;
  257.     case BOTTOM:
  258.         ++opr_sp;
  259.         return val_sp;
  260.     }
  261.     }
  262.     opr_push(tkn);
  263.     return val_sp;
  264. }
  265.  
  266. long
  267. val_push(l)
  268. long l;
  269. {
  270.     return (val_stk[++val_sp] = l);
  271. }
  272.  
  273. long
  274. val_pop()
  275. {
  276.     return (val_stk[val_sp--]);
  277. }
  278.  
  279. opr_push(t)
  280. int t;
  281. {
  282.     return (opr_stk[++opr_sp] = t);
  283. }
  284.  
  285. opr_pop()
  286. {
  287.     return (opr_stk[opr_sp--]);
  288. }
  289.  
  290. op_scan(op)
  291. register struct _oprnd *op;
  292. {
  293.     register int typ, len;
  294.     char s[32];
  295.     long _dtol(), _htol(), _btol(), _actol();
  296.  
  297.     p = opfld_ptr;
  298.  
  299.     if (typ = reg_scan(op)) {
  300.     opfld_ptr = p;
  301.     if (typ > 0) return typ;
  302.     goto foops;
  303.     }
  304.     switch (*opfld_ptr++) {
  305.     case '-':   /* choose between NEGATE and MINUS */
  306.     switch (last_typ) {
  307.     case NULL:
  308.     case IMD:
  309.     case LP:
  310.     case PLUS:
  311.     case MINUS:
  312.     case MULT:
  313.     case DIV:
  314.     case LAND:
  315.     case LOR:
  316.         return (last_typ = NEGATE);
  317.     case RXP:
  318.     case LSHIFT:
  319.     case RSHIFT:
  320.         goto foops;
  321.     default:
  322.         return (last_typ = MINUS);
  323.     }
  324.     case '(':                       /* (        */
  325.     return (last_typ = LP);
  326.     case ')':                       /* )        */
  327.     if (opfld_ptr[0] == '.'             /* ).s        */
  328.         && (opfld_ptr[1] == 's' || opfld_ptr[1] == 'S')) {
  329.         p = (opfld_ptr += 2);    /* skip the '.s' */
  330.         return (last_typ = RXP);
  331.     }
  332.     else return (last_typ = RP);
  333.     case '#':                       /* #        */
  334.     return (last_typ = IMD);
  335.     case '$':                       /* $        */
  336.     lex_val    = _htol();
  337.     return (last_typ = (lv) ? LVALUE : VALUE);
  338.     case '%':                       /* %        */
  339.     lex_val    = _btol();
  340.     return (last_typ = VALUE);
  341.     case '*':                       /* *        */
  342.     switch (last_typ) {
  343.     case NULL:
  344.     case IMD:
  345.     case LP:
  346.     case PLUS:
  347.     case MINUS:
  348.     case MULT:
  349.     case DIV:
  350.     case LAND:
  351.     case LOR:
  352.     case LSHIFT:
  353.     case RSHIFT:
  354.         return (last_typ = PC_VALUE);
  355.     case RXP: goto foops;
  356.     default:
  357.         return (last_typ = MULT);
  358.     }
  359.     case '/':                       /* /        */
  360.     return (last_typ = DIV);
  361.     case '+':                       /* +        */
  362.     return (last_typ = PLUS);
  363.     case '&':                       /* &        */
  364.     return (last_typ = LAND);
  365.     case '!':                       /* !        */
  366.     return (last_typ = LOR);
  367.     case '>':                       /* >...        */
  368.     if (*opfld_ptr++ != '>') goto foops;        /* >FAIL        */
  369.     return (last_typ = RSHIFT);            /* >>        */
  370.     case '<':                       /* <...        */
  371.     if (*opfld_ptr++ != '<') goto foops;        /* <FAIL        */
  372.     return (last_typ = LSHIFT);            /* <<        */
  373.     case '\'':                      /* '        */
  374.     lex_val    = _actol();
  375.     return (last_typ = VALUE);
  376.     case ',':                       /* ,        */
  377.     return (last_typ = COMMA);
  378.     case ' ':
  379.     case '\t':
  380.     case '\n':
  381.     --opfld_ptr;
  382.     return (last_typ = NULL);
  383.     }
  384.     --opfld_ptr;
  385.  
  386. /* look for decimal number */
  387.     if (*opfld_ptr >= '0' && *opfld_ptr    <= '9') {
  388.     lex_val    = _dtol();
  389.     return (last_typ = (lv) ? LVALUE : VALUE);
  390.     }
  391.     p = opfld_ptr;
  392.     if (nextc(&p) == LIM_C) {               /* look for symbol...*/
  393.     len = 1;
  394.     while ((typ = nextc(&p)) == LIM_C || typ == LM_C) ++len;
  395.     savefield(opfld_ptr, len, s);
  396.     opfld_ptr = p - 1; /* back up from failure char */
  397.     if (typ = symsearch(s))    {
  398.         lex_val = symtbl[typ]._val;
  399.         if (symtbl[typ]._atr & RELOCATABLE)    op->_rel_lbl = TRUE;
  400.         return (last_typ = (lex_val    > 32767L || lex_val < -32768L) ?
  401.                     LVALUE : VALUE);
  402.     }
  403.     lex_val    = 0;
  404.     return (last_typ = (pass == 1) ? FWRD_REF : UNDEF_SYMBOL);
  405.     }
  406.  
  407.     ++opfld_ptr;
  408.  
  409. foops:    /* try to align on next operand    arg */
  410.     --opfld_ptr;
  411.     while ((*opfld_ptr != ',') && (*opfld_ptr != '\t')
  412.         && (*opfld_ptr != '\n') && (*opfld_ptr != ' ')) {
  413.     ++opfld_ptr;
  414.     }
  415.     return (last_typ = ERROR);
  416. }
  417.  
  418. reg_scan(op)
  419. register struct _oprnd *op;
  420. {
  421.     p = opfld_ptr;
  422.  
  423.     while (TRUE) {
  424.     switch (*p++) {
  425.     case '-':                    /* -...     */
  426.         if (*p++ != '(') return NULL;
  427.         switch (reg_name())    {
  428.         case NULL:  return NULL;
  429.         case _an:                   /* -(an...    */
  430.         if (*p++ != ')') return ERROR;
  431.         op->_reg = reg_num;
  432.         op->_regtyp = 'a';
  433.         return _pd_ani;                /* -(an)    */
  434.         default: return ERROR;            /* -(FAIL    */
  435.         }
  436.     case '(':                    /* (...     */
  437.         switch (reg_name())    {
  438.         case NULL:  return NULL;
  439.         case _an:                   /* (an...    */
  440.         op->_reg = reg_num;
  441.         op->_regtyp = 'a';
  442.         switch (*p++) {
  443.         case ')':                /* (an)...    */
  444.             if (*p == '+') {            /* (an)+    */
  445.             ++p;
  446.             return _ani_pi;
  447.             }
  448.             return _ani;            /* (an)     */
  449.         case ',':
  450.             goto index;     /* look for index reg */
  451.         default: return ERROR;
  452.         }
  453.         case _pc:                   /* (pc...    */
  454.         op->_reg = 8;   /* special case of addr. reg. */
  455.         op->_regtyp = 'p';
  456.         switch (*p++) {
  457.         case ')':                /* (pc)     */
  458.             return _pc;
  459.         case ',':
  460. index:            switch (reg_name())    {   /* look for index reg. */
  461.             case _dn:               /* (an/pc,dn...        */
  462.             case _dnw:              /* (an/pc,dn.w...   */
  463.             op->_iregtyp = 'd';
  464.             op->_inxl = FALSE;
  465.             break;
  466.             case _dnl:              /* (an/pc,dn.l...   */
  467.             op->_iregtyp = 'd';
  468.             op->_inxl = TRUE;
  469.             break;
  470.             case _an:               /* (an/pc,an...        */
  471.             case _anw:              /* (an/pc,an.w...   */
  472.             op->_iregtyp = 'a';
  473.             op->_inxl = FALSE;
  474.             break;
  475.             case _anl:              /* (an/pc,an.l...   */
  476.             op->_iregtyp = 'a';
  477.             op->_inxl = TRUE;
  478.             break;
  479.             default:
  480.             return ERROR;
  481.             }
  482.             if (*p++ != ')') return ERROR;
  483.             op->_ireg = reg_num;
  484.             return (op->_regtyp    == 'a') ? _an_inx : _pc;
  485.             break;
  486.         default: return ERROR;
  487.         }
  488.         default: return ERROR;
  489.         }
  490.     default: break;     /* neither '-' or '(' */
  491.     }
  492.     --p;
  493.     switch (reg_name()) {
  494.     case NULL:
  495.         return NULL;
  496.     case _an:
  497.         op->_reg = reg_num;
  498.         op->_regtyp    = 'a';
  499.         return _an;
  500.     case _dn:
  501.         op->_reg = reg_num;
  502.         op->_regtyp    = 'd';
  503.         return _dn;
  504.     case _ccr:
  505.         op->_regtyp    = 'c';
  506.         return _ccr;
  507.     case _sr:
  508.         op->_regtyp    = 's';
  509.         return _sr;
  510.     case _usp:
  511.         op->_regtyp    = 'u';
  512.         return _usp;
  513.     case _reglst:
  514.         op->_reg_list = reg_num;
  515.         return _reglst;
  516.     case ERROR:
  517.     default:
  518.         ++p;    /* foops will backtrack...*/
  519.         return ERROR;
  520.     }
  521.     }
  522. }
  523.  
  524.  
  525. reg_name()
  526. {
  527.     register int m_offset = 0;
  528.     register FLAG list = FALSE;
  529.     register unsigned mask = 0x0001;
  530.  
  531. top:
  532.     switch (*p) {
  533.         case 'a':                       /* a...        */
  534.         case 'A':
  535.             m_offset = 8;
  536.         case 'd':                       /* d...        */
  537.         case 'D':
  538.             if( *p == 'd' || *p == 'D' ) m_offset = 0;
  539.         if (p[1] < '0' || p[1] > '7') return (list) ? ERROR : NULL;
  540.         switch (term_char(p[2])) {
  541.             case RTERM:                    /* xn        */
  542.                 p += 2;
  543.                 if(list) {
  544.                     reg_num    |= mask << ((*(p - 1) - '0') + m_offset);
  545.                     return _reglst;
  546.                 }
  547.                 reg_num = *(p - 1) -'0';
  548.                 return (m_offset) ? _an : _dn;
  549.             case SLASH:                    /* xn/...        */
  550.                 list = TRUE;
  551.                 reg_num |= mask << ((p[1] - '0') + m_offset);
  552.                 p += 3;
  553.                 if( term_char(*p) == RTERM ) return _reglst;
  554.                 goto top;
  555.             case HYPHEN:                    /* xn-...        */
  556.                 list = TRUE;
  557.                 switch (reg_range()) {
  558.                     case NULL:                  /* xn-xn        */
  559.                         p += 5;
  560.                         return _reglst;
  561.                     case _reglst:                /* xn-xn/...    */
  562.                         p += 6;
  563.                         goto top;
  564.                     case ERROR:                 /* xn-xnFAIL    */
  565.                         return ERROR;
  566.                 }
  567.             case POINT:                    /* xn....        */
  568.                 reg_num = p[1] - '0';
  569.                 p += 4;
  570.                 switch (*(p - 1)) {
  571.                     case 'l':                   /* xn.l...        */
  572.                     case 'L':
  573.                         return (m_offset) ? _anl : _dnl;
  574.                     case 'w':                   /* xn.w...        */
  575.                     case 'W':
  576.                         return (m_offset) ? _anw : _dnw;
  577.                     default:                    /* xn.FAIL        */
  578.                         return ERROR;
  579.                 }
  580.             default:    return (list) ? ERROR : NULL;   /* xnFAIL        */
  581.         }
  582.         case 'c':                       /* c...        */
  583.         case 'C':
  584.             if (p[1] != 'c' && p[1] != 'C') return NULL;/* cFAIL        */
  585.             if (p[2] != 'r' && p[2] != 'R') return NULL;/* ccFAIL        */
  586.             switch (term_char(p[3])) {
  587.                 case RTERM:                    /* ccr        */
  588.                     p += 3;
  589.                     return (list) ? ERROR : _ccr;
  590.                 case SLASH: return ERROR;            /* ccrFAIL        */
  591.                 default:    return (list) ? ERROR : NULL;   /* ccrFAIL        */
  592.             }
  593.         case 's':                       /* s...        */
  594.         case 'S':
  595.             switch (p[1]) {
  596.                 case 'r':                    /* sr...        */
  597.                 case 'R':
  598.                     switch (term_char(p[2])) {
  599.                         case RTERM:                 /* sr        */
  600.                             p += 2;
  601.                             return (list) ? ERROR : _sr;
  602.                         case SLASH: return ERROR;            /* srFAIL        */
  603.                         default:    return (list) ? ERROR : NULL;/*    srFAIL        */
  604.                     }
  605.                 case 'p':                    /* sp...        */
  606.                 case 'P':
  607.                     switch (term_char(p[2])) {
  608.                         case RTERM:                 /* sp        */
  609.                             p += 2;
  610.                             if (list) {
  611.                                 reg_num |= 0x8000;
  612.                                 return _reglst;
  613.                             }
  614.                             reg_num    = 7;
  615.                             return _an;
  616.                         case SLASH:                 /* sp/...        */
  617.                             list = TRUE;
  618.                             reg_num    |= 0x8000;
  619.                             p += 3;
  620.                             goto top;
  621.                         default:    return (list) ? ERROR : NULL;/*    spFAIL        */
  622.                     }
  623.             }
  624.         case 'u':                       /* u...        */
  625.         case 'U':
  626.             if (p[1] != 's' && p[1] != 'S') return NULL;/* uFAIL        */
  627.             if (p[2] != 'p' && p[2] != 'P') return NULL;/* usFAIL        */
  628.             switch (term_char(p[3])) {
  629.                 case RTERM:                    /* usp        */
  630.                     p += 3;
  631.                     return (list) ? ERROR : _usp;
  632.                 case SLASH: return ERROR;            /* uspFAIL        */
  633.                 default:    return (list) ? ERROR : NULL;   /* uspFAIL        */
  634.             }
  635.         case 'p':
  636.         case 'P':
  637.             if (p[1] != 'c' && p[1] != 'C') return NULL;/* pFAIL        */
  638.             switch (term_char(p[2])) {
  639.                 case RTERM:                    /* pc        */
  640.                     p += 2;
  641.                     return (list) ? ERROR : _pc;
  642.                 case SLASH: return ERROR;            /* pcFAIL        */
  643.                 default:    return (list) ? ERROR : NULL;   /* pcFAIL        */
  644.             }
  645.         default:                        /* FAIL        */
  646.             return NULL;
  647.         }
  648. }
  649.  
  650. term_char(c)
  651. char c;
  652. {
  653.     switch (c) {
  654.     case ')':
  655.     case '\t':
  656.     case ',':
  657.     case '\n':
  658.     case ' ':
  659.     return RTERM;
  660.     case '.':
  661.     return POINT;
  662.     case '/':
  663.     return SLASH;
  664.     case '-':
  665.     return HYPHEN;
  666.     default:
  667.     return NULL;
  668.     }
  669. }
  670.  
  671. reg_range()
  672. {
  673.     register int start, stop;
  674.     register unsigned mask = 0x0001;
  675.  
  676.     if (p[0] != p[3]) return ERROR;
  677.     if ((p[4] < '0') || (p[4] > '7')) return ERROR;
  678.     start = p[1] - '0';
  679.     if ((p[4] - '0') < start) {
  680.     stop = start;
  681.     start = p[4] - '0';
  682.     }
  683.     else stop = p[4] - '0';
  684.     if (p[0] == 'a'  || p[0] == 'A') {
  685.     start += 8;
  686.     stop += 8;
  687.     }
  688.     for ( ; start <= stop; ++start) {
  689.     reg_num    |= mask << start;
  690. /** aztec has problems...
  691.     if (start) reg_num |= mask << start;
  692.     else reg_num |= mask; */
  693.     }
  694.     switch (term_char(p[5])) {
  695.     case RTERM:
  696.     return NULL;
  697.     case SLASH:
  698.     return _reglst;
  699.     case HYPHEN:
  700.     return ERROR;
  701.     }
  702. }
  703.  
  704. long
  705. _dtol()
  706. {
  707.     long val = 0L;
  708.     register char c;
  709.     register int x = 0;
  710.  
  711.     while ((c = *opfld_ptr++) >= '0' && c <= '9') {
  712.     val = val * 10 + c - '0';
  713.     ++x;
  714.     }
  715.     lv = (x > 5) ? YES : NO;
  716.     --opfld_ptr;
  717.     return val;
  718. }
  719.  
  720. long
  721. _htol()
  722. {
  723.     long val = 0L;
  724.     register int i;
  725.     register char c;
  726.     register int x = 0;
  727.  
  728.     while (TRUE) {
  729.     if ((c = *opfld_ptr++) >= '0' && c <= '9') {
  730.         i = c - '0';
  731.     }
  732.     else if ((c = tolower(c)) >= 'a' && c <= 'f') {
  733.         i = (c - 'a') + 10;
  734.     }
  735.     else {
  736.         lv = (x > 4) ? YES : NO;
  737.         --opfld_ptr;
  738.         return val;
  739.     }
  740.     val = val * 16 + i;
  741.     ++x;
  742.     }
  743. }
  744.  
  745. long
  746. _btol()
  747. {
  748.     long val = 0L;
  749.     register char c;
  750.  
  751.     while ((c = *opfld_ptr++) >= '0' && c <= '1')
  752.     val = val * 2 + c - '0';
  753.     --opfld_ptr;
  754.     return val;
  755. }
  756.  
  757. long
  758. _actol()
  759. {
  760.     register int x;
  761.     long val = 0L;
  762.  
  763.     for (x = 4; x; --x) {
  764.     if (*opfld_ptr == '\'') {
  765.         ++opfld_ptr;            /* pass it */
  766.         if (*opfld_ptr != '\'') {       /* end of ascii str */
  767.         return val;
  768.         }
  769.     }
  770.     val = val * 256 + *opfld_ptr++;
  771.     }
  772.     if (*opfld_ptr != '\'') return ERROR;
  773.     ++opfld_ptr;
  774.     return val;
  775. }
  776.  
  777. /*
  778. #undef RTERM
  779. #undef SLASH
  780. #undef HYPHEN
  781. #undef PLUS
  782. #undef MINUS
  783. #undef MULT
  784. #undef DIV
  785. #undef LAND
  786. #undef LOR
  787. #undef LSHIFT
  788. #undef RSHIFT
  789. #undef NEGATE
  790. #undef PC_VALUE
  791. #undef IMD
  792. #undef LP
  793. #undef RP
  794. #undef COMMA
  795. #undef POINT
  796. #undef VALUE
  797. #undef LIM_C
  798. #undef LM_C
  799.  
  800. */
  801.  
  802.  
  803.