Writing a BNF Grammar
dev.to
dev.to
Not THAT being said I will contradict myself: when you are writing a tiny language like that it’s easy to accidentally add dependencies like context-sensitive behavior. Which means if things grow to the point where you need a parser generator it may become much harder.
Has anyone else here read/seen this book and can you remember the exact titles?
Alternatively, you can split the parsing into stage. Take XML for instance. The fact that it's opening and closing tags must be marked by the same identifier makes it context sensitive. You can however get around that by simply registering opening and closing tags in the parsing stage, and verify they match only later.
Really, though: if you have the liberty to design the syntax yourself, context sensitivity is generally best avoided. Heck, you probably want to limit yourself to a subset of context free grammars, like LR (which is guaranteed non-ambiguous). You can restrict even further, and stick to LL(1) —which goes a long way if you parse binary operators in a later stage, with shunting yard or precedence climbing.
Easier parsing means easier tooling, more predictable syntax, easier error handling… Sure, if you don't have a choice (compatibility or business imperative), you can introduce some context sensitivity. Ideally though, you want to use the least powerful grammar you can get away with.
An alternative is to skip a parser generator entirely and so something like a recursive descent parser, which can easily collect any needed context as it goes, and use that in deciding how to parse anything context sensitive.