All Projects → chang-ke → Compiler-Principle

chang-ke / Compiler-Principle

Licence: other
词法分析,LL(1) 文法分析,LR(1) 文法分析

Programming Languages

C++
36643 projects - #6 most used programming language
javascript
184084 projects - #8 most used programming language
c
50402 projects - #5 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to Compiler-Principle

C Cpp Notes
Notes about modern C++, C++11, C++14 and C++17, Boost Libraries, ABI, foreign function interface and reference cards.
Stars: ✭ 363 (+1916.67%)
Mutual labels:  dll, ffi
asmdot
[Unstable] Fast, zero-copy and lightweight (Arm | Mips | x86) assembler in (C | C++ | C# | Go | Haskell | Javascript | Nim | OCaml | Python | Rust).
Stars: ✭ 23 (+27.78%)
Mutual labels:  ffi
ProcessInjector.NET
Learning Process Injection and Hollowing techniques
Stars: ✭ 23 (+27.78%)
Mutual labels:  dll
VoiceBridge
VoiceBridge - an AI-TOOLKIT Open Source C++ Speech Recognition Toolkit
Stars: ✭ 17 (-5.56%)
Mutual labels:  dll
rid-examples
Examples showing how to use Rid in order to build Dart/Flutter apps integrated with Rust.
Stars: ✭ 191 (+961.11%)
Mutual labels:  ffi
hexen-dll-injector
HEX-EN DLL Injector
Stars: ✭ 20 (+11.11%)
Mutual labels:  dll
Extensive-C0-Compiler
北航计算机学院 编译原理最高难度课程设计 BUAA SCSE - Extensive C0 Compiler Design
Stars: ✭ 34 (+88.89%)
Mutual labels:  compiler-design
denoffi
Deno Foreign Function Interface.
Stars: ✭ 37 (+105.56%)
Mutual labels:  ffi
pyCompiler
Python Compiler
Stars: ✭ 13 (-27.78%)
Mutual labels:  compiler-design
php-fuse
PHP FFI bindings for libfuse
Stars: ✭ 53 (+194.44%)
Mutual labels:  ffi
react-native-fast-openpgp
OpenPGP for react native made with golang for fast performance
Stars: ✭ 29 (+61.11%)
Mutual labels:  ffi
php-ffi-rust
PHP7.4 + Rust
Stars: ✭ 28 (+55.56%)
Mutual labels:  ffi
Xamarin-iOS
PSPDFKit for iOS wrapper for the Xamarin platform.
Stars: ✭ 14 (-22.22%)
Mutual labels:  dll
d-l-l
Simplified DLL config creator & handler
Stars: ✭ 27 (+50%)
Mutual labels:  dll
Standard-Toolkit
An update to Component factory's krypton toolkit to support .NET Framework 4.6.2 - 4.8.1 to .NET Core/.NET
Stars: ✭ 194 (+977.78%)
Mutual labels:  dll
RunDLL-NG
A better alternative to RunDLL32
Stars: ✭ 23 (+27.78%)
Mutual labels:  dll
rust-xgboost
Rust bindings for XGBoost.
Stars: ✭ 77 (+327.78%)
Mutual labels:  ffi
Krypton-Toolkit-Suite-NET-Core
A update to Component factory's krypton toolkit to support .NET Framework 3.5 to .NET Core
Stars: ✭ 27 (+50%)
Mutual labels:  dll
deno bindgen
Simplified glue code generation for Deno FFI libraries written in Rust.
Stars: ✭ 142 (+688.89%)
Mutual labels:  ffi
DllLoaderShellcode
Shellcode to load an appended Dll
Stars: ✭ 72 (+300%)
Mutual labels:  dll

Introduction

编译原理实验

  • 词法分析器和LL(1)文法核心代码均采用C++实现,服务端代码使用Koa2实现,前端可视化代码使用React实现 js作为胶水层(node-ffi)将c++运行的结果转发给前端,数据格式使用json
  • LR(1)文法我用的是JavaScript,原因是我做LL(1)文法的时候,要把预测分析表可视化出来,这样去拼接json字符串给nodejs太麻烦了 于是我就用了JavaScript,便于可视化图表等,而且数据结构也比C++好用

使用

npm install 安装依赖
npm run server 开启服务端
npm run dev 开启react开发
npm start 同时启动server和dev

环境:

windows10 + vs2015 + nodejs-v8.9.3

  • ffi引用dll库时参考的文章
  • ffi引入函数名错误参考的文章
  • 编译dll的时候,在CompilersPrinciplesDll.cpp文件里面引入iostream, string等头文件报错,将头文件引入至stdafx.h即可解决
  • ffi里面的string类型对应c++是char* 类型的,而我需要使用string,直接使用string无法获取参数和结果,所以写了个函数转换
  • 其实可以不用ffi的,但是要安装c++编译器,利用child_process.exec去执行cpp文件,然后利用exec返回的子进程进行管道通信
// char* 可直接赋值给string
// string 转 char*,用来返回结果给nodejs
char* to_char_pointer(string str) {
	int length = (int)str.length();
	char *p = new char[length + 1];
	for (int i = 0; i < length; ++i) {
		p[i] = str[i];
	}
	p[length] = '\0'; //加上结束符
	return p;
}

效果预览

  • 词法分析

词法分析我是利用循环来实现自动机匹配标识符,数字等等 词法分析效果图

  • LL(1)

LL的关键在于求出first集和follow集,求first集的时候要注意消除左递归,然后根据first集和follow集求出预测分析表 LL(1)效果图

  • LR(1)

LR的关键在于goto函数和closure函数,只要把这两个函数写出来,整个实验就完成了大半了,当然,这里面的项目还有超前搜索符,这个需要考虑怎么表示,个人觉得使用脚本语言或者c++都挺好写的,c++有结构体,python有字典,JavaScript有字面量对象,但是Java纯面向对象的语言表示这个感觉有点鸡肋。 LR(1)效果图

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].