Go to file
Valk Richard Li 9f30440286 preparation for v5.0 2020-12-19 01:26:15 +08:00
pic change project structure 2020-10-23 14:53:04 +08:00
test preparation for v5.0 2020-12-19 01:26:15 +08:00
.gitignore Initial commit 2019-07-25 02:11:59 +08:00
README.md preparation for v5.0 2020-12-19 01:26:15 +08:00
lib.nas update math.pi :) 2020-11-09 00:33:15 +08:00
main.cpp preparation for v5.0 2020-12-19 01:26:15 +08:00
nasal.ebnf update 2020-10-24 12:16:55 +08:00
nasal.h preparation for v5.0 2020-12-19 01:26:15 +08:00
nasal_ast.h update 2020-12-14 23:43:00 +08:00
nasal_builtin.h preparation for v5.0 2020-12-19 01:26:15 +08:00
nasal_bytecode_vm.h preparation for v5.0 2020-12-19 01:26:15 +08:00
nasal_codegen.h update 2020-12-15 21:13:22 +08:00
nasal_gc.h preparation for v5.0 2020-12-19 01:26:15 +08:00
nasal_import.h update 2020-11-20 19:15:12 +08:00
nasal_lexer.h update 2020-12-14 00:10:31 +08:00
nasal_parse.h update 2020-12-15 13:00:24 +08:00

README.md

Nasal Interpreter

nasal_new_logo

Nasal script language

Nasal is a script language that used in FlightGear.

There is a Nasal console in FlightGear but sometimes it is not so easy for every developer to use.

So this is an interpreter for Nasal written by C++.

The interpreter is still in development.We really need your support!

Why Writing Nasal Interpreter

Nasal is a script language first used in Flightgear.

But in last summer holiday, members in FGPRC told me that it is hard to debug with nasal-console in Flightgear, especially when checking syntax error.

So i tried to write a new interpreter to help them checking syntax error and even, runtime error.

I wrote the lexer, parser and runtime(nasal virtual machine/ast-runtime virtual machine) to help checking errors.

They found it easier for them to check errors before copying nasal-codes in nasal-console in Flightgear to test.

How to Compile

g++ -std=c++11 main.cpp -o main.exe

Lexical Analysis

The flow chart of lexer is here:

nasal_lexer.png

This picture seems ugly. I will re-draw it later(maybe 1000 years later).

Parser

Version 3.0

I refactored parser and make it easier to maintain.

The EBNF is also refactored.

Version 4.0

Parser in this version will pre-calculate some mathematical equations.

This will make bytecode vm running more quickly.

Abstract Syntax Tree

Version 1.2

The ast has been completed in this version.

Version 2.0

A completed ast-interpreter with unfinished lib functions.

Version 3.0

The ast is refactored and is now easier to read and maintain.

Ast-interpreter uses new techniques so it can run codes more efficiently.

Now you can add your own functions as builtin-functions in this interpreter!

I decide to save the ast interpreter after releasing v4.0. Because it took me a long time to think and write...

Version 5.0

I change my mind.AST interpreter leaves me too much things to do.

If i continue saving this interpreter,it will be harder for me to make the bytecode vm become more efficient.

Byte Code Interpreter

Version 4.0

I have just finished the first version of byte-code-interpreter.

This interpreter is still in test.After this test,i will release version 4.0!

Now i am trying to search hidden bugs in this interpreter.Hope you could help me! :)

There's an example of byte code below:

var (a,b,c)=(1,2,3);
.number 1
.number 2
.number 3
.symbol a
.symbol b
.symbol c
0x00000000: pone   0x00000000
0x00000001: load   0x00000000  (a)
0x00000002: pnum   0x00000001  (2)
0x00000003: load   0x00000001  (b)
0x00000004: pnum   0x00000002  (3)
0x00000005: load   0x00000002  (c)
0x00000006: nop    0x00000000

Version 5.0

I decide to optimize bytecode vm in this version.

Because it takes more than 1.5s to count i from 0 to 4000000-1.This is not efficient at all!