Comment by juancn

7 days ago

I never got why compilers don't have pluggable syntaxes.

I mean, once you decide the "flavor" (e.g.: typed, imperative, with a dash of functional and some oop for good measure), you could have more than one syntax and easily switch to whatever the reader wants.

We had an integration language in a product I worked on that had three flavors (you can check it here: https://docs.oracle.com/cd/E13154_01/bpm/docs65/pdf/OracleBP... , page 254)

The original syntax scared some people, so we had the compiler use the same AST with three different parsers: Original, Java and VB. The editor (which had syntax highlighting and auto completion) would let you see the code however you wanted.

You could even have a setting in the IDE that always showed the code as you wanted.

We even respected some weirdness in the spacing and indentation of comments and code when needed.

For some languages, like rust it may be a stretch, but for most vanilla languages, you could easily re-skin them to look much more like something else, that's comfy for whoever is looking at the code.

> I never got why compilers don't have pluggable syntaxes.

Because then you've created dialects and produced the Curse of Common Lisp all over again.

Syntax matters a heck of a lot, and you want consistency and coherency across codebases of the same language, otherwise you don't have a language at all. So wanting it "pluggable" is in fact the worse possible choice you want.

It's also a naïve view to think that concrete syntax can be trivially swapped out with the abstract syntax remaining. For certain things it can usually work (like declaration syntax in the article) but for most things it cannot.

> I never got why compilers don't have pluggable syntaxes.

An interesting question, but the answer is "because it's a bad idea" that doesn't actually solve the problem.

That said, the right way to implement this is as a "transpiler" that compiles one syntax into another. And only the people who want to use it pay the costs.

  • > An interesting question, but the answer is "because it's a bad idea" that doesn't actually solve the problem.

    This doesn't really explain anything, and it isn't clear that both of you have the same model of "the problem" in mind.

    • The usual way people get here is that they didn't realise programs are for reading by humans. That's why we have formatting conventions (the compiler doesn't care but humans do) and so it's also why a single syntax is important.

      If there are six syntaxes for a hypothetical language L, then either every L practitioner must learn all six syntaxes (ew, no thanks) or most L programmers can't read each other's programs and so it's basically unmaintainable.

Code is communication. The compiler could handle it, but what is important is that other people can.

There are many infamous examples of people using the C preprocessor to write near-Pascal or similar in C. It largely died out because it hindered effective communication about the code.