-
-
Notifications
You must be signed in to change notification settings - Fork 5
small a compiler
License
leikang123/LKCompiler
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
LKCompiler是一个小型编译器,LKCompiler使用JavaCC解析器。
==============================================================================================================================================================================================================================================
LKCompiler目前只写了环境安装部分,词法语法少量的实现,后期需要很多语法和词法参与进来,欢迎大家点个stared或者fork,作者有动力造个轮子,初心就是写个编译器,打造一个编程语言玩玩。
如果大家有想法参与贡献,可以加入,但是这个有基础的,具备编译原理基础,如果没有学习编译原理或者很难学习,可以推荐路线图学习
http://coursegalaxy.com/compilers/learn-design.html
有基础的话可以了解一下整个架构,从词法设计开始参与进来。
///===----------------------------------------------------------------------------------
/// 新增了深度学习模型,为的是大家学习一下这个megcc编译器的支持
///===----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
编译器语法规则:
// 库函数运用Java的import,函数名用c函数库
import stdio;
int main(int argc, char **argv)
{
// 打印类似于C语言
printf("Hello, World!\n");
printf("%s\n", "Hello, World!");
return 0;
}
// 数值运算语法:
import stdio;
static int g = 3;
static int c;
int main(int argc, char **argv)
{
int i;
int j = 0;
printf("%d",i);
printf(";%d",j);
i = 2;
j = 1;
printf(";%d", i++);
printf(";%d", j++);
printf(";%d", i + g);
printf(";%d", f(5));
printf(";%d", f(5) + 1);
printf(";%d", f(5) + i);
c = 5;
printf(";%d", f(3) + c);
i = 9;
printf(";%d", f(i));
j = 1;
printf(";%d", f(i) + j);
puts("");
return 0;
}
int f(int i)
{
return i + 1;
}
============================================================================================
配置要求前提:
* JDK 1.5 or later
* JavaCC 4.0 or later
* ant
* make
运行安装配置要求
* Linux 2.4以上
* util-linux (ld-linux.so.2)
* GNU libc 2.3 以上
* GNU binutils (as, ld)
安装
安装目录 /usr/local/LKCompiler:
# sudo ./install.sh
# sudo ln -s ../LKCompiler/bin/LKCompiler /usr/local/bin/LKCompiler
安装好环境配置 $HOME/lkc:
$ ./install.sh $HOME/LKCompiler
$ ln -s ../LKCompiler/bin/LKCompiler $HOME/bin/LKCompiler
Build
该目录下编辑:
make:
$ vi build.properties
$ make
Test
测试:
$ make test
语法使用测试案例以及架构说明:
LKC
|
|----test:启动文件
|
|----example:案例例子测试,文件后缀名为:xxx.l
|
|----bin:启动脚本文件
|
|----src
|
|----main
|
|
|----IR:中间代码生成文件
|
|----parser:解析文件,词法语法规则的设计
|
|----system:系统平台,目前是X86,陆续会增加ARM,RISC-V
|----compiler:编译器部分核心代码
|
|----AST:语法树部分
|
|----assembly:汇编语言对象代码
About
small a compiler
Topics
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Sponsor this project
Packages 0
No packages published