home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / indent / lexi.c < prev    next >
C/C++ Source or Header  |  1999-06-11  |  20KB  |  743 lines

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