added support for dynamic arrays in the parser

This commit is contained in:
overflowerror 2021-05-06 11:22:53 +02:00
parent df3c1b7240
commit 02804efa4c
3 changed files with 20 additions and 2 deletions

View file

@ -6,6 +6,7 @@
struct typeinfo {
char* type;
bool isPointer;
bool isArray;
};
struct memberinfo {

View file

@ -6,5 +6,6 @@ void _panic(const char* f, const char* s);
#define WARN(msg) ("\033[33mwarning:\033[0m " msg)
#define ERROR(msg) ("\033[31mwerror:\033[0m " msg)
#define INFO(msg) ("\033[36minfo:\033[0m " msg)
#endif

View file

@ -117,6 +117,16 @@ structmember: type ID
{
$$ = newMemberInfo($1, $2);
}
| type ID OPEN_BRACKETS NUM CLOSE_BRACKETS
{
yyerror(filename, ERROR("static array members not yet supported"));
YYERROR;
}
| type ID OPEN_BRACKETS CLOSE_BRACKETS
{
yyerror(filename, ERROR("flexible array members not supported; use double pointers for dynamic array instead"));
YYERROR;
}
;
type: STDINT { yyerror(filename, ERROR("stdint types are not yet supported")); YYERROR; }
@ -134,8 +144,14 @@ type: STDINT { yyerror(filename, ERROR("stdint types are not yet supported"));
| type POINTER
{
if ($1->isPointer || strcmp($1->type, "string") == 0) {
yyerror(filename, ERROR("multiple pointer types are not supported"));
YYERROR;
if ($1->isArray) {
yyerror(filename, ERROR("multi pointer types are not supported"));
YYERROR;
} else {
yyerror(filename, INFO("double pointer type; assuming dynamic array"));
$$ = $1;
$$->isArray = true;
}
} else {
$$ = newTypeInfo(true, $1->type);
}