json++

I figured out the easiest way to 'make your own programming language' ever: use the existing syntax of JSON and just have the content be the code.

Here's a sample:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
	"main":
	{
		"params": ["args"],
		"code":
		[
			{"if": [{"infix": [{"==": [{"len": ["args"]}, 2]},
			                    "&&", {"&&": [{"is num": [{"[]": ["args", 0]}]},
			                                  {"is num": [{"[]": ["args", 1]}]}]}]}],
				"false": [{"return": null}]
			},
			{"return": {"foo": [{"[]": ["args", 0]}, {"[]": ["args", 1]}]}}
		]
	},
	"foo":
	{
		"params": ["a", "b"],
		"code":
		[
			[{"c": 0}],
			{":=": ["c", {"+": ["a", "b"]}]},
			{"return": "c"}
		]
	}
}
This program, when executed, will either return null if you don't give it an array of two numbers, or it will return the value returned from calling function foo, which adds the two numbers together.

Absolutely and beautifully convoluted. Should remind some of you of the nested look of functional languages.

I've got a repo where I'm working on the interpreter:
https://github.com/LB--/jsonpp
It will be a fun side project :)

The challenging part will be figuring out how I want to represent string literals...
Last edited on
closed account (18hDSL3A)
You should write the interpreter in Brainfuck.
That's far beyond my skill level and patience.
Pfff, brainfuck is for plebes. Make a malbolge interpreter.
I expected this to be taken a little more seriously...
closed account (N36fSL3A)
Machine code all the way.

Anyway, what is this going to be used for anyway?
closed account (Dy7SLyTq)
Or... you could design a language without actually making a library or interprer/compiler and write the new language in that
closed account (N36fSL3A)
you could design a language without actually making a library or interprer/compiler
wut
Last edited on
@LB

Your JSON idea has some parallels with the arguments in this article:

The Nature of Lisp
http://www.defmacro.org/ramblings/lisp.html

The bulk of my programming language experience is with assorted imperative languages, but I'm currently making another attempt to actually "get" functional languages. And one of my web searches, for a good explanation of what functional programming is all about, led me to the above article; it uses XML, along with Ant and C macros, to describe how Lisp works to functional neophytes.

The Nature of Lisp wrote:
Everything we've learned about Lisp so far can be summarized by a single statement: Lisp is executable XML with a friendlier syntax.

As JSON can store the same sort of data as XML, I assume the parallels hold in your case, too.

Andy
Last edited on
Hah, that's neat. Though I've come to discover long ago that converting XML to JSON is not a friendly process. The PHP way is actually kind of buggy - you get correct translations in some cases but you lose data in others.

As for what json++ will be useful for, it will be useful for my brain as the project will provide learning and experience. And maybe it'll just be nifty.
Last edited on
closed account (Dy7SLyTq)
@lumpkin: make a pseudo language and write a compiler/interpeter in that
This isn't a thread about extreme programming languages or challenging each other to do something really hard.
Topic archived. No new replies allowed.