Convert tables to STRINGARRAY

This commit is contained in:
Augusto Gunsch 2020-12-22 16:00:49 -03:00
parent abef39c1c6
commit 2e48e42368
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
5 changed files with 14 additions and 14 deletions

View File

@ -3,7 +3,6 @@
#include <string.h> #include <string.h>
#include "parser.h" #include "parser.h"
#define mkstrlist(name, array) STRINGARRAY name = { .items = array, .size = strcount(array) }
#define next(parser) parser->current = p->current->next #define next(parser) parser->current = p->current->next
#define anchorparser(parser) p->checkpoint = p->current #define anchorparser(parser) p->checkpoint = p->current
#define rewindparser(parser) p->current = p->checkpoint #define rewindparser(parser) p->current = p->checkpoint

View File

@ -111,7 +111,12 @@ SUBROUTDEC* parsesubroutdec(PARSER* p) {
SUBROUTDEC* subroutdec = (SUBROUTDEC*)malloc(sizeof(SUBROUTDEC)); SUBROUTDEC* subroutdec = (SUBROUTDEC*)malloc(sizeof(SUBROUTDEC));
subroutdec->subroutclass = subroutclass; 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); subroutdec->debug = getdebug(p);

View File

@ -2,17 +2,18 @@
#define TOKENIZER_TABLES_H #define TOKENIZER_TABLES_H
#include "util.h" #include "util.h"
const char* keywords[] = {
const char* keywordsraw[] = {
"class", "constructor", "function", "method", "field", "static", "class", "constructor", "function", "method", "field", "static",
"var", "int", "char", "boolean", "void", "true", "false", "null", "var", "int", "char", "boolean", "void", "true", "false", "null",
"this", "let", "do", "if", "else", "while", "return" "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 #endif

View File

@ -91,19 +91,13 @@ CHARTYPE getchartype(unsigned char c) {
} }
bool iskeyword(STRING* tk) { bool iskeyword(STRING* tk) {
for(int i = 0; i < keywordssize; i++) return existsinarray(&keywords, tk->str);
if(!strcmp(tk->str, keywords[i]))
return true;
return false;
} }
bool issymbol(STRING* tk) { bool issymbol(STRING* tk) {
if(tk->count != 2) if(tk->count != 2)
return false; return false;
for(int i = 0; i < symbolssize; i++) return existsinarray(&symbols, tk->str);
if(!strcmp(tk->str, symbols[i]))
return true;
return false;
} }
bool isint(char* str) { bool isint(char* str) {

1
util.h
View File

@ -10,6 +10,7 @@
#define eprintf(...) fprintf (stderr, __VA_ARGS__) #define eprintf(...) fprintf (stderr, __VA_ARGS__)
#define count(array, type) ((sizeof(array)) / (sizeof(type))) #define count(array, type) ((sizeof(array)) / (sizeof(type)))
#define strcount(array) count(array, char*) #define strcount(array) count(array, char*)
#define mkstrlist(name, array) STRINGARRAY name = { .items = array, .size = strcount(array) }
typedef struct stringlist { typedef struct stringlist {
const char* content; const char* content;