jMiniLangKotlin 实现的编译器和虚拟机
jMiniLang 项目是一个 LR 编译器、虚拟机一体化工程,并且对虚拟机进行了拓展,参考了操作系统设计的思想。
Features(特性)
- 词法分析阶段。Lexer which generates NFA and DFA.
- 语法分析、词法分析、制导翻译。Parser which implements LALR(1) Grammar with optional semantic action.
- 语义分析。Customized semantic analysis.
- 可打印语法树。Printable syntax tree.
- 基于栈的自定义指令集。Stack-based instruction design.
- Kotlin本地方法导入。Native method.
- 代码页导入/导出。Import and export of code page.
- 代码页序列化。Serializable code page.
- 匿名函数及闭包。Lambda functions and Closure.
- 语法/词法错误提示。Display grammar and semantic errors.
- 管道机制。Pipe.
- 多进程机制。Multiple process.
- 同步/异步执行代码。Load file with Sync/Async.
- 虚拟机。Virtual machine.
- 支持彩色界面。Support Colorful GUI.
- 函数式编程。Functional programming.
- LISP.
- 网络流。Socket stream.
- 虚拟文件系统。Save/Load file or VFS.
- 基于原型的类设计。Class prototype.
- Bash Interface.
- 数组/词典初始化。Array/Map initialize list.
- 异常机制。Try/Catch/Throw.
- 行为树。Behavior Tree, including PC network simulator.
- 用户级进程。RING 3 Process, including User Service,
fork
. - 网页服务器。Web Server, including Online Compiler and Runner.
- C语言解析。CParser class on
ModuleUser
.
What it generates(产生)
- 正则表达式、状态机。Structures of Regex, NFA and DFA Table.
- 分析表。Structures of LL/LR Table.
- 语义分析指令。Structures of semantic instructions.
- 语法树。Structures of syntax tree.
- 代码页。Structures of code page.
- 虚拟机指令。Virtual machine instructions.
- 运行时环境。Runtime environment.
Virtual Machine OS
An OS running on jMiniLang compiler and interpreter.
Now has commands:(现在主窗口支持的cmd命令)
- echo
- dup
- pipe
- grep
- proc
- range
- task
- sleep
- time
- count
- msg
- news(refer: https://github.com/bajdcc/NewsApp)
- bash
- replace
- util
- ai
- pc
- music
Tasks:(使用方法如:@system halt
)
- System
- Utility
- Remote
- UI
- Store
- Proc
UI:(使用方法如:@ui on clock
)
- Clock
- Hitokoto
- Monitor
Toggle UI:
task ui on/off clock
task ui on/off hitokoto
task ui on/off monitor
Implemented IPC, usage:(微服务)
task system now
-> Get system timetask util calc 1+2*3
-> Val = 7task ui print hello world
-> Remote windowtask ui path M 100 100 L 200 200
-> SVG
Utility:
task util doc g_func_fold
-> Documenttask util reverse ...
task util toupper ...
task util sum ...
task util product ...
task util palindrome ...
Tests:(测试命令,直接在主窗口cmd输入,Ctrl-C中止)
test philo/philo2
: Multi-processing and synchronization-
test lisp
: LISP language test font
: Support Chinese Language(wide font)test fork
: Test forktest class
: Test AOP and Prototype for classtest bash
: Test bash interfacetest try
: Test try/catch-
test badapple
: Test ascii output, code in BadApple test dialog
: Test JOptionPane.showXXXDialogtest linq
: Test LINQtest proc
: Test Ring 3 APItest proc2
: Test Ring 3 code with inputtest web
: HTTP Web Server
Implemented MSG, usage:(远程控制)
- Create server:
msg server PORT | filter pipe
- Create client:
other pipe | msg connect IP:PORT
PC command:
pc add A 10 10 100 100
pc remove A
pc msg A B
LINQ:
from(list)
orfrom(array)
range(begin, end)
- Function: select, where, first, last, max, sum, for_each, group_by, distinct, union, etc.
TASK PROC:
- exec:执行代码
- exec_file:读文件执行代码
- kill:中止用户进程
- info:取得用户进程状态(用于浏览器远程回调)
USER HANDLE:(用户级进程支持的句柄种类)
- pipe:管道,类似Go中的chan,用于跨进程同步,读阻塞,写不阻塞。
- share:共享,同步跨进程数据共享。
- file:文件,虚拟文件接口,同步操作。
- window:窗口,创建JFrame窗口,异步,包括绘制、消息。
- net:网络,包括HTTP请求,OkHttp实现,异步。
Dependencies:(使用的开源库,下面为部分)
- JSON格式化:fastjson
- 实现远程命令SSH:netty
- 后端及API:spring-boot
- 网页模版:thymeleaf
- 前端交互:vue
- 前端样式:layui
- Markdown文档转换:flexmark
- 数据结构:guava
- HTTP请求:okhttp
- JAR打包:shadow
Manual
Example
Web Server
- Spring Boot API, port 8080
- Java NIO, port 8088
- Render Markdown using FlexMark
Front-end: LayUI(前端)
1. Spring Boot API
Front-end: LayUI + Vue.js API: Json + RestControllerBack-end: jMiniLang API Handler (RING 3 Process)
Run on Server
** Online Compiler Example V: GUI User Window **
评论