2 ms·
> Features I want are: * pythonic indent * no trailing semicolon I would recommend against making up a completely new syntax, since there would be no support i
by chriswarbo 8y ago
> Features I want are: * pythonic indent * no trailing semicolon
I would recommend against making up a completely new syntax, since there would be no support in any existing tools (parsers, linters, IDEs, formatters, ...). Instead, I'd suggest picking a general-purpose syntax with the properties you want (indentation for grouping, newlines for sequencing). One excellent example is called "sweet-expressions", which was originally invented for Scheme but can actually be used to represent any structured data (especially code):
https://srfi.schemers.org/srfi-110 https://srfi.schemers.org/srfi-110
You can use tools like "sweeten" and "unsweeten" from https://sourceforge.net/projects/readable/files https://sourceforge.net/projects/readable/files to convert between sweet-expressions and s-expressions. S-expressions are just raw syntax trees, so "unsweeten" is basically a ready-made parser which you can pipe into any other program you like, e.g. linters, macro expanders, pretty-printers, etc.
To make your language compile to C, you would need some way to "render" those syntax trees into C code. There are existing tools to do this, for example the C-Mera system can read in C syntax trees and write out C code https://github.com/kiselgra/c-mera https://github.com/kiselgra/c-mera
Your preprocessor could then be as simple as `unsweeten | cm c`
To add completely new features like immutable strings you would just need to define some representation for them in the syntax trees (or, if you want to make them the default for "double quotes" you should define an alternative representation for non-immutable strings), then write some find/replace macros to convert occurrences of this representation into an equivalent (but more verbose and elaborate) set of C syntax trees. Stick this find/replace step in between `unsweeten` and `cm` and you've got brand new syntax for very little work.