Closed NeeEoo closed 3 years ago
Do you know a way to get the token after a statement?
Since if the compiler allows non-bracketed statements in compile_if
, the self.parser.find_matching()
wouldn't work.
If the compiler compiles the statement before checking if there exists an else token the stack pointer would be wrong.
One way that i can think of is to save the current token index to a variable, and run compile_statement
and then save the current token index to another variable, then set the token index back to what it was before, and then we get the token.
But that seems a bit unnecessary to compile the statement twice. Once during checking and then again when converting to code.
@elikaski I also need help with the for loop. Since it handles the inner scope differently than the other.
fixed in 0d0bc8800dd10fb8669cd5cb4259038dbf575418
Thank you. The code for if else looks a lot better than mine.
The only thing with the new implementation is that else-less ifs takes up a little more bytes.
You're right, we do waste a cell for if without else but that's a price I'm willing to pay 🤷
Might be able to fix it sometime in the future.
After reading more, the braces that defines a scope is in fact a statement. And
for
,if
,else
andwhile
inner code wants a statement.So, this could maybe be merged and then removed later in another pull request that fixes it so that
for
,if
,else
andwhile
wants a statement in its inner code.