Skip to main content

Questions tagged [control-flow]

For questions about various ways or constructs to control the flow of a program, such as if statements, goto statements, loops, switch statements, etc.

Filter by
Sorted by
Tagged with
4 votes
1 answer
249 views

How to implement a control flow analyser?

I'm finishing right now the lambda expression's resolution for an ActionScript 3 compiler, but, in terms of control flow analysis I've some difficulty to get into it. I've searched for some existing ...
Hydroper's user avatar
  • 1,017
6 votes
1 answer
147 views

What to do with subroutine calls when translating Abstract Syntax Tree to Control Flow Graph?

A newbie here! I'm implementing my current compiler in Haskell and at the moment I'm trying to do the translation of AST to Basic Blocks. Based on the book "Advanced Compiler Design and ...
NotAlfred's user avatar
  • 145
8 votes
1 answer
378 views

How can I account for expressions when building control-flow graphs?

How do statically typed programming languages build CFGs for programs containing expression-level control flow (e.g. ternary expressions, match expressions) which require transformation or extra ...
WZoG's user avatar
  • 83
32 votes
10 answers
9k views

Avoiding student confusion about the meaning of `x == a or b`

I'm designing a language intended to teach kids and other beginners how to program. It's just a fork of Python with a few extra features to make it easier to learn. I've noticed students make one ...
mousetail's user avatar
  • 8,531
12 votes
7 answers
1k views

A conditional block with unconditional intermediate code

One problem that is hard to make not at least somewhat repetitive is if there is code that needs to be executed in a certain order, and the intermediate code is unconditional but first and last code ...
CPlus's user avatar
  • 8,503
4 votes
1 answer
190 views

Correct terminology and relationship between program counters, continuations & contexts

Starting with a representation of a item of computation as an object which includes a method says how to perform the next step of its computation. ...
Bruce Adams's user avatar
  • 2,853
24 votes
3 answers
778 views

How to transpile goto to a language that lacks it?

I'm writing a transpile for a C-like language to Javascript, which lacks a goto statement. Unfortunately the existing library code contains a lot of ...
mousetail's user avatar
  • 8,531
10 votes
4 answers
384 views

How to transpile labelled break/continue statements to a high-level language which lacks them?

Suppose I am writing a source-to-source compiler (also called a transpiler) from one high-level imperative language to another, where the source language allows labelled statements to be targeted by <...
kaya3's user avatar
  • 20k
12 votes
3 answers
2k views

Why does Rust have an infinite loop construct?

The Rust programming language has an infinite loop construct, which looks like this: loop { <some code> } It's the only language I can think of that has ...
Ginger's user avatar
  • 2,629
10 votes
1 answer
345 views

How do I implement AOT compilation of my 2-D esolang?

Background Trilangle is an interpreted 2-D esolang that I made in February and March of this year. At some point, I had the idea to implement an ahead-of-time compiler for the language, and what ...
Bbrk24's user avatar
  • 9,117
7 votes
2 answers
197 views

What are the different options for breaking out of an inner loop?

In languages such as C, to break/continue out of an inner loop, there is no direct way so one must use ...
CPlus's user avatar
  • 8,503
14 votes
13 answers
2k views

What are the pros and cons of goto?

Goto is often "considered harmful". But are there good reasons to have goto? If not, what are some of the cons associated with it that imply it should be avoided?
a coder's user avatar
  • 685
3 votes
3 answers
176 views

Why do some languages not have an 'unreachable' function?

Several languages have a function or macro to indicate that a certain point in control flow cannot be reached, even though the compiler cannot statically prove it, such as ...
Bbrk24's user avatar
  • 9,117
12 votes
2 answers
196 views

How do linear types interact with features that may change the normal control flow?

Linear types are quite a powerful feature of type systems that ensure that "linear values" are used exactly once. For example, ...
Luiz Felipe's user avatar
9 votes
3 answers
264 views

How to compile exceptions?

What are the most common ways of compiling code of a language with first-class support for exceptions, such as C++? Panics in Rust, which have similar behavior, shouldn't be too different. From my ...
Luiz Felipe's user avatar
6 votes
2 answers
319 views

What are the advantages of conditional statements having their own scope?

What are the advantages of conditionals having their own scope? I know this can lead to some extra variables for some programs. But it can also be more memory efficient. Credit to Hg0428 for the idea ...
Ethan's user avatar
  • 377
18 votes
7 answers
1k views

What are the pros and cons of having do ... while loops?

One somewhat rarely used, but still occasionally handy, feature of many programming languages is do ... while loops: ...
Rydwolf Programs's user avatar