aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-05-04 20:32:14 +0900
committernsfisis <nsfisis@gmail.com>2025-05-04 20:32:14 +0900
commitc03e0c49cd3329e0bc3e111393956441aa5f8849 (patch)
tree2494330b5b333a0f2a99b228d8dd7f7bf49b48c3
parentba4e8695a1b99c8fe1f165d2978a7da168007fbd (diff)
downloadP4Dcc-c03e0c49cd3329e0bc3e111393956441aa5f8849.tar.gz
P4Dcc-c03e0c49cd3329e0bc3e111393956441aa5f8849.tar.zst
P4Dcc-c03e0c49cd3329e0bc3e111393956441aa5f8849.zip
char literal
-rw-r--r--main.c15
-rw-r--r--tests/032.sh17
2 files changed, 32 insertions, 0 deletions
diff --git a/main.c b/main.c
index 873ebe6..39e6f31 100644
--- a/main.c
+++ b/main.c
@@ -215,6 +215,21 @@ struct Token* tokenize(char* src, int len) {
tok->kind = TK_GT;
tok = tok + 1;
}
+ } else if (c == '\'') {
+ pos = pos + 1;
+ int ch = src[pos];
+ if (ch == '\\') {
+ pos = pos + 1;
+ ch = src[pos];
+ if (ch == 'n') {
+ ch = '\n';
+ }
+ }
+ pos = pos + 2;
+ tok->kind = TK_L_INT;
+ tok->value = calloc(4, sizeof(char));
+ sprintf(tok->value, "%d", ch);
+ tok = tok + 1;
} else if (c == '"') {
pos = pos + 1;
int start = pos;
diff --git a/tests/032.sh b/tests/032.sh
new file mode 100644
index 0000000..5e55b2a
--- /dev/null
+++ b/tests/032.sh
@@ -0,0 +1,17 @@
+set -e
+
+cat <<'EOF' > expected
+97 48
+92 39
+10
+EOF
+bash ../../test_diff.sh <<'EOF'
+int printf();
+
+int main() {
+ printf("%d %d\n", 'a', '0');
+ printf("%d %d\n", '\\', '\'');
+ printf("%d\n", '\n');
+ return 0;
+}
+EOF