mirror of
https://github.com/rui314/chibicc
synced 2025-03-11 08:42:54 +03:00
Add line and block comments
This commit is contained in:
parent
a0388bada4
commit
6c0a42926a
4
test.sh
4
test.sh
@ -213,4 +213,8 @@ assert 1 'int main() { ({ 0; return 1; 2; }); return 3; }'
|
||||
assert 6 'int main() { return ({ 1; }) + ({ 2; }) + ({ 3; }); }'
|
||||
assert 3 'int main() { return ({ int x=3; x; }); }'
|
||||
|
||||
assert 2 'int main() { /* return 1; */ return 2; }'
|
||||
assert 2 'int main() { // return 1;
|
||||
return 2; }'
|
||||
|
||||
echo OK
|
||||
|
17
tokenize.c
17
tokenize.c
@ -230,6 +230,23 @@ static Token *tokenize(char *filename, char *p) {
|
||||
Token *cur = &head;
|
||||
|
||||
while (*p) {
|
||||
// Skip line comments.
|
||||
if (startswith(p, "//")) {
|
||||
p += 2;
|
||||
while (*p != '\n')
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip block comments.
|
||||
if (startswith(p, "/*")) {
|
||||
char *q = strstr(p + 2, "*/");
|
||||
if (!q)
|
||||
error_at(p, "unclosed block comment");
|
||||
p = q + 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip whitespace characters.
|
||||
if (isspace(*p)) {
|
||||
p++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user