2019-09-02 12:11:31 +08:00
|
|
|
# Nasal Interpreter
|
2019-08-28 23:03:31 +08:00
|
|
|
|
2020-03-09 15:58:34 +08:00
|
|
|
[![nasal_new_logo](pic/nasal.png?raw=true)](http://wiki.flightgear.org/File:Nasallogo3.png)
|
2020-01-29 21:34:52 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
# Nasal script language
|
2019-07-25 02:14:33 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
[Nasal](http://wiki.flightgear.org/Nasal_scripting_language) is a script language that used in [FlightGear](https://www.flightgear.org/).
|
2019-07-25 02:14:33 +08:00
|
|
|
|
|
|
|
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++.
|
2019-07-25 02:17:35 +08:00
|
|
|
|
|
|
|
The interpreter is still in development.Anyone who interested in this could also join us!
|
2019-07-28 00:06:29 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
# Lexical Analysis
|
2019-07-28 00:06:29 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
What do it's outputs look like?
|
2019-07-29 21:50:18 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
> ( identifier | start )
|
2019-07-29 21:50:18 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
> ( operator | ; )
|
2019-07-29 21:50:18 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
> ( reserve word | print )
|
2019-07-29 21:50:18 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
> ( operator | ( )
|
2019-07-29 21:50:18 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
> ( string | Engine started )
|
2019-07-29 21:50:18 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
> ( operator | ) )
|
2019-07-29 21:50:18 +08:00
|
|
|
|
|
|
|
This is what it outputs.
|
2019-08-07 02:48:03 +08:00
|
|
|
|
2019-12-24 16:52:11 +08:00
|
|
|
And the flow chart of lexer is here:
|
|
|
|
|
2020-01-29 20:19:36 +08:00
|
|
|
[![nasal_lexer.png](pic/nasal_lexer.png?raw=true)](https://github.com/ValKmjolnir/Nasal-Interpreter/blob/master/pic/nasal_lexer.png)
|
2019-12-24 16:52:11 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
# Parser
|
2019-09-25 20:49:06 +08:00
|
|
|
|
2020-09-13 16:40:23 +08:00
|
|
|
## In __version 2.0__
|
2020-01-22 19:07:33 +08:00
|
|
|
```javascript
|
|
|
|
(var a,b,c)=(1,2,3);
|
|
|
|
var (r,g,b)=color;
|
|
|
|
```
|
|
|
|
These two types of statements are both definition_expr.
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
(a,b,c)=(1,2,3);
|
|
|
|
(a,b)=(b,a);
|
|
|
|
```
|
|
|
|
This type of statement is multi_assignment.
|
|
|
|
|
2020-09-13 16:40:23 +08:00
|
|
|
And to check if an expr in '(' ')' is multi_scalar or multi_id.
|
2020-01-22 19:07:33 +08:00
|
|
|
|
2020-09-13 16:40:23 +08:00
|
|
|
i used bool nasal_parse::check_multi_scalar() and bool nasal_parse::check_multi_assignment().
|
|
|
|
|
|
|
|
## In __version 3.0__
|
|
|
|
|
|
|
|
I refactored parser and make it easier to maintain.
|
|
|
|
|
|
|
|
the EBNF is also refactored.
|
2020-01-13 14:13:35 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
# Abstract Syntax Tree
|
2019-10-13 11:01:31 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
In __version 1.2__ the ast has been completed.
|
2020-06-01 01:28:49 +08:00
|
|
|
|
2020-09-13 16:40:23 +08:00
|
|
|
In __version 3.0__ the ast is refactored and is now easier to read and maintain.
|
|
|
|
|
2020-06-01 01:28:49 +08:00
|
|
|
# Version 2.0
|
|
|
|
|
|
|
|
a completed ast-interpreter with unfinished lib functions.
|
|
|
|
|
2020-09-13 16:40:23 +08:00
|
|
|
# Version 3.0
|
|
|
|
|
|
|
|
ast-interpreter uses new techniques so it can run codes more efficiently.
|
|
|
|
|
|
|
|
byte-code-interpreter is in progress(i need a lot of time to learn that :( ).
|