diff --git a/src/Delegate.c b/src/Delegate.c index a8e9842..188a5bc 100644 --- a/src/Delegate.c +++ b/src/Delegate.c @@ -51,19 +51,19 @@ char* Suffixate(char* String, char Suffix) { /* - * Starts most of the work to do with the Erythro compiler. - * It: - * Opens the input and output files, - * Parses the global symbols of the file, including function blocks. - * Generates the assembly representation of the source code - * Saves said assembly into the OutputFile - * Returns the name of the file containing the generated assembly. - * Note that the Input file must have a valid extension. - * For Erythro code, this is .er - * The generated assembly will have the extension .s + * Starts most of the work to do with the Erythro compiler. + * It: + * Opens the input and output files, + * Parses the global symbols of the file, including function blocks. + * Generates the assembly representation of the source code + * Saves said assembly into the OutputFile + * Returns the name of the file containing the generated assembly. + * Note that the Input file must have a valid extension. + * For Erythro code, this is .er + * The generated assembly will have the extension .s * - * @param InputFile: The filename of the Erythro Source code to compile - * @return the filename of the generated PECOFF32+ assembly + * @param InputFile: The filename of the Erythro Source code to compile + * @return the filename of the generated PECOFF32+ assembly */ char* Compile(char* InputFile) { char* OutputName; diff --git a/src/Parser.c b/src/Parser.c index 3a24512..47a710b 100644 --- a/src/Parser.c +++ b/src/Parser.c @@ -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,12 +553,9 @@ 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; } } diff --git a/src/Pointers.c b/src/Pointers.c index ca5312f..83a3723 100644 --- a/src/Pointers.c +++ b/src/Pointers.c @@ -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? } diff --git a/src/Statements.c b/src/Statements.c index 08af38a..8bc9df7 100644 --- a/src/Statements.c +++ b/src/Statements.c @@ -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; @@ -212,9 +217,6 @@ struct ASTNode* ParseFunction(int Type) { Tokenise(); 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; diff --git a/tests/struct.er b/tests/struct.er new file mode 100644 index 0000000..2fcf6c0 --- /dev/null +++ b/tests/struct.er @@ -0,0 +1,6 @@ +struct a { + int x, + int y +}; + +int main() { return (0); } \ No newline at end of file