aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main.c21
-rw-r--r--tests/053.sh33
2 files changed, 47 insertions, 7 deletions
diff --git a/main.c b/main.c
index ac5484d..b996615 100644
--- a/main.c
+++ b/main.c
@@ -319,13 +319,8 @@ void pp_tokenize_all(Preprocessor* pp) {
}
} else if (c == '\'') {
start = pp->pos - 1;
- ch = pp->src[pp->pos];
- if (ch == '\\') {
+ if (pp->src[pp->pos] == '\\') {
++pp->pos;
- ch = pp->src[pp->pos];
- if (ch == 'n') {
- ch = '\n';
- }
}
pp->pos += 2;
tok->kind = PpTokenKind_character_constant;
@@ -576,8 +571,20 @@ void tokenize_all(Lexer* l) {
ch = pp_tok->raw.data[1];
if (ch == '\\') {
ch = pp_tok->raw.data[2];
- if (ch == 'n') {
+ if (ch == 'a') {
+ ch = '\a';
+ } else if (ch == 'b') {
+ ch = '\b';
+ } else if (ch == 'f') {
+ ch = '\f';
+ } else if (ch == 'n') {
ch = '\n';
+ } else if (ch == 'r') {
+ ch = '\r';
+ } else if (ch == 't') {
+ ch = '\t';
+ } else if (ch == 'v') {
+ ch = '\v';
}
}
buf = calloc(4, sizeof(char));
diff --git a/tests/053.sh b/tests/053.sh
new file mode 100644
index 0000000..c4350b8
--- /dev/null
+++ b/tests/053.sh
@@ -0,0 +1,33 @@
+set -e
+
+cat <<'EOF' > expected
+39
+34
+63
+92
+7
+8
+12
+10
+13
+9
+11
+EOF
+bash ../../test_diff.sh <<'EOF'
+int printf();
+
+int main() {
+ printf("%d\n", '\'');
+ printf("%d\n", '\"');
+ printf("%d\n", '\?');
+ printf("%d\n", '\\');
+ printf("%d\n", '\a');
+ printf("%d\n", '\b');
+ printf("%d\n", '\f');
+ printf("%d\n", '\n');
+ printf("%d\n", '\r');
+ printf("%d\n", '\t');
+ printf("%d\n", '\v');
+ return 0;
+}
+EOF