Skip to content

RCmerci/2bash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2Bash

A simple language compiles to bash.

Build

Linux

  • git clone
  • make
  • binary location: bundle/default/bin/sbash.exe

macos

  • git clone
  • make mac
  • binary location: _build/default/bin/sbash.exe

Syntax

// basic type
a=1;		// num 
b="111";	// string 
c=[1,2,3];	// num list
d=true;		// bool
// basic operation
a=1+2*3-4/5;
b="deee"++"233";
c=[1,2,3]@@[4,5,6];
d=1==2;
e=2>3;
// if
a=1;
b=2;
if (a<b) {
    c=2;
} else {
    c=3;
}
// for
a=0;
for (i in [1,2,3]) {
   a=a+i;
}
// while
a=0;
while (a < 5) {
   a=a+1;
}
// define function 
fun foo(a, b , c): string-> num -> bool -> string
{
    return sprintf("%s,%d,%d", a, b , c);
}

Builtin Functions

println

  • string|num|bool -> num

    print arg to stdout with newline.

printf

  • string->…->num

sprintf

  • string->…->string

    return formated string

call

  • string -> string

    call external shell command, return its stdout output as string.

    e.g. call(“ls -l”);

exists

  • string -> bool

    test if the file(arg) exists or not.

list

  • string|num|bool -> string list

    convert string|num|bool to string list

num

  • string|bool|num -> num

    convert string|bool|num to num

emacs support

see also 2bash-mode

Todo

  • editor support
    • emacs
    • vim
  • add `break`, `continue`
  • add postion info to compile error

About

simple language compiles to bash

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published