examples: bistro: don't be lazy with switch

* examples/c/bistromathic/parse.y (yylex): Use the switch to
discriminate all the cases.
This commit is contained in:
Akim Demaille
2020-04-14 07:59:51 +02:00
parent 758172a8b9
commit fc18b4313a

View File

@@ -235,11 +235,12 @@ yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc)
case '(': return TOK_LPAREN; case '(': return TOK_LPAREN;
case ')': return TOK_RPAREN; case ')': return TOK_RPAREN;
case 0: return TOK_YYEOF; case '\0': return TOK_YYEOF;
default:
// Numbers. // Numbers.
if (c == '.' || isdigit (c)) case '.':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
{ {
int nchars = 0; int nchars = 0;
sscanf (*line - 1, "%lf%n", &yylval->TOK_NUM, &nchars); sscanf (*line - 1, "%lf%n", &yylval->TOK_NUM, &nchars);
@@ -247,8 +248,14 @@ yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc)
yylloc->last_column += nchars - 1; yylloc->last_column += nchars - 1;
return TOK_NUM; return TOK_NUM;
} }
// Identifiers. // Identifiers.
else if (islower (c)) case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y':
case 'z':
{ {
int nchars = 0; int nchars = 0;
char buf[100]; char buf[100];
@@ -266,14 +273,13 @@ yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc)
return s->type; return s->type;
} }
} }
// Stray characters. // Stray characters.
else default:
{
yyerror (yylloc, "error: invalid character"); yyerror (yylloc, "error: invalid character");
return yylex (line, yylval, yylloc); return yylex (line, yylval, yylloc);
} }
} }
}
/*---------. /*---------.