r/ProgrammingLanguages • 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

19 comments sorted by

7

u/kohugaly 1h ago

I'm pretty sure this is just macros.

1

u/Key_River7180 Nain. 1h ago

similar yeah

3

u/titaniumalt 1h ago

how would you write said functions? more specifically, in what language?

2

u/Key_River7180 Nain. 1h ago

idk:

parser(parser ([forms... :[string]])) := parse input and make a parser

You'd need a bootstrapping one of some kind

2

u/titaniumalt 1h ago

yes, i am talking about said bootstrapping language, how would that work?

1

u/Key_River7180 Nain. 39m ago

Probably implemented in the compiler

1

u/bl4nkSl8 25m ago

That's a syntax...

4

u/Albert_Custard 52m ago

By having a syntax

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/Key_River7180 Nain. 1h ago

more or less

1

u/samanzaman 55m ago

Agda can do it as well ( in a quite sophisticated way). Their website should also have the relevant research papers

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

1

u/Key_River7180 Nain. 38m ago

This doesn't have positional arguments or stuff

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/NomagnoIsNotDead 11m ago

This is a problem with FORTH! You can't hope to properly syntax-highlight a real codebase because any random word/function can hijack the input stream.

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:

TRUE x y y
x
TRUE

MAIN ignored ignored
TRUE readInput readInput
MAIN

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.