terrajobst / minsk

This repo contains Minsk, a handwritten compiler in C#. It illustrates basic concepts of compiler construction and how one can tool the language inside of an IDE by exposing APIs for parsing and type checking.

Home Page:http://minsk-compiler.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] A different lowering for while-statement perhaps

jigargandhi opened this issue · comments

commented

Hey @terrajobst,

I am really enjoying your compiler series.
In episode 8 lowering, you have mentioned while statement as sequence of steps

  • goto check
  • continue
  • body
  • gotoTrue condition continue
  • end

Perhaps, what if we had a version with one less label as follows

  • begin
  • gotoFalse condition end
  • body
  • goto begin
  • end

Would it impact anytime later?

Thanks!!

I think you're right that we could have gotten away with fewer labels in that episode.

But eventually we'll need to have at least two labels per loop: one for jumping out of the loop and one for continuing the loop. Those two labels are the jump targets for the break and continue statements. You can see this in episode 13.

commented

Yeah, when we have break and continue in loops additional labels might be necessary. Thanks for your explanation. Keep rocking with the series :)

Thanks for watching and asking questions ☺️