mirror of
https://github.com/linux-msm/qmic.git
synced 2024-11-23 09:44:06 +08:00
parser: refactor loops in yylex()
The first character in a symbol or numeric value in a number will not go beyond the end of the token buffer. Knowing this, the loops in yylex() can be rearranged to use while () instead of do...while (). Signed-off-by: Alex Elder <elder@linaro.org> Message-Id: <20211001232338.769309-30-elder@linaro.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
parent
b6b7384256
commit
734ecff5a5
12
parser.c
12
parser.c
@ -218,14 +218,14 @@ static struct token yylex()
|
||||
;
|
||||
|
||||
if (isalpha(ch)) {
|
||||
do {
|
||||
*p++ = ch;
|
||||
while ((ch = input()) && (isalnum(ch) || ch == '_')) {
|
||||
if (p - buf == sizeof(buf)) {
|
||||
buf[TOKEN_BUF_MIN] = '\0';
|
||||
yyerror("token too long: \"%s...\"", buf);
|
||||
}
|
||||
*p++ = ch;
|
||||
ch = input();
|
||||
} while (isalnum(ch) || ch == '_');
|
||||
}
|
||||
unput(ch);
|
||||
*p = '\0';
|
||||
|
||||
@ -275,14 +275,14 @@ static struct token yylex()
|
||||
base = 10;
|
||||
}
|
||||
|
||||
do {
|
||||
*p++ = ch;
|
||||
while ((ch = input()) && isvalid(ch)) {
|
||||
if (p - buf == sizeof(buf)) {
|
||||
buf[TOKEN_BUF_MIN] = '\0';
|
||||
yyerror("number too long: \"%s...\"", buf);
|
||||
}
|
||||
*p++ = ch;
|
||||
ch = input();
|
||||
} while (isvalid(ch));
|
||||
}
|
||||
unput(ch);
|
||||
*p = '\0';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user