Fixes to struct parsing
This commit is contained in:
parent
72358aed9f
commit
8263fb853b
21
src/Parser.c
21
src/Parser.c
|
@ -511,13 +511,20 @@ struct ASTNode* ParseCompound() {
|
||||||
|
|
||||||
void ParseGlobals() {
|
void ParseGlobals() {
|
||||||
struct ASTNode* Tree;
|
struct ASTNode* Tree;
|
||||||
|
struct SymbolTableEntry* Composite;
|
||||||
int Type, FunctionComing;
|
int Type, FunctionComing;
|
||||||
|
|
||||||
printf("Parsing global definitions\r\n");
|
printf("Parsing global definitions\r\n");
|
||||||
|
|
||||||
while(1) {
|
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");
|
printf("New definition incoming..\r\n\n");
|
||||||
Type = ParseOptionalPointer(NULL);
|
Type = ParseOptionalPointer(&Composite);
|
||||||
|
|
||||||
//TODO: converge pathways on this block?
|
//TODO: converge pathways on this block?
|
||||||
if(CurrentToken.type == KW_FUNC) {
|
if(CurrentToken.type == KW_FUNC) {
|
||||||
|
@ -525,6 +532,13 @@ void ParseGlobals() {
|
||||||
FunctionComing = 1;
|
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");
|
VerifyToken(TY_IDENTIFIER, "ident");
|
||||||
|
|
||||||
if(FunctionComing && CurrentToken.type == LI_LPARE) {
|
if(FunctionComing && CurrentToken.type == LI_LPARE) {
|
||||||
|
@ -539,13 +553,10 @@ void ParseGlobals() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("\tParsing global variable declaration\n");
|
printf("\tParsing global variable declaration\n");
|
||||||
BeginVariableDeclaration(Type, NULL, SC_GLOBAL);
|
BeginVariableDeclaration(Type, Composite, SC_GLOBAL);
|
||||||
VerifyToken(LI_SEMIC, ";");
|
VerifyToken(LI_SEMIC, ";");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(CurrentToken.type == LI_EOF)
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,12 +104,12 @@ int ParseOptionalPointer(struct SymbolTableEntry** Composite) {
|
||||||
// x = **y;
|
// x = **y;
|
||||||
// possible.
|
// possible.
|
||||||
while(1) {
|
while(1) {
|
||||||
Tokenise();
|
|
||||||
printf("\t\t\tType on parsing is %d\n", CurrentToken.type);
|
printf("\t\t\tType on parsing is %d\n", CurrentToken.type);
|
||||||
if(CurrentToken.type != AR_STAR)
|
if(CurrentToken.type != AR_STAR)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
Type = PointerTo(Type);
|
Type = PointerTo(Type);
|
||||||
|
Tokenise();
|
||||||
// Tokenise(); TODO: is this skipping pointers?
|
// Tokenise(); TODO: is this skipping pointers?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ static int ReadDeclarationList(struct SymbolTableEntry* FunctionSymbol, int Stor
|
||||||
if(FunctionSymbol != NULL)
|
if(FunctionSymbol != NULL)
|
||||||
PrototypePointer = FunctionSymbol->Start;
|
PrototypePointer = FunctionSymbol->Start;
|
||||||
|
|
||||||
while(CurrentToken.type != LI_RPARE) {
|
while(CurrentToken.type != End) {
|
||||||
TokenType = ParseOptionalPointer(FunctionSymbol);
|
TokenType = ParseOptionalPointer(FunctionSymbol);
|
||||||
VerifyToken(TY_IDENTIFIER, "identifier");
|
VerifyToken(TY_IDENTIFIER, "identifier");
|
||||||
|
|
||||||
|
@ -200,6 +200,11 @@ struct ASTNode* ParseFunction(int Type) {
|
||||||
ParamCount = ReadDeclarationList(OldFunction, SC_GLOBAL, LI_RPARE);
|
ParamCount = ReadDeclarationList(OldFunction, SC_GLOBAL, LI_RPARE);
|
||||||
VerifyToken(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) {
|
if(NewFunction) {
|
||||||
NewFunction->Elements = ParamCount;
|
NewFunction->Elements = ParamCount;
|
||||||
NewFunction->Start = Params;
|
NewFunction->Start = Params;
|
||||||
|
@ -213,9 +218,6 @@ struct ASTNode* ParseFunction(int Type) {
|
||||||
return NULL;
|
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;
|
FunctionEntry = OldFunction;
|
||||||
|
|
||||||
Tree = ParseCompound();
|
Tree = ParseCompound();
|
||||||
|
|
6
tests/struct.er
Normal file
6
tests/struct.er
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
struct a {
|
||||||
|
int x,
|
||||||
|
int y
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() { return (0); }
|
Loading…
Reference in New Issue
Block a user