summaryrefslogtreecommitdiff
path: root/attocc.c
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-06-16 11:31:58 +0200
committermetamuffin <metamuffin@disroot.org>2024-06-16 11:31:58 +0200
commitd61782a1d33e6aca31802ceda918de0864d4c979 (patch)
tree1d80144f52b852acc38233db5a0dd1de867317d1 /attocc.c
parent111d50c8a343df9f90b1b695b836ae093fe96add (diff)
downloadattocc-d61782a1d33e6aca31802ceda918de0864d4c979.tar
attocc-d61782a1d33e6aca31802ceda918de0864d4c979.tar.bz2
attocc-d61782a1d33e6aca31802ceda918de0864d4c979.tar.zst
fiix a few lexing crashes
Diffstat (limited to 'attocc.c')
-rw-r--r--attocc.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/attocc.c b/attocc.c
index b9a1ff9..5c92ac7 100644
--- a/attocc.c
+++ b/attocc.c
@@ -335,8 +335,8 @@ struct token *tokenize(char *source) {
match = 0;
for (int i = 0; i < NUM_KEYWORDS; i++) {
char *kw = KEYWORDS[i];
- if (remaining >= strlen(kw)) {
- if (strncmp(kw, p, strlen(kw)) == 0) {
+ if (remaining >= strlen(kw) + 1) {
+ if (strncmp(kw, p, strlen(kw)) == 0 && !is_ident(p[strlen(kw)])) {
struct token *new_token = token_push(&tokens, &num_tokens);
if (!new_token)
return NULL;
@@ -403,7 +403,7 @@ struct token *tokenize(char *source) {
struct token *new_token = token_push(&tokens, &num_tokens);
if (!new_token)
return NULL;
- new_token->kind = TOK_IDENTIFIER;
+ new_token->kind = TOK_CONSTANT;
new_token->data.constant_kind = CONST_STR;
new_token->data.constant_str_value = str;
continue;
@@ -428,7 +428,7 @@ struct token *tokenize(char *source) {
if (!new_token)
return NULL;
new_token->kind = TOK_CONSTANT;
- new_token->data.constant_kind = CONST_STR;
+ new_token->data.constant_kind = CONST_CHAR;
new_token->data.constant_char_value = chr;
continue;
}
@@ -534,29 +534,53 @@ void debug_tokens(struct token *tokens) {
}
#endif
-enum expr_kind {
+enum node_kind {
NO_BINOP,
NO_UNOP,
NO_MEMBER_ACCESS,
+ NO_STRUCT,
+ NO_UNION,
+ NO_ENUM,
+ NO_FUNCTION
};
-union expr_data {
+union node_data {
struct {
struct expr *lhs;
struct expr *rhs;
} binop;
};
-struct expr {
- enum expr_kind kind;
- union expr_data data;
+struct node {
+ enum node_kind kind;
+ union node_data data;
};
-enum decl_kind { DECL_STRUCT, DECL_UNION, DECL_ENUM, DECL_FUNCTION };
+char parse_enum_decl(struct token *tokens, struct node **node) {
+ int p = 0;
+ if (tokens[p].kind != TOK_KEYWORD || tokens[p].data.keyword != KW_ENUM)
+ return 1;
+ p++;
-struct decl {
- enum decl_kind kind;
-};
+ char *ident = NULL;
+ if (tokens[p].kind == TOK_IDENTIFIER) {
+ ident = tokens[p].data.identifier;
+ p++;
+ }
+
+ if (tokens[p].kind != TOK_SEPERATOR || tokens[p].data.seperator != SEP_LCURLY)
+ return 1;
+ p++;
+
+ *node = malloc(sizeof(struct node));
+ if (!*node) {
+ fprintf(stderr, "malloc failed\n");
+ return 1;
+ }
+ // (**node).data.;
+
+ return 0;
+}
struct decl *parse(struct token *tokens) { return NULL; }