Ask HN: How do you extend a programming language?
For example, if I want to implement new set of operators or introduce the idea of group(a specific method to collect variables and functions), How do I do that?
For example, if I want to implement new set of operators or introduce the idea of group(a specific method to collect variables and functions), How do I do that?
For instance, there is often a "lexical analyzer" that interprets things like word boundaries, numbers and string literals.
Then there is a parser that implements the grammar of a language and creates an "abstract syntax tree"
Then usually there are several phases of transformation before creating machine code or structures that are interpreted.
To add a new feature to a language you will probably need to change several of these layers. For instance, you will need to add new syntax to the parser and then add an implementation. In some cases these changes may be localized, for instance, if you want to add an unless() keyword which works like if() but has a reversed sense, you can probably write a transformation close to the parser which just replaces the unless(X) structure with if(not(X)). Other changes could be more extensive.