---
title: "Discussion on \"Build a Compiler from Scratch, Part 1.1: A Hello World of sorts\" | Hashnode"
description: "Discussion on \"Build a Compiler from Scratch, Part 1.1: A Hello World of sorts\". It has become common practice to start with a \"Hello World\" program when learning a new programming language.\nThis is a simple program that outputs the text \"Hello, World!\" to the screen. While writing such a program \nis a trivial task with most prog..."
url: "https://hashnode.com/posts/build-a-compiler-from-scratch-part-11-a-hello-world-of-sorts/685b368a2c1dbdb423ba0c92"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Build a Compiler from Scratch, Part 1.1: A Hello World of sorts](https://blog.sylver.dev/build-a-compiler-from-scratch-part-11-a-hello-world-of-sorts?utm_source=hashnode&utm_medium=feed)

It has become common practice to start with a "Hello World" program when learning a new programming language. This is a simple program that outputs the text "Hello, World!" to the screen. While writing such a program is a trivial task with most prog...

Jun 24, 2025 · 22 min read · blog.sylver.dev  
Updated Aug 3, 2025  
Read the article

-   [#rust](https://hashnode.com/tag/rust)
-   [#compiler](https://hashnode.com/tag/compiler)
-   [#tutorial](https://hashnode.com/tag/tutorial)

## Written by

[Geoffrey Copin](https://hashnode.com/@Sylver)

@Sylver

  
[View profile](https://hashnode.com/@Sylver)

## Responses 1

Markdown supported · ⌘↵ to post

[Raiyan Hossain](https://hashnode.com/@zireael9797)

[Aug 3, 2025](https://hashnode.com/posts/build-a-compiler-from-scratch-part-11-a-hello-world-of-sorts/685b368a2c1dbdb423ba0c92/comment/688ee4dc3598c01e878a1013)

```
impl Iterator for Lexer<'_> {
    type Item = (Token, Span);

    fn next(&mut self) -> Option<Self::Item> {
-       self.next_token();
+       self.emit_next_tokens();
+       self.token_queue.pop_front()
    }
}
```

One question here

emit\_next\_tokens(); can push one or more tokens to the queue.

pop\_front(); only consumes one. Does this not mean the queue will race ahead of the iteration?

I tried setting type Item = (Token, Span, u32 /_Current Queue Size_/) with a longer bit of code with a lot of indentation and it did race ahead. It's possible I missed something else elsewhere.

[Geoffrey Copin](https://hashnode.com/@Sylver)

[Aug 3, 2025](https://hashnode.com/posts/build-a-compiler-from-scratch-part-11-a-hello-world-of-sorts/685b368a2c1dbdb423ba0c92/comment/688ee4dc3598c01e878a1013#reply-688fbdd33254f7291d881958)

You are absolutely correct! It would be better to check the length of the token queue before trying to emit new tokens. I edited the code accordingly
