# __Nasal Script Language__ ```C++ __ _ /\ \ \__ _ ___ __ _| | / \/ / _` / __|/ _` | | / /\ / (_| \__ \ (_| | | \_\ \/ \__,_|___/\__,_|_| ``` ## __Contents__ * [__Introduction__](#introduction) * [__Why Writing Nasal Interpreter__](#why-writing-nasal-interpreter) * [__Compile__](#how-to-compile) * [__Usage__](#how-to-use) * [__Parser__](#parser) * [v1.0](#version-10-parser-last-update-20191014) * [__Abstract Syntax Tree__](#abstract-syntax-tree) * [v1.2](#version-12-ast-last-update-20191031) * [v2.0](#version-20-ast-last-update-2020831) * [v3.0](#version-30-ast-last-update-20201023) * [v5.0](#version-50-ast-last-update-202137) * [__Bytecode VM__](#bytecode-virtual-machine) * [v4.0](#version-40-vm-last-update-20201217) * [v5.0](#version-50-vm-last-update-202137) * [v6.0](#version-60-vm-last-update-202161) * [v6.5](#version-65-vm-last-update-2021624) * [v7.0](#version-70-vm-last-update-2021108) * [v8.0](#version-80-vm-latest) * [__Benchmark__](#benchmark) * [v6.5 (i5-8250U windows 10)](#version-65-i5-8250u-windows10-2021619) * [v6.5 (i5-8250U ubuntu-WSL)](#version-70-i5-8250u-ubuntu-wsl-on-windows10-2021629) * [v8.0 (R9-5900HX ubuntu-WSL)](#version-80-r9-5900hx-ubuntu-wsl-2022123) * [__Tutorial__](#tutorial) * [basic value type](#basic-value-type) * [operators](#operators) * [definition](#definition) * [multi-assignment](#multi-assignment) * [conditional expression](#conditional-expression) * [loop](#loop) * [subvec](#subvec) * [special function call](#special-function-call) * [lambda](#lambda) * [closure](#closure) * [trait](#trait) * [native functions](#native-functions) * [modules](#modulesfor-library-developers) * [__Difference__](#difference-between-andys-and-this-interpreter) * [strict definition](#1-must-use-var-to-define-variables) * [(outdated)use after definition](#2-now-supported-couldnt-use-variables-before-definitions) * [default dynamic arguments](#3-default-dynamic-arguments-not-supported) * [__Trace Back Info__](#trace-back-info) * [native function 'die'](#1-native-function-die) * [stack overflow](#2-stack-overflow-crash-info) * [runtime error](#3-normal-vm-error-crash-info) * [detailed crash info](#4-detailed-crash-info) * [__Debugger__](#debugger) __Contact us if having great ideas to share!__ * __E-mail__: lhk101lhk101@qq.com * __QQ__: 896693328 ## __Introduction__ __[Nasal](http://wiki.flightgear.org/Nasal_scripting_language)__ is an ECMAscript-like programming language that used in __[FlightGear](https://www.flightgear.org/)__. This language is designed by __[Andy Ross](https://github.com/andyross)__. The interpreter is totally rewritten by __[ValKmjolnir](https://github.com/ValKmjolnir)__ using `C++`(`-std=c++11`) without reusing the code in __[Andy Ross's nasal interpreter]()__. But we really appreciate that Andy created this amazing programming language and his interpreter project. Now this project uses __MIT license__ (2021/5/4). Edit it if you want, use this project to learn or create more interesting things (But don't forget me XD). ## __Why Writing Nasal Interpreter__ In 2019 summer holiday, members in __[FGPRC](https://www.fgprc.org/)__ told me that it is hard to debug with nasal-console in Flightgear, especially when checking syntax errors. So i tried to write a new interpreter to help them checking syntax error and even, runtime error. I wrote the lexer, parser and bytecode virtual machine(there was an ast-interpreter, but i deleted it after version4.0) to help checking errors. We found it much easier to check syntax and runtime errors before copying nasal-codes in nasal-console in Flightgear to test. Also, you could use this language to write some interesting programs and run them without the lib of Flightgear. You could add your own modules to make this interpreter a useful tool in your own projects (such as a script in a game just as Flightgear does). ## __How to Compile__ Better choose the latest update of the interpreter. Download the source code and build it! It's quite easy to build this interpreter. __MUST USE__ __`-O2/-O3`__ if want to optimize the interpreter! Also remember to use g++ or clang++.(mingw-w64 in __`Windows`__) > [cpp compiler] -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions Or use this in __`linux/macOS/Unix`__ > [cpp compiler] -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl ## __How to Use__ Input this command to run scripts __directly__: > ./nasal filename Use these commands to get version of interpreter: > ./nasal -v | --version ```bash __ _ /\ \ \__ _ ___ __ _| | / \/ / _` / __|/ _` | | / /\ / (_| \__ \ (_| | | \_\ \/ \__,_|___/\__,_|_| nasal interpreter ver 8.0 thanks to : https://github.com/andyross/nasal code repo : https://github.com/ValKmjolnir/Nasal-Interpreter code repo : https://gitee.com/valkmjolnir/Nasal-Interpreter lang info : http://wiki.flightgear.org/Nasal_scripting_language input to get help . ``` Use these commands to get help(see more debug commands in help): > ./nasal -h | --help ```bash nasal