<commit_before># SelectScriptC

SelectScript Compiler and REPL implemented in Clojure for the SandhillSkipperVM.

SelectScript is a dynamically typed programming language with imperative,
procedural, functional, (object-oriented), declarative and relational aspects.

## Editor Integration

There is syntax highlighting support for several editors available:

| Atom  | [github.com/ESS-OVGU/language-selectscript](https://github.com/ESS-OVGU/language-selectscript) |
|-------|------------------------------------------------------------------------------------------------|
| Emacs | [github.com/fin-ger/select-script-mode](https://github.com/fin-ger/select-script-mode)         |

## Setup

### Requirements

This system was only tested on Linux and Arduino...

* git ;)
* gcc
* Java and Clojure (see: https://leiningen.org)

### Download

The following command will download the entire project:

``` bash
git clone --recursive  https://github.com/ESS-OVGU/SelectScriptC.git
```

### Build

Build the entire system, including VM with its dynamic type-system and the
language compiler. While the first two elements have been developen in plain C,
the compiler was implemented in Clojure.

``` bash
cd SelectScriptC
make
```

Run the following command to install the `S2c` to `/usr/local/bin`.

``` bash
make install
# make uninstall # for uninstalling
```

> Alternatively you can also enter `SandhillSkipper` and run make in there and
> compile the Clojure sources with `lein uberjar` or `lein run`.

### Test

All test-cases are defined in folder `test`, to run all test use the following
command:

``` bash
lein test
```

To only test a certain file use:

``` bash
lein test towers # will run all test in towers.clj
```

or to run only one specific test:

``` bash
lein test :only towers/simple
```

## Usage

### Basics

Some basic examples can be found in the corresponding folder:
``` bash
cd examples
```

To execute a SelectScript program use
``` bash
S2c -x ackerman.S2
```

Or use the interactive shell by run in `S2c` only, but there are also more
options, use `-h` or `-help` to see all:
``` bash
S2c --help
 __      _           _   __           _       _
/ _\ ___| | ___  ___| |_/ _\ ___ _ __(_)_ __ | |_
\ \ / _ \ |/ _ \/ __| __\ \ / __| '__| | '_ \| __|
_\ \  __/ |  __/ (__| |__\ \ (__| |  | | |_) | |_
\__/\___|_|\___|\___|\__\__/\___|_|  |_| .__/ \__|
                                       |_|

  -o, --output FILE    Export result to file
      --no-optimize    Do not optimize
  -d, --debug          execute stepwise
  -a, --assembly       print assembly
  -i, --interim        print interim
  -b, --bytecode       print bytecode
  -p, --parse-tree     print parsetree
  -x, --execute        Run the program
  -r, --repl           interactive
  -s, --server         run compiler as web-server
      --port           server port
  -h, --help
```

### Compilation

If only bytecode should be generated, that should be executed on another VM,
then use `-a` or `-b` and pipe the result into a target file:

``` bash
S2c -b ackerman.S2 > ackerman.h
cat ackerman.h
12, 8, 2, 0, 5, 65, 99, 107, 0, 3, 110, 0, 3, 109, 0, 6, 65, 99, 107, 40, 0, 3,
44, 0, 5, 41, 32, 61, 0, 7, 112, 114, 105, 110, 116, 0, 0, 9, 0, 90, 0, 12, 3,
3, 109, 0, 3, 110, 0, 5, 65, 99, 107, 0, 2, 0, -106, 0, 0, -106, 1, 52, 16, 0,
64, 0, 25, 11, 0, 16, 1, 3, 1, 66, 1, 26, 54, 0, 16, 1, 64, 0, 25, 21, 0, 16, 0,
3, 1, 67, 1, 3, 1, 7, 2, 0, 38, 0, 26, -44, -1, 26, 28, 0, 16, 0, 3, 1, 67, 1,
16, 0, 16, 1, 3, 1, 67, 1, 18, 2, 24, 2, 7, 2, 0, 38, 0, 26, -73, -1, 15, -108,
1, 13, 0, 3, 0, 3, 1, 3, 2, 3, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 7, 10, 0,
3, 0, 3, 1, 3, 2, 3, 3, 7, 4, 0, 11, 2, 0, 2, 3, 27, 0, 28, 25, 30, 0, 48, 10,
4, 16, 3, 10, 5, 16, 2, 10, 6, 16, 3, 16, 2, 18, 1, 24, 2, 18, 7, 24, 7, 36, 0,
26, -30, -1, 14, 14,
```

In contrast to this, the `-a` option will generate pretty-printed and readble
assembly-code, that can directly be applied in C. All mnemonics are C-defines
and correspond to a numerical value, as depicted in the listing above.

``` bash
S2c -a ackerman.S2 > ackerman.h
cat ackerman.h

/*0000*/ SP_SAVEX,    8, // 8
                      2, 0, //  ""
                      5, 'A', 'c', 'k', 0, //  "Ack"
                      3, 'n', 0, //  "n"
                      3, 'm', 0, //  "m"
                      6, 'A', 'c', 'k', '(', 0, //  "Ack("
                      3, ',', 0, //  ","
                      5, ')', ' ', '=', 0, //  ") ="
                      7, 'p', 'r', 'i', 'n', 't', 0, //  "print"
                      0, // local variables
/*0037*/ ENC_PROC,    0, // help: ""
                      90, 0, // length: 90
//////////////////////////////////////////////////////////
/*0040*/               SP_SAVEX,    3, // 3
                                    3, 'm', 0, //  "m"
                                    3, 'n', 0, //  "n"
                                    5, 'A', 'c', 'k', 0, //  "Ack"
                                    2, // local variables
/*0054*/               ENC_NONE,
/*0055*/               STORE_LOC|P, 0, // "m"
/*0057*/               ENC_NONE,
/*0058*/               STORE_LOC|P, 1, // "n"
/*0060*/               PROC_LOAD,
/*0061*/               LOC,         0, // "m"
...<commit_msg>added a grammar/tutorial for selectscript<commit_after># SelectScriptC

SelectScript Compiler and REPL implemented in Clojure for the SandhillSkipperVM.

SelectScript is a dynamically typed programming language with imperative,
procedural, functional, (object-oriented), declarative and relational aspects.

## Editor Integration

There is syntax highlighting support for several editors available:

| Atom  | [github.com/ESS-OVGU/language-selectscript](https://github.com/ESS-OVGU/language-selectscript) |
|-------|------------------------------------------------------------------------------------------------|
| Emacs | [github.com/fin-ger/select-script-mode](https://github.com/fin-ger/select-script-mode)         |

## Setup

### Requirements

This system was only tested on Linux and Arduino...

* git ;)
* gcc
* Java and Clojure (see: https://leiningen.org)

### Download

The following command will download the entire project:

``` bash
git clone --recursive  https://github.com/ESS-OVGU/SelectScriptC.git
```

### Build

Build the entire system, including VM with its dynamic type-system and the
language compiler. While the first two elements have been developen in plain C,
the compiler was implemented in Clojure.

``` bash
cd SelectScriptC
make
```

Run the following command to install the `S2c` to `/usr/local/bin`.

``` bash
make install
# make uninstall # for uninstalling
```

> Alternatively you can also enter `SandhillSkipper` and run make in there and
> compile the Clojure sources with `lein uberjar` or `lein run`.

### Test

All test-cases are defined in folder `test`, to run all test use the following
command:

``` bash
lein test
```

To only test a certain file use:

``` bash
lein test towers # will run all test in towers.clj
```

or to run only one specific test:

``` bash
lein test :only towers/simple
```

## Usage

### Basics

Some basic examples can be found in the corresponding folder:
``` bash
cd examples
```

To execute a SelectScript program use
``` bash
S2c -x ackerman.S2
```

Or use the interactive shell by run in `S2c` only, but there are also more
options, use `-h` or `-help` to see all:
``` bash
S2c --help
 __      _           _   __           _       _
/ _\ ___| | ___  ___| |_/ _\ ___ _ __(_)_ __ | |_
\ \ / _ \ |/ _ \/ __| __\ \ / __| '__| | '_ \| __|
_\ \  __/ |  __/ (__| |__\ \ (__| |  | | |_) | |_
\__/\___|_|\___|\___|\__\__/\___|_|  |_| .__/ \__|
                                       |_|

  -o, --output FILE    Export result to file
      --no-optimize    Do not optimize
  -d, --debug          execute stepwise
  -a, --assembly       print assembly
  -i, --interim        print interim
  -b, --bytecode       print bytecode
  -p, --parse-tree     print parsetree
  -x, --execute        Run the program
  -r, --repl           interactive
  -s, --server         run compiler as web-server
      --port           server port
  -h, --help
```

### Compilation

If only bytecode should be generated, that should be executed on another VM,
then use `-a` or `-b` and pipe the result into a target file:

``` bash
S2c -b ackerman.S2 > ackerman.h
cat ackerman.h
12, 8, 2, 0, 5, 65, 99, 107, 0, 3, 110, 0, 3, 109, 0, 6, 65, 99, 107, 40, 0, 3,
44, 0, 5, 41, 32, 61, 0, 7, 112, 114, 105, 110, 116, 0, 0, 9, 0, 90, 0, 12, 3,
3, 109, 0, 3, 110, 0, 5, 65, 99, 107, 0, 2, 0, -106, 0, 0, -106, 1, 52, 16, 0,
64, 0, 25, 11, 0, 16, 1, 3, 1, 66, 1, 26, 54, 0, 16, 1, 64, 0, 25, 21, 0, 16, 0,
3, 1, 67, 1, 3, 1, 7, 2, 0, 38, 0, 26, -44, -1, 26, 28, 0, 16, 0, 3, 1, 67, 1,
16, 0, 16, 1, 3, 1, 67, 1, 18, 2, 24, 2, 7, 2, 0, 38, 0, 26, -73, -1, 15, -108,
1, 13, 0, 3, 0, 3, 1, 3, 2, 3, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 7, 10, 0,
3, 0, 3, 1, 3, 2, 3, 3, 7, 4, 0, 11, 2, 0, 2, 3, 27, 0, 28, 25, 30, 0, 48, 10,
4, 16, 3, 10, 5, 16, 2, 10, 6, 16, 3, 16, 2, 18, 1, 24, 2, 18, 7, 24, 7, 36, 0,
26, -30, -1, 14, 14,
```

In contrast to this, the `-a` option will generate pretty-printed and readble
assembly-code, that can directly be applied in C. All mnemonics are C-defines
and correspond to a numerical value, as depicted in the listing above.

``` bash
S2c -a ackerman.S2 > ackerman.h
cat ackerman.h

/*0000*/ SP_SAVEX,    8, // 8
                      2, 0, //  ""
                      5, 'A', 'c', 'k', 0, //  "Ack"
                      3, 'n', 0, //  "n"
                      3, 'm', 0, //  "m"
                      6, 'A', 'c', 'k', '(', 0, //  "Ack("
                      3, ',', 0, //  ","
                      5, ')', ' ', '=', 0, //  ") ="
                      7, 'p', 'r', 'i', 'n', 't', 0, //  "print"
                      0, // local variables
/*0037*/ ENC_PROC,    0, // help: ""
                      90, 0, // length: 90
//////////////////////////////////////////////////////////
/*0040*/               SP_SAVEX,    3, // 3
                                    3, 'm', 0, //  "m"
                                    3, 'n', 0, //  "n"
                                    5, 'A', 'c', 'k', 0, //  "Ack"
                                    2, // local variables
/*0054*/               ENC_NONE,
/*0055*/               STORE_LOC|P, 0, // "m"
/*0057*/               ENC_NONE,
/*0058*/               STORE_LOC|P, 1, // "n"
/*0060*/               PROC_LOAD,
/*0061*/               LOC,         0, // "m"
. . .
{'fraction_non_alphanumeric': 0.1875, 'fraction_numerical': 0.07439117199391172, 'mean_word_length': 1.7463427377220482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3416521', 'n_tokens_mistral': 4463, 'n_tokens_neox': 3612, 'n_words': 1352}