jMiniLangKotlin 实现的编译器和虚拟机

联合创作 · 2023-10-02

jMiniLang 项目是一个 LR 编译器、虚拟机一体化工程,并且对虚拟机进行了拓展,参考了操作系统设计的思想。

Features(特性)

  1. 词法分析阶段。Lexer which generates NFA and DFA.
  2. 语法分析、词法分析、制导翻译。Parser which implements LALR(1) Grammar with optional semantic action.
  3. 语义分析。Customized semantic analysis.
  4. 可打印语法树。Printable syntax tree.
  5. 基于栈的自定义指令集。Stack-based instruction design.
  6. Kotlin本地方法导入。Native method.
  7. 代码页导入/导出。Import and export of code page.
  8. 代码页序列化。Serializable code page.
  9. 匿名函数及闭包。Lambda functions and Closure.
  10. 语法/词法错误提示。Display grammar and semantic errors.
  11. 管道机制。Pipe.
  12. 多进程机制。Multiple process.
  13. 同步/异步执行代码。Load file with Sync/Async.
  14. 虚拟机。Virtual machine.
  15. 支持彩色界面。Support Colorful GUI.
  16. 函数式编程。Functional programming.
  17. LISP.
  18. 网络流。Socket stream.
  19. 虚拟文件系统。Save/Load file or VFS.
  20. 基于原型的类设计。Class prototype.
  21. Bash Interface.
  22. 数组/词典初始化。Array/Map initialize list.
  23. 异常机制。Try/Catch/Throw.
  24. 行为树。Behavior Tree, including PC network simulator.
  25. 用户级进程。RING 3 Process, including User Service, fork.
  26. 网页服务器。Web Server, including Online Compiler and Runner.
  27. 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命令)

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 time
  • task util calc 1+2*3 -> Val = 7
  • task ui print hello world -> Remote window
  • task ui path M 100 100 L 200 200 -> SVG

Utility:

  • task util doc g_func_fold -> Document
  • task 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 fork
  • test class: Test AOP and Prototype for class
  • test bash: Test bash interface
  • test try: Test try/catch
  • test badapple: Test ascii output, code in BadApple
  • test dialog: Test JOptionPane.showXXXDialog
  • test linq: Test LINQ
  • test proc: Test Ring 3 API
  • test proc2: Test Ring 3 code with input
  • test 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) or from(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

Simplified Chinese Version

Example

Web Server

  1. Spring Boot API, port 8080
  2. Java NIO, port 8088
  3. Render Markdown using FlexMark

Front-end: LayUI(前端)

1. Spring Boot API

Front-end: LayUI + Vue.js API: Json + RestController

Back-end: jMiniLang API Handler (RING 3 Process)

Run on Server

** Online Compiler Example V: GUI User Window **

浏览 10
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报