diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-14 03:29:04 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-14 03:29:04 +0000 |
| commit | 699e18b65b07af73ccd14b28f83572b1843c7d37 (patch) | |
| tree | 98b98269e02eb9052b2af698383a858d63b120a7 /lib/Parser | |
| parent | 3ef7f8b778dce23af25965b379126b9dd95d1c27 (diff) | |
feat(types): add native C scalar types and imported aliases
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'lib/Parser')
| -rw-r--r-- | lib/Parser/Parser.cc | 7 | ||||
| -rw-r--r-- | lib/Parser/ParserType.cc | 23 |
2 files changed, 28 insertions, 2 deletions
diff --git a/lib/Parser/Parser.cc b/lib/Parser/Parser.cc index aeb81fe..3bc095e 100644 --- a/lib/Parser/Parser.cc +++ b/lib/Parser/Parser.cc @@ -112,6 +112,13 @@ bool Parser::ParseDesignatorSuffix(std::vector<DesignatorAccess> &Out) { } std::string Parser::ParseTypeName(bool AllowVoid) { + switch (CurTok) { + case tok_c_int: getNextToken(); return "C_INT"; + case tok_c_char: getNextToken(); return "C_CHAR"; + case tok_c_string: getNextToken(); return "C_STRING"; + case tok_c_double: getNextToken(); return "C_DOUBLE"; + default: break; + } if (CurTok == tok_integer_kw) { getNextToken(); return "INTEGER"; diff --git a/lib/Parser/ParserType.cc b/lib/Parser/ParserType.cc index 358e3e2..e249c4c 100644 --- a/lib/Parser/ParserType.cc +++ b/lib/Parser/ParserType.cc @@ -34,7 +34,26 @@ std::unique_ptr<StmtAST> Parser::ParseTypeDecl() { if (!IsClass && CurTok == tok_eq) { getNextToken(); - if (CurTok == '(') { + if (CurTok == tok_c_type) { + getNextToken(); + if (CurTok != '(') { + fprintf(stderr, "error: Expected '(' after C_TYPE at line %d\n", Lex.getLine()); + return nullptr; + } + getNextToken(); + if (CurTok != tok_string_literal) { + fprintf(stderr, "error: C_TYPE requires a string literal at line %d\n", Lex.getLine()); + return nullptr; + } + std::string Expression = Lex.StringVal; + getNextToken(); + if (CurTok != ')') { + fprintf(stderr, "error: Expected ')' after C_TYPE string at line %d\n", Lex.getLine()); + return nullptr; + } + getNextToken(); + Decl = std::make_unique<CTypeDeclAST>(Name, Expression); + } else if (CurTok == '(') { getNextToken(); std::vector<std::string> Values; while (true) { @@ -65,7 +84,7 @@ std::unique_ptr<StmtAST> Parser::ParseTypeDecl() { getNextToken(); return nullptr; } else { - fprintf(stderr, "error: Expected '(' or '^' after '=' in TYPE %s at line %d\n", + fprintf(stderr, "error: Expected '(', '^' or C_TYPE after '=' in TYPE %s at line %d\n", Name.c_str(), Lex.getLine()); return nullptr; } |
