r/ProgrammingLanguages • u/Key_River7180 Nain. • 1h ago
Would a syntaxless programming language be possible?
So I had the idea of a syntaxless programming language where a function parses its form as it needs.
In this system, a parser is a function turning a description of the syntax to a kind of binding
parser: forms -> (given syntax) -> binding;
For example:
template ([a] is in between [min] and [max]) # binding
:= a >= min and a <= max; # lambda
Idk just a cool idea. There are many problems with this (for starters, when do you know what parser to use?)
0
Upvotes
7
u/kohugaly 1h ago
I'm pretty sure this is just macros.
3
u/titaniumalt 1h ago
how would you write said functions? more specifically, in what language?
11
u/mooglinux 59m ago
…so Lisp?
1
u/Mission-Landscape-17 1h ago
So you want a language that lets you add new syntax whenever? You can do this in Prolog.
1
u/asdfa2342543 53m ago
So when you say “no syntax” i guess you mean no primitive tokens? If so I’ve been trying something that fits that bill for a long time.
The conclusion i came to is that there still is a syntax of a kind in the position. There’s implicitly something like a data constructor with positional arguments. However I still haven’t come up with a 100% nailed down semantics with literally 0 hardcoded tokens. I do suspect it’s possible after digging into some relevant math, computer science, and type theory. Here’s a post about aspects of it: https://spacechimplives.substack.com/p/computing-with-geometry
3
u/alaricsp 55m ago
FORTH has this. A word, when referenced during compilation, can be invoked "immediately" and access the input stream the compiler is compiling and do whatever parsing it wants, then compile code to do whatever needs doing at run time. For instance, the word " parses string literal syntax up to the next ", tucks the string away in memory, and then compiles code to push a pointer to it at run time to the stack, thereby providing string literals!
2
u/pthierry 13m ago
In theory, this is probably possible. You could attach a parser to an identifier, and when one such parser says it's done, you look for the next identifier.
The issue is that it makes the language unreadable, and worse, impossible to apply syntax highlighting, because only the local parser knows where it stops.
1
u/to7m 43m ago
I started working on a programming language with no syntax in 2020: gitlab.com/to7m/433
It got some unkind comments in this sub, with people saying it didn't even count as a programming language, so I stopped working on it.
In addition to not having syntax, it also does not have function definitions, grammar, operators, etc. As such, it is not currently possible to write programs in it like you describe.
1
u/NomagnoIsNotDead 24m ago edited 13m ago
So, taking the replies to far, have my ramblings:
Lisp qualifies as having no syntax, in the sense that you *can't* use any syntax other than S-expressions, which are just trees (some implementations let you mess with the parsing FORTH-style but not universal).
FORTH qualifies as having no syntax, in the sense that you can have any syntax you please by manipulating the input stream, the basic 'syntax' is just concatenating word/function invocations, and you can override any function name. However, you sure as hell do have a 'default' syntax as well as a syntax during the bootstrapping process.
Smalltalk... well it has syntax so it doesn't qualify! But it's pretty minimal as well and often mentioned in the same breath as FORTH and Lisp.
The most radical definition of 'no syntax' could hence be: having no reserved tokens, AND having no clear structure that makes use these reserved tokens even during the bootstrapping process.
If we're getting esoteric, maybe some kind of language that infers the syntax at the start of the program, or that lets you configure the syntax at the start of the program? Or that uses no reserved tokens but uses the specific tokens you specify as part of its syntax?
A silly example that probably qualifies under the last definition but is otherwise uninteresting, with syntax 'function-name arg1 arg2 ... argN argN body function-name' , with the last argument repeated to terminate the argument list, and the function name repeated to terminate the body, making it freeform:
This silly example evidently doesn't support recursion or side effects, but you can add more builtin functions like readInput to assist in this, and changing the syntax on-the-go, I guess, but at which point are you re-inventing FORTH? (at a pretty early in that thought experiment). This'd probably have to be postfix to be useful since grouping is currently impossible unless you add parentheses, and you can argue that this has a clear syntax but it is simply extremely non-context-free.
Combinator calculi don't really have any syntax, but they also have no built-in way to perform abstraction, which hardly qualifies as a programming LANGUAGE.