diff --git a/parser/parser-internal.h b/parser/parser-internal.h index 31d7a34..85c720f 100644 --- a/parser/parser-internal.h +++ b/parser/parser-internal.h @@ -3,7 +3,6 @@ #include #include "parser.h" -#define mkstrlist(name, array) STRINGARRAY name = { .items = array, .size = strcount(array) } #define next(parser) parser->current = p->current->next #define anchorparser(parser) p->checkpoint = p->current #define rewindparser(parser) p->current = p->checkpoint diff --git a/parser/parser-structure.c b/parser/parser-structure.c index e8e8d6f..d1c0504 100644 --- a/parser/parser-structure.c +++ b/parser/parser-structure.c @@ -111,7 +111,12 @@ SUBROUTDEC* parsesubroutdec(PARSER* p) { SUBROUTDEC* subroutdec = (SUBROUTDEC*)malloc(sizeof(SUBROUTDEC)); subroutdec->subroutclass = subroutclass; - subroutdec->type = parsetype(p); + if(differs(p, "void")) + subroutdec->type = parsetype(p); + else { + subroutdec->type = p->current->token; + next(p); + } subroutdec->debug = getdebug(p); diff --git a/tokenizer/tokenizer-tables.h b/tokenizer/tokenizer-tables.h index 768ebc7..61eb940 100644 --- a/tokenizer/tokenizer-tables.h +++ b/tokenizer/tokenizer-tables.h @@ -2,17 +2,18 @@ #define TOKENIZER_TABLES_H #include "util.h" -const char* keywords[] = { + +const char* keywordsraw[] = { "class", "constructor", "function", "method", "field", "static", "var", "int", "char", "boolean", "void", "true", "false", "null", "this", "let", "do", "if", "else", "while", "return" }; -const int keywordssize = strcount(keyword); +mkstrlist(keywords, keywordsraw); -const char* symbols[] = { +const char* symbolsraw[] = { "{", "}", "(", ")", "[", "]", ".", ",", ";", "+", "-", "*", "/", "&", "|", "<", ">", "=", "~" }; -const int symbolssize = strcount(symbols); +mkstrlist(symbols, symbolsraw); #endif diff --git a/tokenizer/tokenizer.c b/tokenizer/tokenizer.c index 62e1d1b..7c8ce89 100644 --- a/tokenizer/tokenizer.c +++ b/tokenizer/tokenizer.c @@ -91,19 +91,13 @@ CHARTYPE getchartype(unsigned char c) { } bool iskeyword(STRING* tk) { - for(int i = 0; i < keywordssize; i++) - if(!strcmp(tk->str, keywords[i])) - return true; - return false; + return existsinarray(&keywords, tk->str); } bool issymbol(STRING* tk) { if(tk->count != 2) return false; - for(int i = 0; i < symbolssize; i++) - if(!strcmp(tk->str, symbols[i])) - return true; - return false; + return existsinarray(&symbols, tk->str); } bool isint(char* str) { diff --git a/util.h b/util.h index 248c206..e67847d 100644 --- a/util.h +++ b/util.h @@ -10,6 +10,7 @@ #define eprintf(...) fprintf (stderr, __VA_ARGS__) #define count(array, type) ((sizeof(array)) / (sizeof(type))) #define strcount(array) count(array, char*) +#define mkstrlist(name, array) STRINGARRAY name = { .items = array, .size = strcount(array) } typedef struct stringlist { const char* content;