Skip to content

Instantly share code, notes, and snippets.

@djedr
Last active July 4, 2023 21:35
Show Gist options
  • Save djedr/151241f1a9a5bc627059dd9b23fc7432 to your computer and use it in GitHub Desktop.
Save djedr/151241f1a9a5bc627059dd9b23fc7432 to your computer and use it in GitHub Desktop.

This gist expands on this Hacker News reply.


The official Jevko spec is meant to be fully generic, but in fact if you don't care about that then you can use this simplifed grammar to start (ABNF + RegExp):

tree = *sub text
sub  = text '[' tree ']'
text = /[^\[\]]*/

Meaning:

  • a tree is zero or more subs followed by text
  • a sub is text followed by tree enclosed in square brackets
  • text is zero or more characters which are not square brackets

A basic parser for this grammar is less than 50 lines of basic code in any programming language (e.g. 25 lines of JavaScript). No lexer needed.

Once you have a tree structure you can start transforming and then interpreting it!

This is what I've been doing recently with my latest language experiment and it is going rather nicely.

Here is some example code written in this language:

let[
  [even?]  fn[  [n]
    ?[
      =[ [n] [0] ]  [true]
      odd?[-[ [n] [1] ]]
    ]
  ]
  [odd?]  fn[  [n]
    ?[
      =[ [n] [0] ]  [false]
      even?[-[ [n] [1] ]]
    ]
  ]
]
even?[10001]

Here is some code written in another Jevko-based language. Lots of brackets you say? Oh, well. But we got identifiers with spaces!

Now once you get the semantics to your liking, you can replace the syntax with something like:

let even? := fn n =>
    if n = 0 then true
    else odd?[n - 1]

let odd? := fn n =>
    if n = 0 then false
    else even?[n - 1]
    
even?[10001]

So yeah. Jevko is pretty fun. I hope you have fun using it.

Cheerio!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment