WIP: If statements

Something is consuming too much if statement wise (only when `else` is present though)
This commit is contained in:
Tristan B. Kildaire 2021-03-18 21:06:10 +02:00
parent 4322c2aa0c
commit 808c124724
2 changed files with 18 additions and 6 deletions

View File

@ -131,9 +131,12 @@ public final class Parser
/* Pop off the `else` */ /* Pop off the `else` */
nextToken(); nextToken();
/* Check if we have an `if` after the `else` (so an "else if" statement) */ /* Check if we have an `if` after the `{` (so an "else if" statement) */
if (getSymbolType(getCurrentToken()) == SymbolType.IF && !reachedElse) if (getSymbolType(getCurrentToken()) == SymbolType.IF && !reachedElse)
{ {
/* Pop off the `if` */
nextToken();
/* Expect an opening brace `(` */ /* Expect an opening brace `(` */
expect(SymbolType.LBRACE, getCurrentToken()); expect(SymbolType.LBRACE, getCurrentToken());
nextToken(); nextToken();
@ -151,20 +154,26 @@ public final class Parser
expect(SymbolType.CCURLY, getCurrentToken()); expect(SymbolType.CCURLY, getCurrentToken());
nextToken(); nextToken();
} }
/* Check for opening brace (just an "else" statement) */ /* Check for opening curly (just an "else" statement) */
else if (getSymbolType(getCurrentToken()) == SymbolType.ELSE) else if (getSymbolType(getCurrentToken()) == SymbolType.OCURLY)
{ {
/* TODO: Implement me */ /* TODO: Implement me */
import std.stdio;
writeln("EYO ELSE");
/* Opening { */ /* Opening { */
writeln("Bruh"~to!(string)(getCurrentToken()));
nextToken(); nextToken();
expect(SymbolType.OCURLY, getCurrentToken());
/* Parse the if' statement's body AND expect a closing curly */ /* Parse the if' statement's body AND expect a closing curly */
parseBody(); parseBody();
expect(SymbolType.CCURLY, getCurrentToken()); expect(SymbolType.CCURLY, getCurrentToken());
nextToken(); nextToken();
writeln("EYO ELSE (END):");
writeln("Bruh"~to!(string)(getCurrentToken()));
/* Don't allow anything to follow after this */ /* Don't allow anything to follow after this */
reachedElse = true; reachedElse = true;
} }
@ -173,6 +182,7 @@ public final class Parser
{ {
/* TODO: Add error */ /* TODO: Add error */
/* TODO: DO we need this here? */ /* TODO: DO we need this here? */
expect("fok");
} }
} }
@ -191,6 +201,8 @@ public final class Parser
else else
{ {
/* TODO: Add error */ /* TODO: Add error */
import std.stdio;
writeln("Bruh"~to!(string)(getCurrentToken()));
break; break;
} }
} }

View File

@ -29,7 +29,7 @@ class clazz_2_1
if(1) if(1)
{ {
print(1);
} }
else else
{ {
@ -38,7 +38,7 @@ class clazz_2_1
if(1) if(1)
{ {
print(1);
} }
else else
{ {