home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / indent-1.9.1-base.tgz / indent-1.9.1-base.tar / fsf / indent / lexi.c < prev    next >
C/C++ Source or Header  |  1994-01-29  |  20KB  |  749 lines

  1. /* Copyright (c) 1994, Joseph Arceneaux.  All rights reserved
  2.  
  3.    Copyright (c) 1992, Free Software Foundation, Inc.  All rights reserved.
  4.  
  5.    Copyright (c) 1985 Sun Microsystems, Inc. Copyright (c) 1980 The Regents
  6.    of the University of California. Copyright (c) 1976 Board of Trustees of
  7.    the University of Illinois. All rights reserved.
  8.  
  9.    Redistribution and use in source and binary forms are permitted
  10.    provided that
  11.    the above copyright notice and this paragraph are duplicated in all such
  12.    forms and that any documentation, advertising materials, and other
  13.    materials related to such distribution and use acknowledge that the
  14.    software was developed by the University of California, Berkeley, the
  15.    University of Illinois, Urbana, and Sun Microsystems, Inc.  The name of
  16.    either University or Sun Microsystems may not be used to endorse or
  17.    promote products derived from this software without specific prior written
  18.    permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  19.    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
  20.    OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
  21.  
  22.  
  23. /* Here we have the token scanner for indent.  It scans off one token and
  24.    puts it in the global variable "token".  It returns a code, indicating the
  25.    type of token scanned. */
  26.  
  27. #include "sys.h"
  28. #include "indent.h"
  29. #include <ctype.h>
  30.  
  31. /* Stuff that needs to be shared with the rest of indent. Documented in
  32.    indent.h.  */
  33. char *token;
  34. char *token_end;
  35.  
  36. #define alphanum 1
  37. #define opchar 3
  38.  
  39. struct templ
  40. {
  41.   char *rwd;
  42.   enum rwcodes rwcode;
  43. };
  44.  
  45. /* Pointer to a vector of keywords specified by the user.  */
  46. static struct templ *user_specials = 0;
  47.  
  48. /* Allocated size of user_specials.  */
  49. static unsigned int user_specials_max;
  50.  
  51. /* Index in user_specials of the first unused entry.  */
  52. static unsigned int user_specials_idx;
  53.  
  54. char chartype[128] =
  55. {                /* this is used to facilitate the decision of
  56.                    what type (alphanumeric, operator) each
  57.                    character is */
  58.   0, 0, 0, 0, 0, 0, 0, 0,
  59.   0, 0, 0, 0, 0, 0, 0, 0,
  60.   0, 0, 0, 0, 0, 0, 0, 0,
  61.   0, 0, 0, 0, 0, 0, 0, 0,
  62.   0, 3, 0, 0, 1, 3, 3, 0,
  63.   0, 0, 3, 3, 0, 3, 0, 3,
  64.   1, 1, 1, 1, 1, 1, 1, 1,
  65.   1, 1, 0, 0, 3, 3, 3, 3,
  66.   0, 1, 1, 1, 1, 1, 1, 1,
  67.   1, 1, 1, 1, 1, 1, 1, 1,
  68.   1, 1, 1, 1, 1, 1, 1, 1,
  69.   1, 1, 1, 0, 0, 0, 3, 1,
  70.   0, 1, 1, 1, 1, 1, 1, 1,
  71.   1, 1, 1, 1, 1, 1, 1, 1,
  72.   1, 1, 1, 1, 1, 1, 1, 1,
  73.   1, 1, 1, 0, 3, 0, 3, 0
  74. };
  75.  
  76. /* C code produced by gperf version 2.0 (K&R C version)
  77.    Command-line:
  78.    gperf -c -p -t -T -g -j1 -o -K rwd -N is_reserved indent.gperf  */
  79.  
  80. #define MIN_WORD_LENGTH 2
  81. #define MAX_WORD_LENGTH 8
  82. #define MIN_HASH_VALUE 4
  83. #define MAX_HASH_VALUE 42
  84.  
  85. /* 31 keywords. 39 is the maximum key range */
  86.  
  87. INLINE
  88. static int
  89. hash (str, len)
  90.      register char *str;
  91.      register unsigned int  len;
  92. {
  93.   static unsigned char hash_table[] =
  94.     {
  95.      42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
  96.      42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
  97.      42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
  98.      42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
  99.      42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
  100.      42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
  101.      42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
  102.      42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
  103.      42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
  104.      42, 42, 42, 42, 42, 42, 42, 42,  6,  9,
  105.      10,  0, 16,  5,  4, 24, 42,  0, 20,  4,
  106.      20,  0, 42, 42,  6,  0,  0, 10, 10,  2,
  107.      42, 42, 42, 42, 42, 42, 42, 42,
  108.     };
  109.   return len + hash_table[str[len - 1]] + hash_table[str[0]];
  110. }
  111.  
  112.  
  113. INLINE
  114. struct templ*
  115. is_reserved (str, len)
  116.      register char *str;
  117.      register unsigned int len;
  118. {
  119.  
  120.   static struct templ wordlist[] =
  121.     {
  122.       {"",}, {"",}, {"",}, {"",}, 
  123.       {"else",  rw_sp_nparen,},
  124.       {"short",  rw_decl,},
  125.       {"struct",  rw_struct_like,},
  126.       {"while",  rw_sp_paren,},
  127.       {"enum",  rw_struct_like,},
  128.       {"goto",  rw_break,},
  129.       {"switch",  rw_switch,},
  130.       {"break",  rw_break,},
  131.       {"do",  rw_sp_nparen,},
  132.       {"case",  rw_case,},
  133.       {"const",  rw_decl,},
  134.       {"static",  rw_decl,},
  135.       {"double",  rw_decl,},
  136.       {"default",  rw_case,},
  137.       {"volatile",  rw_decl,},
  138.       {"char",  rw_decl,},
  139.       {"register",  rw_decl,},
  140.       {"float",  rw_decl,},
  141.       {"sizeof",  rw_sizeof,},
  142.       {"typedef",  rw_decl,},
  143.       {"void",  rw_decl,},
  144.       {"for",  rw_sp_paren,},
  145.       {"extern",  rw_decl,},
  146.       {"int",  rw_decl,},
  147.       {"unsigned",  rw_decl,},
  148.       {"long",  rw_decl,},
  149.       {"",}, 
  150.       {"global",  rw_decl,},
  151.       {"return",  rw_return,},
  152.       {"",}, {"",}, 
  153.       {"union",  rw_struct_like,},
  154.       {"va_dcl",  rw_decl,},
  155.       {"",}, {"",}, {"",}, {"",}, {"",}, 
  156.       {"if",  rw_sp_paren,},
  157.     };
  158.  
  159.   if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
  160.     {
  161.       register int key = hash (str, len);
  162.  
  163.       if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
  164.         {
  165.           register char *s = wordlist[key].rwd;
  166.  
  167.           if (*s == *str && !strncmp (str + 1, s + 1, len - 1))
  168.             return &wordlist[key];
  169.         }
  170.     }
  171.   return 0;
  172. }
  173.  
  174. extern int squest;
  175.  
  176. enum codes
  177. lexi ()
  178. {
  179.   int unary_delim;        /* this is set to 1 if the current token
  180.                    forces a following operator to be unary */
  181.   static enum codes last_code;    /* the last token type returned */
  182.   static int l_struct;        /* set to 1 if the last token was 'struct' */
  183.   enum codes code;        /* internal code to be returned */
  184.   char qchar;            /* the delimiter character for a string */
  185.  
  186.   unary_delim = false;
  187.   /* tell world that this token started in column 1 iff the last
  188.      thing scanned was nl */
  189.   parser_state_tos->col_1 = parser_state_tos->last_nl;
  190.   parser_state_tos->last_nl = false;
  191.  
  192.   while (*buf_ptr == ' ' || *buf_ptr == TAB)
  193.     {                /* get rid of blanks */
  194.       parser_state_tos->col_1 = false;    /* leading blanks imply token is not
  195.                        in column 1 */
  196.       if (++buf_ptr >= buf_end)
  197.     fill_buffer ();
  198.     }
  199.  
  200.   token = buf_ptr;
  201.  
  202.   /* Scan an alphanumeric token */
  203.   if (chartype[*buf_ptr] == alphanum
  204.       || (buf_ptr[0] == '.' && isdigit (buf_ptr[1])))
  205.     {
  206.       /* we have a character or number */
  207.       register struct templ *p;
  208.  
  209.       if (isdigit (*buf_ptr) || (buf_ptr[0] == '.' && isdigit (buf_ptr[1])))
  210.     {
  211.       int seendot = 0, seenexp = 0;
  212.       if (*buf_ptr == '0' &&
  213.           (buf_ptr[1] == 'x' || buf_ptr[1] == 'X'))
  214.         {
  215.           buf_ptr += 2;
  216.           while (isxdigit (*buf_ptr))
  217.         buf_ptr++;
  218.         }
  219.       else
  220.         while (1)
  221.           {
  222.         if (*buf_ptr == '.')
  223.           if (seendot)
  224.             break;
  225.           else
  226.             seendot++;
  227.         buf_ptr++;
  228.         if (!isdigit (*buf_ptr) && *buf_ptr != '.')
  229.           if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp)
  230.             break;
  231.           else
  232.             {
  233.               seenexp++;
  234.               seendot++;
  235.               buf_ptr++;
  236.               if (*buf_ptr == '+' || *buf_ptr == '-')
  237.             buf_ptr++;
  238.             }
  239.           }
  240.       /* Accept unsigned, unsigned long, and float constants
  241.          (U, UL, and F suffixes).  I'm not sure if LU is ansii.
  242.          11Jun93 - rdh@key.amdahl.com tells me LL and ULL are also
  243.          acceptable. */
  244.       if (*buf_ptr == 'F' || *buf_ptr == 'f')
  245.         buf_ptr++;
  246.       else
  247.         {
  248.           if (*buf_ptr == 'U' || *buf_ptr == 'u')
  249.         buf_ptr++;
  250.           if (*buf_ptr == 'L' || *buf_ptr == 'l')
  251.         buf_ptr++;
  252.           if (*buf_ptr == 'L' || *buf_ptr == 'l')
  253.         buf_ptr++;
  254.         }
  255.     }
  256.       else
  257.     while (chartype[*buf_ptr] == alphanum)
  258.       {            /* copy it over */
  259.         buf_ptr++;
  260.         if (buf_ptr >= buf_end)
  261.           fill_buffer ();
  262.       }
  263.       token_end = buf_ptr;
  264.       while (*buf_ptr == ' ' || *buf_ptr == TAB)
  265.     {
  266.       if (++buf_ptr >= buf_end)
  267.         fill_buffer ();
  268.     }
  269.       parser_state_tos->its_a_keyword = false;
  270.       parser_state_tos->sizeof_keyword = false;
  271.  
  272.       /* if last token was 'struct', then this token should be treated
  273.      as a declaration */
  274.       if (l_struct)
  275.     {
  276.       l_struct = false;
  277.       last_code = ident;
  278.       parser_state_tos->last_u_d = true;
  279.       return (decl);
  280.     }
  281.  
  282.       /* Operator after indentifier is binary */
  283.       parser_state_tos->last_u_d = false;
  284.       last_code = ident;
  285.  
  286.       /* Check whether the token is a reserved word.  Use perfect hashing... */
  287.       p = is_reserved (token, token_end - token);
  288.  
  289.       if (!p && user_specials != 0)
  290.     {
  291.       for (p = &user_specials[0];
  292.            p < &user_specials[0] + user_specials_idx;
  293.            p++)
  294.         {
  295.           char *q = token;
  296.           char *r = p->rwd;
  297.  
  298.           /* This string compare is a little nonstandard because token
  299.              ends at the character before token_end and p->rwd is
  300.              null-terminated.  */
  301.           while (1)
  302.         {
  303.           /* If we have come to the end of both the keyword in
  304.              user_specials and the keyword in token they are equal.  */
  305.           if (q >= token_end && !*r)
  306.             goto found_keyword;
  307.  
  308.           /* If we have come to the end of just one, they are not
  309.              equal.  */
  310.           if (q >= token_end || !*r)
  311.             break;
  312.  
  313.           /* If the characters in corresponding characters are not
  314.              equal, the strings are not equal.  */
  315.           if (*q++ != *r++)
  316.             break;
  317.         }
  318.         }
  319.       /* Didn't find anything in user_specials.  */
  320.       p = 0;
  321.     }
  322.  
  323.       if (p)
  324.     {            /* we have a keyword */
  325.     found_keyword:
  326.       parser_state_tos->its_a_keyword = true;
  327.       parser_state_tos->last_u_d = true;
  328.       parser_state_tos->last_rw = p->rwcode;
  329.       switch (p->rwcode)
  330.         {
  331.         case rw_switch:    /* it is a switch */
  332.           return (swstmt);
  333.         case rw_case:    /* a case or default */
  334.           return (casestmt);
  335.  
  336.         case rw_struct_like:    /* a "struct" */
  337.           if (parser_state_tos->p_l_follow
  338.           && !(parser_state_tos->noncast_mask
  339.                & 1 << parser_state_tos->p_l_follow))
  340.         /* inside parens: cast */
  341.         {
  342.           parser_state_tos->cast_mask
  343.             |= 1 << parser_state_tos->p_l_follow;
  344.           break;
  345.         }
  346.           l_struct = true;
  347.  
  348.           /* Next time around, we will want to know that we have had a
  349.              'struct' */
  350.         case rw_decl:    /* one of the declaration keywords */
  351.           if (parser_state_tos->p_l_follow
  352.           && !(parser_state_tos->noncast_mask
  353.                & 1 << parser_state_tos->p_l_follow))
  354.         /* inside parens: cast */
  355.         {
  356.           parser_state_tos->cast_mask
  357.             |= 1 << parser_state_tos->p_l_follow;
  358.           break;
  359.         }
  360.           last_code = decl;
  361.           return (decl);
  362.  
  363.         case rw_sp_paren:    /* if, while, for */
  364.           return (sp_paren);
  365.  
  366.         case rw_sp_nparen:    /* do, else */
  367.           return (sp_nparen);
  368.  
  369.         case rw_sizeof:
  370.           parser_state_tos->sizeof_keyword = true;
  371.           return (ident);
  372.  
  373.         case rw_return:
  374.         case rw_break:
  375.         default:        /* all others are treated like any other
  376.                    identifier */
  377.           return (ident);
  378.         }            /* end of switch */
  379.     }            /* end of if (found_it) */
  380.  
  381.       if (*buf_ptr == '('
  382.       && parser_state_tos->tos <= 1
  383.       && parser_state_tos->ind_level == 0
  384.       && parser_state_tos->paren_depth == 0)
  385.     {
  386.       /* We have found something which might be the name in a function
  387.          definition.  */
  388.       register char *tp;
  389.       int paren_count = 1;
  390.  
  391.       /* Skip to the matching ')'.  */
  392.       for (tp = buf_ptr + 1;
  393.            paren_count > 0 && tp < in_prog + in_prog_size;
  394.            tp++)
  395.         {
  396.           if (*tp == '(')
  397.         paren_count++;
  398.           if (*tp == ')')
  399.         paren_count--;
  400.           /* Can't occur in parameter list; this way we don't search the
  401.              whole file in the case of unbalanced parens.  */
  402.           if (*tp == ';')
  403.         goto not_proc;
  404.         }
  405.  
  406.       if (paren_count == 0)
  407.         {
  408.           while (isspace (*tp))
  409.         tp++;
  410.           /* If the next char is ';' or ',' or '(' we have a function
  411.              declaration, not a definition.
  412.  
  413.          I've added '=' to this list to keep from breaking
  414.          a non-valid C macro from libc.  -jla */
  415.           if (*tp != ';' && *tp != ',' && *tp != '(' && *tp != '=')
  416.         {
  417.           parser_state_tos->procname = token;
  418.           parser_state_tos->procname_end = token_end;
  419.           parser_state_tos->in_parameter_declaration = 1;
  420.         }
  421.         }
  422.  
  423.     not_proc:;
  424.     }
  425.  
  426.       /* The following hack attempts to guess whether or not the
  427.      current token is in fact a declaration keyword -- one that
  428.      has been typedef'd */
  429.       if (((*buf_ptr == '*' && buf_ptr[1] != '=')
  430.        || isalpha (*buf_ptr) || *buf_ptr == '_')
  431.       && !parser_state_tos->p_l_follow
  432.       && !parser_state_tos->block_init
  433.       && (parser_state_tos->last_token == rparen
  434.           || parser_state_tos->last_token == semicolon
  435.           || parser_state_tos->last_token == decl
  436.           || parser_state_tos->last_token == lbrace
  437.           || parser_state_tos->last_token == rbrace))
  438.     {
  439.       parser_state_tos->its_a_keyword = true;
  440.       parser_state_tos->last_u_d = true;
  441.       last_code = decl;
  442.       return decl;
  443.     }
  444.  
  445.       if (last_code == decl)    /* if this is a declared variable, then
  446.                    following sign is unary */
  447.     parser_state_tos->last_u_d = true;    /* will make "int a -1" work */
  448.       last_code = ident;
  449.       return (ident);        /* the ident is not in the list */
  450.     }                /* end of procesing for alpanum character */
  451.   /* Scan a non-alphanumeric token */
  452.  
  453.   /* If it is not a one character token, token_end will get changed later.  */
  454.   token_end = buf_ptr + 1;
  455.  
  456.   if (++buf_ptr >= buf_end)
  457.     fill_buffer ();
  458.  
  459.   switch (*token)
  460.     {
  461.     case '\0':
  462.       code = code_eof;
  463.       break;
  464.  
  465.     case EOL:
  466.       unary_delim = parser_state_tos->last_u_d;
  467.       parser_state_tos->last_nl = true;
  468.       code = newline;
  469.       break;
  470.  
  471.     case '\'':            /* start of quoted character */
  472.     case '"':            /* start of string */
  473.       qchar = *token;
  474.  
  475.       /* Find out how big the literal is so we can set token_end.  */
  476.  
  477.       /* Invariant:  before loop test buf_ptr points to the next */
  478.       /* character that we have not yet checked. */
  479.       while (*buf_ptr != qchar && *buf_ptr != 0 && *buf_ptr != EOL)
  480.     {
  481.       if (*buf_ptr == '\\')
  482.         {
  483.           buf_ptr++;
  484.           if (buf_ptr >= buf_end)
  485.         fill_buffer ();
  486.           if (*buf_ptr == EOL)
  487.         ++line_no;
  488.           if (*buf_ptr == 0)
  489.         break;
  490.         }
  491.       buf_ptr++;
  492.       if (buf_ptr >= buf_end)
  493.         fill_buffer ();
  494.     }
  495.       if (*buf_ptr == EOL || *buf_ptr == 0)
  496.     {
  497.       diag (1, (qchar == '\''
  498.             ? "Unterminated character constant"
  499.             : "Unterminated string constant"),
  500.         0, 0);
  501.     }
  502.       else
  503.     {
  504.       /* Advance over end quote char.  */
  505.       buf_ptr++;
  506.       if (buf_ptr >= buf_end)
  507.         fill_buffer ();
  508.     }
  509.  
  510.       code = ident;
  511.       break;
  512.  
  513.     case ('('):
  514.     case ('['):
  515.       unary_delim = true;
  516.       code = lparen;
  517.       break;
  518.  
  519.     case (')'):
  520.     case (']'):
  521.       code = rparen;
  522.       break;
  523.  
  524.     case '#':
  525.       unary_delim = parser_state_tos->last_u_d;
  526.       code = preesc;
  527.       break;
  528.  
  529.     case '?':
  530.       unary_delim = true;
  531.       code = question;
  532.       break;
  533.  
  534.     case (':'):
  535.       code = colon;
  536.       unary_delim = true;
  537.       if (squest && *e_com != ' ')
  538.     {
  539.       if (e_code == s_code)
  540.         parser_state_tos->want_blank = false;
  541.       else
  542.         parser_state_tos->want_blank = true;
  543.     }
  544.       break;
  545.  
  546.     case (';'):
  547.       unary_delim = true;
  548.       code = semicolon;
  549.       break;
  550.  
  551.     case ('{'):
  552.       unary_delim = true;
  553.  
  554.       /* This check is made in the code for '='.  No one who writes
  555.          initializers without '=' these days deserves to have indent work on
  556.          their code (besides which, uncommenting this would screw up anything
  557.          which assumes that parser_state_tos->block_init really means you are
  558.          in an initializer.  */
  559.       /* if (parser_state_tos->in_or_st) parser_state_tos->block_init = 1; */
  560.  
  561.       /* The following neat hack causes the braces in structure
  562.          initializations to be treated as parentheses, thus causing
  563.          initializations to line up correctly, e.g. struct foo bar = {{a, b,
  564.          c}, {1, 2}}; If lparen is returned, token can be used to distinguish
  565.          between '{' and '(' where necessary.  */
  566.  
  567.       code = parser_state_tos->block_init ? lparen : lbrace;
  568.       break;
  569.  
  570.     case ('}'):
  571.       unary_delim = true;
  572.       /* The following neat hack is explained under '{' above.  */
  573.       code = parser_state_tos->block_init ? rparen : rbrace;
  574.  
  575.       break;
  576.  
  577.     case 014:            /* a form feed */
  578.       unary_delim = parser_state_tos->last_u_d;
  579.       parser_state_tos->last_nl = true;    /* remember this so we can set
  580.                        'parser_state_tos->col_1' right */
  581.       code = form_feed;
  582.       break;
  583.  
  584.     case (','):
  585.       unary_delim = true;
  586.       code = comma;
  587.       break;
  588.  
  589.     case '.':
  590.       unary_delim = false;
  591.       code = period;
  592.       break;
  593.  
  594.     case '-':
  595.     case '+':            /* check for -, +, --, ++ */
  596.       code = (parser_state_tos->last_u_d ? unary_op : binary_op);
  597.       unary_delim = true;
  598.  
  599.       if (*buf_ptr == token[0])
  600.     {
  601.       /* check for doubled character */
  602.       buf_ptr++;
  603.       /* buffer overflow will be checked at end of loop */
  604.       if (last_code == ident || last_code == rparen)
  605.         {
  606.           code = (parser_state_tos->last_u_d ? unary_op : postop);
  607.           /* check for following ++ or -- */
  608.           unary_delim = false;
  609.         }
  610.     }
  611.       else if (*buf_ptr == '=')
  612.     /* check for operator += */
  613.     buf_ptr++;
  614.       else if (*buf_ptr == '>')
  615.     {
  616.       /* check for operator -> */
  617.       buf_ptr++;
  618.       if (!pointer_as_binop)
  619.         {
  620.           unary_delim = false;
  621.           code = unary_op;
  622.           parser_state_tos->want_blank = false;
  623.         }
  624.     }
  625.       break;            /* buffer overflow will be checked at end of
  626.                    switch */
  627.  
  628.     case '=':
  629.       if (parser_state_tos->in_or_st)
  630.     parser_state_tos->block_init = 1;
  631.  
  632.       if (*buf_ptr == '=')    /* == */
  633.     buf_ptr++;
  634.       else if (*buf_ptr == '-'
  635.            || *buf_ptr == '+'
  636.            || *buf_ptr == '*'
  637.            || *buf_ptr == '&')
  638.     {
  639.       /* Something like x=-1, which can mean x -= 1 ("old style" in K&R1)
  640.          or x = -1 (ANSI).  Note that this is only an ambiguity if the
  641.          character can also be a unary operator.  If not, just produce
  642.          output code that produces a syntax error (the theory being that
  643.          people want to detect and eliminate old style assignments but
  644.          they don't want indent to silently change the meaning of their
  645.          code).  */
  646.       diag (0,
  647.       "old style assignment ambiguity in \"=%c\".  Assuming \"= %c\"\n",
  648.         (int) *buf_ptr, (int) *buf_ptr);
  649.     }
  650.  
  651.       code = binary_op;
  652.       unary_delim = true;
  653.       break;
  654.       /* can drop thru!!! */
  655.  
  656.     case '>':
  657.     case '<':
  658.     case '!':
  659.       /* ops like <, <<, <=, !=, <<=, etc */
  660.       /* This will of course scan sequences like "<=>", "!=>", "<<>", etc. as
  661.          one token, but I don't think that will cause any harm.  */
  662.       while (*buf_ptr == '>' || *buf_ptr == '<' || *buf_ptr == '=')
  663.     {
  664.       if (++buf_ptr >= buf_end)
  665.         fill_buffer ();
  666.       if (*buf_ptr == '=')
  667.         {
  668.           if (++buf_ptr >= buf_end)
  669.         fill_buffer ();
  670.         }
  671.     }
  672.  
  673.       code = (parser_state_tos->last_u_d ? unary_op : binary_op);
  674.       unary_delim = true;
  675.       break;
  676.  
  677.     default:
  678.       if (token[0] == '/' && (*buf_ptr == '*' || *buf_ptr == '/'))
  679.     {
  680.       /* A C or C++ comment */
  681.  
  682.       if (*buf_ptr == '*')
  683.         code = comment;
  684.       else
  685.         code = cplus_comment;
  686.  
  687.       if (++buf_ptr >= buf_end)
  688.         fill_buffer ();
  689.  
  690.       unary_delim = parser_state_tos->last_u_d;
  691.       break;
  692.     }
  693.  
  694.       while (*(buf_ptr - 1) == *buf_ptr || *buf_ptr == '=')
  695.     {
  696.       /* handle ||, &&, etc, and also things as in int *****i */
  697.       if (++buf_ptr >= buf_end)
  698.         fill_buffer ();
  699.     }
  700.       code = (parser_state_tos->last_u_d ? unary_op : binary_op);
  701.       unary_delim = true;
  702.  
  703.  
  704.     }                /* end of switch */
  705.  
  706.   if (code != newline)
  707.     {
  708.       l_struct = false;
  709.       last_code = code;
  710.     }
  711.   token_end = buf_ptr;
  712.   if (buf_ptr >= buf_end)    /* check for input buffer empty */
  713.     fill_buffer ();
  714.   parser_state_tos->last_u_d = unary_delim;
  715.  
  716.   return (code);
  717. }
  718.  
  719. /* Add the given keyword to the keyword table, using val as the keyword type */
  720. addkey (key, val)
  721.      char *key;
  722.      enum rwcodes val;
  723. {
  724.   register struct templ *p;
  725.  
  726.   /* Check to see whether key is a reserved word or not. */
  727.   if (is_reserved (key, strlen (key)) != 0)
  728.     return;
  729.  
  730.   if (user_specials == 0)
  731.     {
  732.       user_specials = (struct templ *) xmalloc (5 * sizeof (struct templ));
  733.       user_specials_max = 5;
  734.       user_specials_idx = 0;
  735.     }
  736.   else if (user_specials_idx == user_specials_max)
  737.     {
  738.       user_specials_max += 5;
  739.       user_specials = (struct templ *) xrealloc ((char *) user_specials,
  740.                          user_specials_max
  741.                          * sizeof (struct templ));
  742.     }
  743.  
  744.   p = &user_specials[user_specials_idx++];
  745.   p->rwd = key;
  746.   p->rwcode = val;
  747.   return;
  748. }
  749.