Let's make a programming language. Functions—Key points
We continue the development of our toy programming language. In this episode, our speaker Yuri demonstrates how to implement functions and explains how functions, scopes, and symbol lookup are built in code using C++. About the speaker Yuri Minaev is an experienced C++ developer, architect at PVS-Studio, and a recognized voice in the C++ community who has spoken at CppCast, C++ on Sea, and…
In the latest episode of the "Let's make a programming language" series, Yuri Minaev, a C++ developer and architect at PVS-Studio, demonstrates how to implement functions in the toy language using C++. Functions introduce multiple scopes and different levels of name visibility, with names declared inside a function being inaccessible outside it while names from parent scopes remain accessible.
Parsing functions involves declaring them with the 'fn' keyword, specifying parameters, and defining a compound statement containing the function body. Functions are parsed in two stages: declaration and body processing. The semantic analyzer determines a function's return type from return statements, checks compatibility, and adds implicit casts when necessary.
An empty function with no return statements gets the void type. The talk concludes with functions implemented and introduces the evaluator as the next step.
Brief written by urgent.news from Dev.to's own syndicated text. Machine-written — may contain errors; check the original before relying on it.