aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--preprocess.c227
-rw-r--r--tokenize.c40
2 files changed, 177 insertions, 90 deletions
diff --git a/preprocess.c b/preprocess.c
index 0cf7c27..c2c373f 100644
--- a/preprocess.c
+++ b/preprocess.c
@@ -22,40 +22,16 @@ enum TokenKind {
TokenKind_pp_directive_pragma,
TokenKind_pp_directive_undef,
- TokenKind_and,
- TokenKind_andand,
- TokenKind_arrow,
- TokenKind_assign,
- TokenKind_assign_add,
- TokenKind_assign_and,
- TokenKind_assign_div,
- TokenKind_assign_lshift,
- TokenKind_assign_mod,
- TokenKind_assign_mul,
- TokenKind_assign_or,
- TokenKind_assign_rshift,
- TokenKind_assign_sub,
- TokenKind_assign_xor,
- TokenKind_brace_l,
- TokenKind_brace_r,
- TokenKind_bracket_l,
- TokenKind_bracket_r,
- TokenKind_colon,
- TokenKind_comma,
- TokenKind_dot,
- TokenKind_ellipsis,
- TokenKind_eq,
- TokenKind_ge,
- TokenKind_gt,
- TokenKind_ident,
- TokenKind_keyword__Bool,
- TokenKind_keyword__Complex,
- TokenKind_keyword__Imaginary,
+ // C23: 6.4.1
+ TokenKind_keyword_alignas,
+ TokenKind_keyword_alignof,
TokenKind_keyword_auto,
+ TokenKind_keyword_bool,
TokenKind_keyword_break,
TokenKind_keyword_case,
TokenKind_keyword_char,
TokenKind_keyword_const,
+ TokenKind_keyword_constexpr,
TokenKind_keyword_continue,
TokenKind_keyword_default,
TokenKind_keyword_do,
@@ -63,6 +39,7 @@ enum TokenKind {
TokenKind_keyword_else,
TokenKind_keyword_enum,
TokenKind_keyword_extern,
+ TokenKind_keyword_false,
TokenKind_keyword_float,
TokenKind_keyword_for,
TokenKind_keyword_goto,
@@ -70,6 +47,7 @@ enum TokenKind {
TokenKind_keyword_inline,
TokenKind_keyword_int,
TokenKind_keyword_long,
+ TokenKind_keyword_nullptr,
TokenKind_keyword_register,
TokenKind_keyword_restrict,
TokenKind_keyword_return,
@@ -77,14 +55,55 @@ enum TokenKind {
TokenKind_keyword_signed,
TokenKind_keyword_sizeof,
TokenKind_keyword_static,
+ TokenKind_keyword_static_assert,
TokenKind_keyword_struct,
TokenKind_keyword_switch,
+ TokenKind_keyword_thread_local,
+ TokenKind_keyword_true,
TokenKind_keyword_typedef,
+ TokenKind_keyword_typeof,
+ TokenKind_keyword_typeof_unqual,
TokenKind_keyword_union,
TokenKind_keyword_unsigned,
TokenKind_keyword_void,
TokenKind_keyword_volatile,
TokenKind_keyword_while,
+ TokenKind_keyword__Atomic,
+ TokenKind_keyword__BitInt,
+ TokenKind_keyword__Complex,
+ TokenKind_keyword__Decimal128,
+ TokenKind_keyword__Decimal32,
+ TokenKind_keyword__Decimal64,
+ TokenKind_keyword__Generic,
+ TokenKind_keyword__Imaginary,
+ TokenKind_keyword__Noreturn,
+
+ TokenKind_and,
+ TokenKind_andand,
+ TokenKind_arrow,
+ TokenKind_assign,
+ TokenKind_assign_add,
+ TokenKind_assign_and,
+ TokenKind_assign_div,
+ TokenKind_assign_lshift,
+ TokenKind_assign_mod,
+ TokenKind_assign_mul,
+ TokenKind_assign_or,
+ TokenKind_assign_rshift,
+ TokenKind_assign_sub,
+ TokenKind_assign_xor,
+ TokenKind_brace_l,
+ TokenKind_brace_r,
+ TokenKind_bracket_l,
+ TokenKind_bracket_r,
+ TokenKind_colon,
+ TokenKind_comma,
+ TokenKind_dot,
+ TokenKind_ellipsis,
+ TokenKind_eq,
+ TokenKind_ge,
+ TokenKind_gt,
+ TokenKind_ident,
TokenKind_le,
TokenKind_literal_int,
TokenKind_literal_str,
@@ -152,66 +171,14 @@ const char* token_kind_stringify(TokenKind k) {
return "#pragma";
else if (k == TokenKind_pp_directive_undef)
return "#undef";
- else if (k == TokenKind_and)
- return "&";
- else if (k == TokenKind_andand)
- return "&&";
- else if (k == TokenKind_arrow)
- return "->";
- else if (k == TokenKind_assign)
- return "=";
- else if (k == TokenKind_assign_add)
- return "+=";
- else if (k == TokenKind_assign_and)
- return "&=";
- else if (k == TokenKind_assign_div)
- return "/=";
- else if (k == TokenKind_assign_lshift)
- return "<<=";
- else if (k == TokenKind_assign_mod)
- return "%=";
- else if (k == TokenKind_assign_mul)
- return "*=";
- else if (k == TokenKind_assign_or)
- return "|=";
- else if (k == TokenKind_assign_rshift)
- return ">>=";
- else if (k == TokenKind_assign_sub)
- return "-=";
- else if (k == TokenKind_assign_xor)
- return "^=";
- else if (k == TokenKind_brace_l)
- return "{";
- else if (k == TokenKind_brace_r)
- return "}";
- else if (k == TokenKind_bracket_l)
- return "[";
- else if (k == TokenKind_bracket_r)
- return "]";
- else if (k == TokenKind_colon)
- return ":";
- else if (k == TokenKind_comma)
- return ",";
- else if (k == TokenKind_dot)
- return ".";
- else if (k == TokenKind_ellipsis)
- return "...";
- else if (k == TokenKind_eq)
- return "==";
- else if (k == TokenKind_ge)
- return ">=";
- else if (k == TokenKind_gt)
- return ">";
- else if (k == TokenKind_ident)
- return "<identifier>";
- else if (k == TokenKind_keyword__Bool)
- return "_Bool";
- else if (k == TokenKind_keyword__Complex)
- return "_Complex";
- else if (k == TokenKind_keyword__Imaginary)
- return "_Imaginary";
+ else if (k == TokenKind_keyword_alignas)
+ return "alignas";
+ else if (k == TokenKind_keyword_alignof)
+ return "alignof";
else if (k == TokenKind_keyword_auto)
return "auto";
+ else if (k == TokenKind_keyword_bool)
+ return "bool";
else if (k == TokenKind_keyword_break)
return "break";
else if (k == TokenKind_keyword_case)
@@ -220,6 +187,8 @@ const char* token_kind_stringify(TokenKind k) {
return "char";
else if (k == TokenKind_keyword_const)
return "const";
+ else if (k == TokenKind_keyword_constexpr)
+ return "constexpr";
else if (k == TokenKind_keyword_continue)
return "continue";
else if (k == TokenKind_keyword_default)
@@ -234,6 +203,8 @@ const char* token_kind_stringify(TokenKind k) {
return "enum";
else if (k == TokenKind_keyword_extern)
return "extern";
+ else if (k == TokenKind_keyword_false)
+ return "false";
else if (k == TokenKind_keyword_float)
return "float";
else if (k == TokenKind_keyword_for)
@@ -248,6 +219,8 @@ const char* token_kind_stringify(TokenKind k) {
return "int";
else if (k == TokenKind_keyword_long)
return "long";
+ else if (k == TokenKind_keyword_nullptr)
+ return "nullptr";
else if (k == TokenKind_keyword_register)
return "register";
else if (k == TokenKind_keyword_restrict)
@@ -262,12 +235,22 @@ const char* token_kind_stringify(TokenKind k) {
return "sizeof";
else if (k == TokenKind_keyword_static)
return "static";
+ else if (k == TokenKind_keyword_static_assert)
+ return "static_assert";
else if (k == TokenKind_keyword_struct)
return "struct";
else if (k == TokenKind_keyword_switch)
return "switch";
+ else if (k == TokenKind_keyword_thread_local)
+ return "thread_local";
+ else if (k == TokenKind_keyword_true)
+ return "true";
else if (k == TokenKind_keyword_typedef)
return "typedef";
+ else if (k == TokenKind_keyword_typeof)
+ return "typeof";
+ else if (k == TokenKind_keyword_typeof_unqual)
+ return "typeof_unqual";
else if (k == TokenKind_keyword_union)
return "union";
else if (k == TokenKind_keyword_unsigned)
@@ -278,6 +261,76 @@ const char* token_kind_stringify(TokenKind k) {
return "volatile";
else if (k == TokenKind_keyword_while)
return "while";
+ else if (k == TokenKind_keyword__Atomic)
+ return "_Atomic";
+ else if (k == TokenKind_keyword__BitInt)
+ return "_BitInt";
+ else if (k == TokenKind_keyword__Complex)
+ return "_Complex";
+ else if (k == TokenKind_keyword__Decimal128)
+ return "_Decimal128";
+ else if (k == TokenKind_keyword__Decimal32)
+ return "_Decimal32";
+ else if (k == TokenKind_keyword__Decimal64)
+ return "_Decimal64";
+ else if (k == TokenKind_keyword__Generic)
+ return "_Generic";
+ else if (k == TokenKind_keyword__Imaginary)
+ return "_Imaginary";
+ else if (k == TokenKind_keyword__Noreturn)
+ return "_Noreturn";
+ else if (k == TokenKind_and)
+ return "&";
+ else if (k == TokenKind_andand)
+ return "&&";
+ else if (k == TokenKind_arrow)
+ return "->";
+ else if (k == TokenKind_assign)
+ return "=";
+ else if (k == TokenKind_assign_add)
+ return "+=";
+ else if (k == TokenKind_assign_and)
+ return "&=";
+ else if (k == TokenKind_assign_div)
+ return "/=";
+ else if (k == TokenKind_assign_lshift)
+ return "<<=";
+ else if (k == TokenKind_assign_mod)
+ return "%=";
+ else if (k == TokenKind_assign_mul)
+ return "*=";
+ else if (k == TokenKind_assign_or)
+ return "|=";
+ else if (k == TokenKind_assign_rshift)
+ return ">>=";
+ else if (k == TokenKind_assign_sub)
+ return "-=";
+ else if (k == TokenKind_assign_xor)
+ return "^=";
+ else if (k == TokenKind_brace_l)
+ return "{";
+ else if (k == TokenKind_brace_r)
+ return "}";
+ else if (k == TokenKind_bracket_l)
+ return "[";
+ else if (k == TokenKind_bracket_r)
+ return "]";
+ else if (k == TokenKind_colon)
+ return ":";
+ else if (k == TokenKind_comma)
+ return ",";
+ else if (k == TokenKind_dot)
+ return ".";
+ else if (k == TokenKind_ellipsis)
+ return "...";
+ else if (k == TokenKind_eq)
+ return "==";
+ else if (k == TokenKind_ge)
+ return ">=";
+ else if (k == TokenKind_gt)
+ return ">";
+ else if (k == TokenKind_ident)
+ return "<identifier>";
else if (k == TokenKind_le)
return "le";
else if (k == TokenKind_literal_int)
diff --git a/tokenize.c b/tokenize.c
index 9b4042d..a7e99b2 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -47,8 +47,14 @@ void tokenize_all(Lexer* l) {
}
tok->value.integer = ch;
} else if (k == TokenKind_ident) {
- if (strcmp(pp_tok->value.string, "auto") == 0) {
+ if (strcmp(pp_tok->value.string, "alignas") == 0) {
+ tok->kind = TokenKind_keyword_alignas;
+ } else if (strcmp(pp_tok->value.string, "alignof") == 0) {
+ tok->kind = TokenKind_keyword_alignof;
+ } else if (strcmp(pp_tok->value.string, "auto") == 0) {
tok->kind = TokenKind_keyword_auto;
+ } else if (strcmp(pp_tok->value.string, "bool") == 0) {
+ tok->kind = TokenKind_keyword_bool;
} else if (strcmp(pp_tok->value.string, "break") == 0) {
tok->kind = TokenKind_keyword_break;
} else if (strcmp(pp_tok->value.string, "case") == 0) {
@@ -57,6 +63,8 @@ void tokenize_all(Lexer* l) {
tok->kind = TokenKind_keyword_char;
} else if (strcmp(pp_tok->value.string, "const") == 0) {
tok->kind = TokenKind_keyword_const;
+ } else if (strcmp(pp_tok->value.string, "constexpr") == 0) {
+ tok->kind = TokenKind_keyword_constexpr;
} else if (strcmp(pp_tok->value.string, "continue") == 0) {
tok->kind = TokenKind_keyword_continue;
} else if (strcmp(pp_tok->value.string, "default") == 0) {
@@ -71,6 +79,8 @@ void tokenize_all(Lexer* l) {
tok->kind = TokenKind_keyword_enum;
} else if (strcmp(pp_tok->value.string, "extern") == 0) {
tok->kind = TokenKind_keyword_extern;
+ } else if (strcmp(pp_tok->value.string, "false") == 0) {
+ tok->kind = TokenKind_keyword_false;
} else if (strcmp(pp_tok->value.string, "float") == 0) {
tok->kind = TokenKind_keyword_float;
} else if (strcmp(pp_tok->value.string, "for") == 0) {
@@ -85,6 +95,8 @@ void tokenize_all(Lexer* l) {
tok->kind = TokenKind_keyword_int;
} else if (strcmp(pp_tok->value.string, "long") == 0) {
tok->kind = TokenKind_keyword_long;
+ } else if (strcmp(pp_tok->value.string, "nullptr") == 0) {
+ tok->kind = TokenKind_keyword_nullptr;
} else if (strcmp(pp_tok->value.string, "register") == 0) {
tok->kind = TokenKind_keyword_register;
} else if (strcmp(pp_tok->value.string, "restrict") == 0) {
@@ -99,12 +111,22 @@ void tokenize_all(Lexer* l) {
tok->kind = TokenKind_keyword_sizeof;
} else if (strcmp(pp_tok->value.string, "static") == 0) {
tok->kind = TokenKind_keyword_static;
+ } else if (strcmp(pp_tok->value.string, "static_assert") == 0) {
+ tok->kind = TokenKind_keyword_static_assert;
} else if (strcmp(pp_tok->value.string, "struct") == 0) {
tok->kind = TokenKind_keyword_struct;
} else if (strcmp(pp_tok->value.string, "switch") == 0) {
tok->kind = TokenKind_keyword_switch;
+ } else if (strcmp(pp_tok->value.string, "thread_local") == 0) {
+ tok->kind = TokenKind_keyword_thread_local;
+ } else if (strcmp(pp_tok->value.string, "true") == 0) {
+ tok->kind = TokenKind_keyword_true;
} else if (strcmp(pp_tok->value.string, "typedef") == 0) {
tok->kind = TokenKind_keyword_typedef;
+ } else if (strcmp(pp_tok->value.string, "typeof") == 0) {
+ tok->kind = TokenKind_keyword_typeof;
+ } else if (strcmp(pp_tok->value.string, "typeof_unqual") == 0) {
+ tok->kind = TokenKind_keyword_typeof_unqual;
} else if (strcmp(pp_tok->value.string, "union") == 0) {
tok->kind = TokenKind_keyword_union;
} else if (strcmp(pp_tok->value.string, "unsigned") == 0) {
@@ -115,12 +137,24 @@ void tokenize_all(Lexer* l) {
tok->kind = TokenKind_keyword_volatile;
} else if (strcmp(pp_tok->value.string, "while") == 0) {
tok->kind = TokenKind_keyword_while;
- } else if (strcmp(pp_tok->value.string, "_Bool") == 0) {
- tok->kind = TokenKind_keyword__Bool;
+ } else if (strcmp(pp_tok->value.string, "_Atomic") == 0) {
+ tok->kind = TokenKind_keyword__Atomic;
+ } else if (strcmp(pp_tok->value.string, "_BitInt") == 0) {
+ tok->kind = TokenKind_keyword__BitInt;
} else if (strcmp(pp_tok->value.string, "_Complex") == 0) {
tok->kind = TokenKind_keyword__Complex;
+ } else if (strcmp(pp_tok->value.string, "_Decimal128") == 0) {
+ tok->kind = TokenKind_keyword__Decimal128;
+ } else if (strcmp(pp_tok->value.string, "_Decimal32") == 0) {
+ tok->kind = TokenKind_keyword__Decimal32;
+ } else if (strcmp(pp_tok->value.string, "_Decimal64") == 0) {
+ tok->kind = TokenKind_keyword__Decimal64;
+ } else if (strcmp(pp_tok->value.string, "_Generic") == 0) {
+ tok->kind = TokenKind_keyword__Generic;
} else if (strcmp(pp_tok->value.string, "_Imaginary") == 0) {
tok->kind = TokenKind_keyword__Imaginary;
+ } else if (strcmp(pp_tok->value.string, "_Noreturn") == 0) {
+ tok->kind = TokenKind_keyword__Noreturn;
} else {
tok->kind = TokenKind_ident;
tok->value = pp_tok->value;