Convert tables to STRINGARRAY
This commit is contained in:
parent
abef39c1c6
commit
2e48e42368
|
@ -3,7 +3,6 @@
|
|||
#include <string.h>
|
||||
#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
|
||||
|
|
|
@ -111,7 +111,12 @@ SUBROUTDEC* parsesubroutdec(PARSER* p) {
|
|||
SUBROUTDEC* subroutdec = (SUBROUTDEC*)malloc(sizeof(SUBROUTDEC));
|
||||
subroutdec->subroutclass = subroutclass;
|
||||
|
||||
if(differs(p, "void"))
|
||||
subroutdec->type = parsetype(p);
|
||||
else {
|
||||
subroutdec->type = p->current->token;
|
||||
next(p);
|
||||
}
|
||||
|
||||
subroutdec->debug = getdebug(p);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
1
util.h
1
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;
|
||||
|
|
Loading…
Reference in New Issue