Fixes to struct parsing
This commit is contained in:
parent
72358aed9f
commit
8263fb853b
|
@ -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;
|
||||
|
|
21
src/Parser.c
21
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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?
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
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