|
| 1 | +## Using the Interpreter |
| 2 | + |
| 3 | +For details on the language itself, read the [manual](http://hjemmesider.diku.dk/~torbenm/Troll/manual.pdf). |
| 4 | + |
| 5 | +All functionality described in the manual is implemented (*not necessarily correctly* :) with the following exceptions: |
| 6 | + |
| 7 | +- Compositional functions |
| 8 | +- Probability calculations |
| 9 | + |
| 10 | +As these are functions I do not currently need, their implementation is low priority. Let me know if they are important to you and I may re-consider. Of course, pull requests with implementations are appreciated! |
| 11 | + |
| 12 | +### Running a Script |
| 13 | + |
| 14 | +If you run troll with a filename on the command line, it will execute that script |
| 15 | + |
| 16 | +``` |
| 17 | +troll afile.t |
| 18 | +``` |
| 19 | + |
| 20 | +You can optionally define variables on the command line as well |
| 21 | + |
| 22 | +``` |
| 23 | +troll afile.t N=5 S=20 |
| 24 | +``` |
| 25 | + |
| 26 | +Given this command line, the definitions can make use of the values specified for `N` and `S`. Variable definitions must be of the form `<identifier>=<integer>` where `<identifier>` follows the Troll requirements for variable names. There cannot be spaces between the equals sign and the identifier and integer value. Definitions for variables that are not used in the Troll script are ignored. |
| 27 | + |
| 28 | +Troll files conventionally have names ending in `.t`, but that is not required. |
| 29 | + |
| 30 | +### Interactive Usage |
| 31 | + |
| 32 | +If you run troll without a filename |
| 33 | + |
| 34 | +``` |
| 35 | +$ troll |
| 36 | +``` |
| 37 | + |
| 38 | +it will start up an interactive shell (aka a REPL). You can enter a line of Troll code at the prompt and the interpreter will print the resulting value. In addition, several commands are supported (enter commands on a line by themselves): |
| 39 | + |
| 40 | +- `+set` — define a variable to be used in subsequent Troll code. The format is `+set <varname> <integer>` |
| 41 | +- `-set` — remove a variable definition. The format is `-set <varname` |
| 42 | +- `+multiline` — allows you to enter multiple lines of Troll code |
| 43 | + |
| 44 | + This is particularly useful for entering function definitions since currently you cannot enter them without also entering a 'main' Troll script. |
| 45 | + |
| 46 | + To stop entering Toll code and have the interpreter run the script, enter `+done` on its own line. |
| 47 | +- `+quit` — quit the REPL (*Ctl-D and Ctl-C also work*) |
| 48 | +- `+version` — print the interpreter version |
| 49 | +- `+help` — print a help message |
| 50 | + |
| 51 | +NOTE: Variable definitions remain in existance until either you remove them (*via `-set`*) or you quit the REPL; although you can *shadow* variables by re-defining them. Functions continue to be defined as well (*currently there is no mechanism to un-define a function, other than quitting the REPL*). |
| 52 | + |
| 53 | +The following commands are (*probably*) only of interest to people working on the Troll implementation: |
| 54 | + |
| 55 | +- `+parser` — print the AST |
| 56 | +- `-parser` — stop printing the AST |
| 57 | +- `+scanner` — print the token stream |
| 58 | +- `-scanner` — stop printing the token stream |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +## Installing Troll |
| 65 | + |
| 66 | +Troll should build on any platform that has Swift, i.e. macOS, Linux (Ubuntu, CentOS, Amazon Linux 2), and Windows 10. Currently it has only been tested on macOS. |
| 67 | + |
| 68 | +### Get a pre-compiled version |
| 69 | + |
| 70 | +Download the [latest release](https://github.com/profburke/troll/releases), and copy the executable to somewhere on your PATH; `/usr/local/bin` is recommended. |
| 71 | + |
| 72 | +### Build from scratch |
| 73 | + |
| 74 | +Building should be fairly straight-forward: |
| 75 | + |
| 76 | +``` |
| 77 | +git clone https://github.com/profburke/troll |
| 78 | +cd troll |
| 79 | +swift build -c release |
| 80 | +``` |
| 81 | + |
| 82 | +Copy the executable file (`.build/release/troll`) to somewhere on your PATH; `/usr/local/bin` is a good choice. |
| 83 | + |
| 84 | +If there are errors while building, please create an [issue](https://github.com/profburke/troll/issues/new). |
0 commit comments