> That sounds pretty hard / impossible to do.
Why do you think that?
This is how most compilers used to work.
And languages like Pascal were specifically designed to be able to be compiled in a mostly single pass.
Look up ‘syntax directed translation’ in an old compiler textbook.