In the book Crafting Interpreters, at the end of chapter 16, the following challenge is made:
What tokens would you emit for:
"Nested ${"interpolation?! Are you ${"mad?!"}"}"
Instead of inventing new tokens, another solution might be to rewrite this code, in machine-readable form and less-human-readable form, using tokens that already exist, and inventing a new runtime library primitive “strcat” (for “string concatenate”), e.g.
Working Python code for this is:
And a parse tree for this might be:
See Also
Email: ptcomputingsimplicity@gmail.com
References: https://guitarvydas.github.io/2024/01/06/References.html
Blog: guitarvydas.github.io
Videos: https://www.youtube.com/@programmingsimplicity2980
Discord: https://discord.gg/65YZUh6Jpq
Leanpub: [WIP] https://leanpub.com/u/paul-tarvydas
Gumroad: tarvydas.gumroad.com
Twitter: @paul_tarvydas
Substack: paultarvydas.substack.com