aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-05-04 14:21:40 +0900
committernsfisis <nsfisis@gmail.com>2025-05-04 14:21:40 +0900
commit8a323fe3f7a964040c085a67cc8868f07b63bb6a (patch)
treedc287b84af4059fc88c838b880971d72ed3db62e
parent17db00d6d50c849ad4cf65f434c06ceedc20f97d (diff)
downloadP4Dcc-8a323fe3f7a964040c085a67cc8868f07b63bb6a.tar.gz
P4Dcc-8a323fe3f7a964040c085a67cc8868f07b63bb6a.tar.zst
P4Dcc-8a323fe3f7a964040c085a67cc8868f07b63bb6a.zip
support more primitive types
-rw-r--r--main.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/main.c b/main.c
index d48f7b4..5e5c894 100644
--- a/main.c
+++ b/main.c
@@ -650,7 +650,7 @@ AST* parse_continue_stmt(PARSER* p) {
}
int is_type_token(int token_kind) {
- return token_kind == TK_K_INT;
+ return token_kind == TK_K_INT || token_kind == TK_K_LONG || token_kind == TK_K_CHAR || token_kind == TK_K_VOID;
}
TYPE* parse_type(PARSER* p) {
@@ -658,7 +658,16 @@ TYPE* parse_type(PARSER* p) {
if (!is_type_token(t->kind)) {
fatal_error("parse_type: unknown type");
}
- TYPE* ty = type_new(TK_K_INT);
+ TYPE* ty = type_new(TY_UNKNOWN);
+ if (t->kind == TK_K_INT) {
+ ty->kind = TY_INT;
+ } else if (t->kind == TK_K_LONG) {
+ ty->kind = TY_LONG;
+ } else if (t->kind == TK_K_CHAR) {
+ ty->kind = TY_CHAR;
+ } else if (t->kind == TK_K_VOID) {
+ ty->kind = TY_VOID;
+ }
return ty;
}