Skip to content

git-guuud/bracket-eso-lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bracket - an esoteric programming language

Try it out

Comments

  • Comments are written as / followed by the comment text and ending with /
  • /This is a comment/ will be ignored by the interpreter.

Numbers

  • Represented as nested brackets
  • 0 -> [] (equivalent to group of no statements)
  • 1 -> [()]
  • 2 -> [()()]
  • 3 -> [()()()]
  • ...

Operators

  • & (equivalent to +1)
  • * (equivalent to -1)

Variables/Functions

  • {x}()[y] - set value of variable x to y
  • {x}[] - get value of variable x
  • {x}(y)[z] - define function x with arguments y to return value z
  • {x}[y] - call function x with arguments y
  • statements can be grouped using [] (value of a group is the value of the last statement in it)
  • value of definition of variable is the value it is being set to.
  • value of definition of function is 0.

Conditionals

  • [x] | [y] | [z] - if x != 0 then y else z

Variable/Function Names

  • Valid bracket nestings only, e.g. (), (()), (()()), (()(())), etc.

Try-Catch

  • <try_block|catch_block> - if error is encountered while executing try_block, execute continues from catch_block instead.

Print

  • <x> - print x as a number
  • <x|> - print x as a character
  • Value of the statement is the value of x

Examples

addition (5+6)

/Define a function named (()()) to add two numbers let's say add(x,y)/

{(()())}( () (()) ) [ 
    [ {(())}[] ] |                          /if y is not 0/
        [ {(()())} [ &{()}[] *{(())}[] ] ]  /then return value of add(x+1, y-1)/
    |
        [ {()}[] ]                          /else if y is 0 return x/
]

/Calling the function on 5 and 6/
{(()())}[ [()()()()()] [()()()()()()] ]

multiplication (6*8)

/addition function/
{(()())}( () (()) ) [
    [ {(())}[] ] | 
        [ {(()())} [ &{()}[] *{(())}[] ] ]
    |
        [ {()}[] ]
]

/Helper function say mul_help(x,y,acc)/

{(()()()())} ( () (()) ((())) ) [
    [ {(())}[] ] |              /if y is not 0/                                           
        [ {(()()()())} [        /call mul_help(x, y-1, acc+x)/ 
            {()}[]              /x/
            *{(())}[]           /y-1/
            {(()())} [          /add(acc, x)/
                {((()))}[] 
                {()}[] 
                ] 
            ] 
        ]
    |                           /if y is 0/
        [ {((()))}[] ]          /return acc/
]

/Multiplication function say mul(x,y)/
{(()()())} ( () (()) ) [
    {(()()()())} [ {()}[] {(())}[] [] ] /mul_help(x, y, 0)/
]

{(()()())} [ [()()()()()()] [()()()()()()()()]] /mul(6,8)/

How to compile it yourself

  • Clone the repository
  • Run cargo build --release --target web in the root directory
  • Run npm install ../pkg in the site directory
  • Run npm serve in the site directory
  • And Done! That's it, you can now run the interpreter in your browser at http://localhost:8080/ or http://localhost:3000/ whichever is given by the npm serve command.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors