- /* Find a token. */
- for (;;)
- {
- if (NULL == lexer->prog && ! lex_get_line (lexer) )
- {
- lexer->token = T_STOP;
- return;
- }
-
- /* If a token was pushed ahead, return it. */
- if (lexer->put_token)
- {
- restore_token (lexer);
- return;
- }
-
- for (;;)
- {
- /* Skip whitespace. */
- while (c_isspace ((unsigned char) *lexer->prog))
- lexer->prog++;
-
- if (*lexer->prog)
- break;
-
- if (lexer->dot)
- {
- lexer->dot = 0;
- lexer->token = T_ENDCMD;
- return;
- }
- else if (!lex_get_line (lexer))
- {
- lexer->prog = NULL;
- lexer->token = T_STOP;
- return;
- }
-
- if (lexer->put_token)
- {
- restore_token (lexer);
- return;
- }
- }
-
-
- /* Actually parse the token. */
- ds_clear (&lexer->tokstr);
-
- switch (*lexer->prog)
- {
- case '-': case '.':
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- {
- char *tail;
-
- /* `-' can introduce a negative number, or it can be a
- token by itself. If it is not followed by a digit or a
- decimal point, it is definitely not a number.
- Otherwise, it might be either, but most of the time we
- want it as a number. When the syntax calls for a `-'
- token, lex_negative_to_dash() must be used to break
- negative numbers into two tokens. */
- if (*lexer->prog == '-')
- {
- ds_put_byte (&lexer->tokstr, *lexer->prog++);
- while (c_isspace ((unsigned char) *lexer->prog))
- lexer->prog++;
-
- if (!c_isdigit ((unsigned char) *lexer->prog) && *lexer->prog != '.')
- {
- lexer->token = T_DASH;
- break;
- }
- lexer->token = T_NEG_NUM;
- }
- else
- lexer->token = T_POS_NUM;
-
- /* Parse the number, copying it into tokstr. */
- while (c_isdigit ((unsigned char) *lexer->prog))
- ds_put_byte (&lexer->tokstr, *lexer->prog++);
- if (*lexer->prog == '.')
- {
- ds_put_byte (&lexer->tokstr, *lexer->prog++);
- while (c_isdigit ((unsigned char) *lexer->prog))
- ds_put_byte (&lexer->tokstr, *lexer->prog++);
- }
- if (*lexer->prog == 'e' || *lexer->prog == 'E')
- {
- ds_put_byte (&lexer->tokstr, *lexer->prog++);
- if (*lexer->prog == '+' || *lexer->prog == '-')
- ds_put_byte (&lexer->tokstr, *lexer->prog++);
- while (c_isdigit ((unsigned char) *lexer->prog))
- ds_put_byte (&lexer->tokstr, *lexer->prog++);
- }
-
- /* Parse as floating point. */
- lexer->tokval = c_strtod (ds_cstr (&lexer->tokstr), &tail);
- if (*tail)
- {
- msg (SE, _("%s does not form a valid number."),
- ds_cstr (&lexer->tokstr));
- lexer->tokval = 0.0;
-
- ds_clear (&lexer->tokstr);
- ds_put_byte (&lexer->tokstr, '0');
- }
-
- break;
- }
-
- case '\'': case '"':
- lexer->token = parse_string (lexer, CHARACTER_STRING);
- break;
-
- case '+':
- lexer->token = T_PLUS;
- lexer->prog++;
- break;
-
- case '/':
- lexer->token = T_SLASH;
- lexer->prog++;
- break;
-
- case '=':
- lexer->token = T_EQUALS;
- lexer->prog++;
- break;
-
- case '(':
- lexer->token = T_LPAREN;
- lexer->prog++;
- break;