# __Nasal Scripting Language__ ```C++ __ _ /\ \ \__ _ ___ __ _| | / \/ / _` / __|/ _` | | / /\ / (_| \__ \ (_| | | \_\ \/ \__,_|___/\__,_|_| ``` ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ValKmjolnir/Nasal-Interpreter?style=flat-square&logo=github) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ValKmjolnir/Nasal-Interpreter?style=flat-square&logo=github) ![in dev](https://img.shields.io/badge/dev-v10.0-blue?style=flat-square&logo=github) [![license](https://img.shields.io/badge/license-MIT-green?style=flat-square&logo=github)](./LICENSE) > This document is also available in: [__中文__](./doc/README_zh.md) | [__English__](./README.md) ## __Contents__ * [__Introduction__](#introduction) * [__Compile__](#how-to-compile) * [__Usage__](#how-to-use) * [__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) * [__Release Notes__](#release-notes) * [v8.0](#version-80-release) * [__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-last-update-2022212) * [v9.0](#version-90-vm-last-update-2022518) * [v10.0](#version-100-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) * [v9.0 (R9-5900HX ubuntu-WSL)](#version-90-r9-5900hx-ubuntu-wsl-2022213) * [__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 this 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 deleted after v4.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__ ![windows](https://img.shields.io/badge/Microsoft-Windows-green?style=flat-square&logo=windows) ![macOS](https://img.shields.io/badge/Apple%20Inc.-MacOS-green?style=flat-square&logo=apple) ![linux](https://img.shields.io/badge/GNU-Linux-green?style=flat-square&logo=GNU) Better choose the latest update of the interpreter. Download the source and build it! It's quite easy to build this interpreter. __CAUTION__: If want to use the release zip/tar.gz file to build the interpreter, please read the [__Release Notes__](#release-notes) below to make sure this release file has no fatal bugs. There are some tips to fix the release manually. [![please use MinGW](https://www.mingw-w64.org/header.svg)](https://www.mingw-w64.org/ "PLEASE USE MINGW ON WINDOWS!") __PLEASE USE MINGW ON WINDOWS!__ ![g++](https://img.shields.io/badge/GNU-g++-A42E2B?style=flat-square&logo=GNU) ![clang++](https://img.shields.io/badge/LLVM-clang++-262D3A?style=flat-square&logo=LLVM) Use g++ on __`Windows`__(`MinGW-w64`) platform. Download MinGW-w64 [__HERE__](https://www.mingw-w64.org/downloads/). (otherwise don't blame me for not reminding YOU 👿 ) > g++ -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -static Or use g++/clang++ on __`linux/macOS/Unix`__ platform. > [cpp compiler] -std=c++11 -O3 main.cpp -o nasal -fno-exceptions -ldl Or using makefile,`mingw32-make` is __`Windows(MinGW-w64)`__ platform's `make`: > mingw32-make nasal.exe > > mingw32-make.exe nasal.exe on __`linux/macOS/Unix`__: > make nasal ## __How to Use__ First we should learn how to write and run a program using this language, click to see the [__tutorial__](#tutorial). Input this command to run scripts __directly__: > ./nasal filename Use these commands to get version of interpreter: > ./nasal -v | --version ```bash __ _ /\ \ \__ _ ___ __ _| | / \/ / _` / __|/ _` | | / /\ / (_| \__ \ (_| | | \_\ \/ \__,_|___/\__,_|_| nasal ver : 10.0 c++ std : 201103 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 ,--#-, <3 / \____\ <3 |_|__A_| nasal