Fix parsing issues

This commit is contained in:
Augusto Gunsch 2020-12-22 14:38:10 -03:00
parent 351446bb6d
commit d65bcc202f
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
7 changed files with 23 additions and 38 deletions

View File

@ -26,18 +26,12 @@ mkstrlist(operators, opsarr);
TERM* parsetermnullified(PARSER* p) {
TOKENTYPE type = p->current->type;
if(type == integer)
return parseint(p);
else if(type == string)
return parsestr(p);
else if(type == keyword)
return parsekeyword(p);
else if(type == identifier)
return parseidentifierterm(p);
else if(equals(p, "-") || equals(p, "~"))
return parseunaryopterm(p);
else if(equals(p, "("))
return parseinnerexpression(p);
if(type == integer) return parseint(p);
if(type == string) return parsestr(p);
if(type == keyword) return parsekeyword(p);
if(type == identifier) return parseidentifierterm(p);
if(equals(p, "-") || equals(p, "~")) return parseunaryopterm(p);
if(equals(p, "(")) return parseinnerexpression(p);
return NULL;
}
@ -94,8 +88,10 @@ TERM* parseinnerexpression(PARSER* p) {
}
TERM* parsecalltermnullified(PARSER* p) {
TERM* t = mkterm(subroutcall);
SUBROUTCALL* call = parsesubroutcallnullified(p);
if(call == NULL)
return NULL;
TERM* t = mkterm(subroutcall);
t->call == call;
return t;
}
@ -184,6 +180,7 @@ SUBROUTCALL* parsesubroutcallnullified(PARSER* p) {
if(p->current->type != identifier)
return nullsubroutcall(p, c);
c->name = p->current->token;
next(p);
if(differs(p, "("))
return nullsubroutcall(p, c);

View File

@ -5,8 +5,8 @@
#define mkstrlist(name, array) STRINGARRAY name = { .items = array, .size = strcount(array) }
#define next(parser) parser->current = p->current->next
#define rewindparser(parser) p->checkpoint = p->current
#define anchorparser(parser) p->current = p->checkpoint
#define anchorparser(parser) p->checkpoint = p->current
#define rewindparser(parser) p->current = p->checkpoint
#define differs(parser, str) strcmp(parser->current->token, str)
#define nextdiffers(parser, str) strcmp(parser->current->next->token, str)
#define equals(parser, str) !differs(parser, str)

View File

@ -18,18 +18,13 @@ STATEMENT* mkstatement(STATEMENTTYPE t) {
return s;
}
// Though nullified, will throw errors if the parsing was on-going
// Though nullified, will throw errors if the parsing fails while on-going
STATEMENT* parsestatementnullified(PARSER* p) {
if(equals(p, "let"))
return parselet(p);
else if(equals(p, "if"))
return parseif(p);
else if(equals(p, "while"))
return parsewhile(p);
else if(equals(p, "do"))
return parsedo(p);
else if(equals(p, "return"))
return parsereturn(p);
if(equals(p, "let")) return parselet(p);
if(equals(p, "if")) return parseif(p);
if(equals(p, "while")) return parsewhile(p);
if(equals(p, "do")) return parsedo(p);
if(equals(p, "return")) return parsereturn(p);
return NULL;
}

View File

@ -111,13 +111,7 @@ SUBROUTDEC* parsesubroutdec(PARSER* p) {
SUBROUTDEC* subroutdec = (SUBROUTDEC*)malloc(sizeof(SUBROUTDEC));
subroutdec->subroutclass = subroutclass;
subroutdec->typeclass = p->current->type;
if(equals(p, "void")) {
subroutdec->type = p->current->token;
next(p);
}
else
subroutdec->type = parsetype(p);
subroutdec->type = parsetype(p);
subroutdec->debug = getdebug(p);
@ -185,7 +179,7 @@ bool isprimitive(TOKEN* tk) {
}
char* parsetype(PARSER* p) {
if(p->current->type != identifier);
if(p->current->type != identifier)
unexpected(p);
char* result = p->current->token;

View File

@ -50,7 +50,6 @@ typedef enum {
typedef struct subroutdec {
SUBROUTCLASS subroutclass;
char* type;
TOKENTYPE typeclass;
char* name;
struct parameter* parameters;
struct subroutbody* body;

View File

@ -14,6 +14,6 @@ PARSER* mkparser(TOKEN* tokens, char* file) {
return parser;
}
void parse(PARSER* parser) {
parser->output = parseclasses(parser);
void parse(PARSER* p) {
p->output = parseclasses(p);
}

View File

@ -12,5 +12,5 @@ typedef struct {
} PARSER;
PARSER* mkparser(TOKEN* tokens, char* file);
void parse(PARSER* parser);
void parse(PARSER* p);
#endif