2019-09-02 12:11:31 +08:00
|
|
|
# Nasal Interpreter
|
2019-08-28 23:03:31 +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 | engineTimer )
|
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
|
|
|
> ( 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
|
|
|
|
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:
|
|
|
|
|
|
|
|
![nasal_lexer.png](https://github.com/ValKmjolnir/Nasal-Interpreter/tree/master/pic/nasal_lexer.png)
|
|
|
|
|
2019-08-28 15:37:21 +08:00
|
|
|
# Push down automata
|
|
|
|
|
|
|
|
After many times of failure,i finally try to use PDA to do the parse work.
|
2019-09-25 20:49:06 +08:00
|
|
|
|
2019-12-10 14:02:30 +08:00
|
|
|
But something occurred,so i finally didn't make it.However you can still see this LL(1) and LR(0) parser in __version 0.7 & 0.9__ .
|
2019-09-25 20:49:06 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
# Parser
|
2019-09-25 20:49:06 +08:00
|
|
|
|
|
|
|
The parser can recognize some basic elements in resource program.
|
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
In __version 1.1__ you can use the fully-functional parser.
|
2019-10-22 13:06:13 +08:00
|
|
|
|
|
|
|
But there are still some differences such as:
|
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
```javascript
|
2019-10-22 13:06:13 +08:00
|
|
|
(var a,b,c)=(1,2,3);
|
|
|
|
var (r,g,b)=color;
|
|
|
|
(a,b)=(b,a);
|
2019-12-10 14:00:55 +08:00
|
|
|
```
|
2019-10-22 13:06:13 +08:00
|
|
|
|
|
|
|
etc. cannot be recognized.
|
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
And each statement must have a ';' after it or you will be informed with __'error: expect a ';''__ .
|
2019-10-01 23:16:04 +08:00
|
|
|
|
2020-01-13 14:13:35 +08:00
|
|
|
In __version 2.0__ these problems will be solved.
|
|
|
|
|
2019-10-01 23:16:04 +08:00
|
|
|
# Calculator
|
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
You can try a calculator in __version 0.17~0.19__ !
|
2019-10-13 11:01:31 +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.
|
2019-10-22 20:24:42 +08:00
|
|
|
|
|
|
|
But there are still some bugs inside.
|
2019-11-19 18:20:20 +08:00
|
|
|
|
|
|
|
# Balloon script
|
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
[Balloon](https://github.com/ValKmjolnir/Balloon-script) is created for experiment.
|
2019-11-19 18:20:20 +08:00
|
|
|
|
2019-12-10 14:00:55 +08:00
|
|
|
It is a subset of Nasal and the parser is __stricter__ than Nasal parser.
|
2019-11-19 18:20:20 +08:00
|
|
|
|
|
|
|
Explore the usage of balloon and enjoy yourself! XD
|