Are there any languages that compile to Bash?

后端 未结 8 1375
夕颜
夕颜 2021-01-30 02:13

I both love and hate writing Bash. I love that it\'s so streamlined for operating on files and working with processes (I agree with this popular question that it\'s way

8条回答
  •  被撕碎了的回忆
    2021-01-30 03:05

    I recently developed a language called BashClass which is Object Oriented, has type checking and allow multi-dimensional arrays. The language syntax is inspired by different programming languages.

    Here's an example on how a List class is implemented (Full example here):

    class List extends Object {
        var Object[] data = new Object[];
        var int size = 0;
        constructor List(){
            super_constructor();
        }
    
        function void add(var Object object) {
            data[size] = object;
            size = size + 1;
        }
    
        function void pop() {
            if(size == 0) {
                exception("Cannot remove element from an empty list");
            }
            size = size - 1;
            data[size] = null;
        }
    
        function int size() {
            return size;
        }
    
        function Object get(var int index) {
            if(index < 0 || index >= size) {
                exception("Cannot access element out of bound");
            }
            return data[index];
        }
    }
    

    Classes and multi-dimensional arrays in BashClass are converted to Bash 4.4 associative arrays. The language is at its first release and is open source on Github. Feel free to contirbute and suggest features.

提交回复
热议问题