Fixed if statement parsing bug

if_statement_parsing
Tristan B. V. Kildaire 2021-03-20 15:24:39 +02:00
parent 7882b49c72
commit 5874a4c801
1 changed files with 10 additions and 1 deletions

View File

@ -93,8 +93,15 @@ public final class Parser
bool hasIf; bool hasIf;
bool reachedElse; bool reachedElse;
ulong i = 0;
while (hasTokens()) while (hasTokens())
{ {
i++;
import std.stdio;
writeln("Token: "~getCurrentToken().getToken());
writeln("Current parseIf while: "~to!(string)(i));
writeln("Bababooey: "~to!(string)(getSymbolType(getCurrentToken()) == SymbolType.ELSE && hasIf));
// /* If else has been reached then exit */ // /* If else has been reached then exit */
// if(reachedElse) // if(reachedElse)
// { // {
@ -124,6 +131,8 @@ public final class Parser
expect(SymbolType.CCURLY, getCurrentToken()); expect(SymbolType.CCURLY, getCurrentToken());
nextToken(); nextToken();
writeln("American boy: "~getCurrentToken().getToken());
hasIf = true; hasIf = true;
} }
else if (getSymbolType(getCurrentToken()) == SymbolType.ELSE && hasIf) else if (getSymbolType(getCurrentToken()) == SymbolType.ELSE && hasIf)
@ -164,7 +173,7 @@ public final class Parser
/* Opening { */ /* Opening { */
writeln("Bruh"~to!(string)(getCurrentToken())); writeln("Bruh"~to!(string)(getCurrentToken()));
nextToken(); // nextToken();
/* Parse the if' statement's body AND expect a closing curly */ /* Parse the if' statement's body AND expect a closing curly */
parseBody(); parseBody();