/[pspp]/pspp/src/lexer.c
ViewVC logotype

Diff of /pspp/src/lexer.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by jmd, Fri Nov 19 06:06:22 2004 UTC revision 1.13 by blp, Mon Mar 7 03:04:50 2005 UTC
# Line 44  Line 44 
44  /* Current token. */  /* Current token. */
45  int token;  int token;
46    
47  /* T_NUM: the token's value. */  /* T_POS_NUM, T_NEG_NUM: the token's value. */
48  double tokval;  double tokval;
49    
50  /* T_ID: the identifier. */  /* T_ID: the identifier. */
# Line 224  lex_get (void) Line 224  lex_get (void)
224                      token = '-';                      token = '-';
225                      break;                      break;
226                    }                    }
227                    token = T_NEG_NUM;
228                }                }
229                else
230                  token = T_POS_NUM;
231                    
232              /* Parse the number, copying it into tokstr. */              /* Parse the number, copying it into tokstr. */
233              while (isdigit ((unsigned char) *prog))              while (isdigit ((unsigned char) *prog))
234                ds_putc (&tokstr, *prog++);                ds_putc (&tokstr, *prog++);
# Line 256  lex_get (void) Line 259  lex_get (void)
259                  ds_putc (&tokstr, '0');                  ds_putc (&tokstr, '0');
260                }                }
261    
             token = T_NUM;  
262              break;              break;
263            }            }
264    
# Line 425  lex_end_of_command (void) Line 427  lex_end_of_command (void)
427    
428  /* Token testing functions. */  /* Token testing functions. */
429    
430  /* Returns nonzero if the current token is an integer. */  /* Returns true if the current token is a number. */
431  int  bool
432  lex_integer_p (void)  lex_is_number (void)
433    {
434      return token == T_POS_NUM || token == T_NEG_NUM;
435    }
436    
437    /* Returns the value of the current token, which must be a
438       floating point number. */
439    double
440    lex_number (void)
441    {
442      assert (lex_is_number ());
443      return tokval;
444    }
445    
446    /* Returns true iff the current token is an integer. */
447    bool
448    lex_is_integer (void)
449  {  {
450    return (token == T_NUM    return (lex_is_number ()
451            && tokval != NOT_LONG            && tokval != NOT_LONG
452            && tokval >= LONG_MIN            && tokval >= LONG_MIN
453            && tokval <= LONG_MAX            && tokval <= LONG_MAX
# Line 441  lex_integer_p (void) Line 459  lex_integer_p (void)
459  long  long
460  lex_integer (void)  lex_integer (void)
461  {  {
462    assert (lex_integer_p ());    assert (lex_is_integer ());
463    return tokval;    return tokval;
464  }  }
 /* Returns nonzero if the current token is an floating point. */  
 int  
 lex_double_p (void)  
 {  
   return ( token == T_NUM  
            && tokval != NOT_DOUBLE );  
 }  
   
 /* Returns the value of the current token, which must be a  
    floating point number. */  
 double  
 lex_double (void)  
 {  
   assert (lex_double_p ());  
   return tokval;  
 }  
   
465        
466  /* Token matching functions. */  /* Token matching functions. */
467    
# Line 498  lex_match_id (const char *s) Line 499  lex_match_id (const char *s)
499  int  int
500  lex_match_int (int x)  lex_match_int (int x)
501  {  {
502    if (lex_integer_p () && lex_integer () == x)    if (lex_is_integer () && lex_integer () == x)
503      {      {
504        lex_get ();        lex_get ();
505        return 1;        return 1;
# Line 563  lex_force_string (void) Line 564  lex_force_string (void)
564  int  int
565  lex_force_int (void)  lex_force_int (void)
566  {  {
567    if (lex_integer_p ())    if (lex_is_integer ())
568      return 1;      return 1;
569    else    else
570      {      {
# Line 577  lex_force_int (void) Line 578  lex_force_int (void)
578  int  int
579  lex_force_num (void)  lex_force_num (void)
580  {  {
581    if (token == T_NUM)    if (lex_is_number ())
582      return 1;      return 1;
583    else    else
584      {      {
# Line 877  lex_token_representation (void) Line 878  lex_token_representation (void)
878    switch (token)    switch (token)
879      {      {
880      case T_ID:      case T_ID:
881      case T_NUM:      case T_POS_NUM:
882        case T_NEG_NUM:
883        return xstrdup (ds_c_str (&tokstr));        return xstrdup (ds_c_str (&tokstr));
884        break;        break;
885    
# Line 952  lex_token_representation (void) Line 954  lex_token_representation (void)
954  void  void
955  lex_negative_to_dash (void)  lex_negative_to_dash (void)
956  {  {
957    if (token == T_NUM && tokval < 0.0)    if (token == T_NEG_NUM)
958      {      {
959        token = T_NUM;        token = T_POS_NUM;
960        tokval = -tokval;        tokval = -tokval;
961        ds_replace (&tokstr, ds_c_str (&tokstr) + 1);        ds_replace (&tokstr, ds_c_str (&tokstr) + 1);
962        save_token ();        save_token ();
# Line 1216  dump_token (void) Line 1218  dump_token (void)
1218        fprintf (stderr, "ID\t%s\n", tokid);        fprintf (stderr, "ID\t%s\n", tokid);
1219        break;        break;
1220    
1221      case T_NUM:      case T_POS_NUM:
1222        case T_NEG_NUM:
1223        fprintf (stderr, "NUM\t%f\n", tokval);        fprintf (stderr, "NUM\t%f\n", tokval);
1224        break;        break;
1225    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26