Fixes to struct parsing

This commit is contained in:
Curle 2021-02-22 17:43:06 +00:00
parent 72358aed9f
commit 8263fb853b
No known key found for this signature in database
GPG Key ID: 58A5C4688ECE6E7C
5 changed files with 41 additions and 22 deletions

View File

@ -511,13 +511,20 @@ struct ASTNode* ParseCompound() {
void ParseGlobals() {
struct ASTNode* Tree;
struct SymbolTableEntry* Composite;
int Type, FunctionComing;
printf("Parsing global definitions\r\n");
while(1) {
// We loop early if there's a struct, and since a struct may be the last
// thing in a file, we need to check for eof before anything else
if(CurrentToken.type == LI_EOF)
break;
printf("New definition incoming..\r\n\n");
Type = ParseOptionalPointer(NULL);
Type = ParseOptionalPointer(&Composite);
//TODO: converge pathways on this block?
if(CurrentToken.type == KW_FUNC) {
@ -525,6 +532,13 @@ void ParseGlobals() {
FunctionComing = 1;
}
// Structs are parsed fully in ParseOptionalPointer
// TODO: FIX THAT!!
if(Type == DAT_STRUCT && CurrentToken.type == LI_SEMIC) {
Tokenise();
continue;
}
VerifyToken(TY_IDENTIFIER, "ident");
if(FunctionComing && CurrentToken.type == LI_LPARE) {
@ -539,13 +553,10 @@ void ParseGlobals() {
}
} else {
printf("\tParsing global variable declaration\n");
BeginVariableDeclaration(Type, NULL, SC_GLOBAL);
BeginVariableDeclaration(Type, Composite, SC_GLOBAL);
VerifyToken(LI_SEMIC, ";");
}
if(CurrentToken.type == LI_EOF)
break;
}
}

View File

@ -104,12 +104,12 @@ int ParseOptionalPointer(struct SymbolTableEntry** Composite) {
// x = **y;
// possible.
while(1) {
Tokenise();
printf("\t\t\tType on parsing is %d\n", CurrentToken.type);
if(CurrentToken.type != AR_STAR)
break;
Type = PointerTo(Type);
Tokenise();
// Tokenise(); TODO: is this skipping pointers?
}

View File

@ -33,7 +33,7 @@ static int ReadDeclarationList(struct SymbolTableEntry* FunctionSymbol, int Stor
if(FunctionSymbol != NULL)
PrototypePointer = FunctionSymbol->Start;
while(CurrentToken.type != LI_RPARE) {
while(CurrentToken.type != End) {
TokenType = ParseOptionalPointer(FunctionSymbol);
VerifyToken(TY_IDENTIFIER, "identifier");
@ -200,6 +200,11 @@ struct ASTNode* ParseFunction(int Type) {
ParamCount = ReadDeclarationList(OldFunction, SC_GLOBAL, LI_RPARE);
VerifyToken(LI_RPARE, ")");
printf("\nIdentified%sfunction %s of return type %s, end label %d\n",
(OldFunction == NULL) ? " new " : " overloaded ",
(OldFunction == NULL) ? NewFunction->Name : OldFunction->Name,
TypeNames(Type), BreakLabel);
if(NewFunction) {
NewFunction->Elements = ParamCount;
NewFunction->Start = Params;
@ -213,9 +218,6 @@ struct ASTNode* ParseFunction(int Type) {
return NULL;
}
printf("\nIdentified%sfunction %s of return type %s, end label %d\n", (OldFunction == NULL) ? " new " : " overloaded ", OldFunction->Name, TypeNames(Type), BreakLabel);
FunctionEntry = OldFunction;
Tree = ParseCompound();

6
tests/struct.er Normal file
View File

@ -0,0 +1,6 @@
struct a {
int x,
int y
};
int main() { return (0); }