build and run
This commit is contained in:
+2
-1
@@ -77,4 +77,5 @@ fabric.properties
|
|||||||
# Editor-based Rest Client
|
# Editor-based Rest Client
|
||||||
.idea/httpRequests
|
.idea/httpRequests
|
||||||
|
|
||||||
/res/lexer.c
|
# /res/lexer.c
|
||||||
|
!/lib/*.jar
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: com.compiler.Main
|
||||||
|
Class-Path: lib/commons-lang3-3.0.jar lib/asm-9.1.jar
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# CJCompiler
|
||||||
|
|
||||||
|
把类C语法编译成Java字节码。
|
||||||
|
|
||||||
|
## 构建方式
|
||||||
|
|
||||||
|
1. python build.py
|
||||||
|
2. java -jar ./CJCompiler.jar
|
||||||
|
3. java lexer
|
||||||
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
|
proj_dir = os.getcwd()
|
||||||
|
src_dir = os.path.join(proj_dir, "src")
|
||||||
|
lib_dir = os.path.join(proj_dir, "lib")
|
||||||
|
out_dir = os.path.join(proj_dir, "out")
|
||||||
|
res_dir = os.path.join(proj_dir, "res")
|
||||||
|
jar = os.path.join(proj_dir, "CJCompiler.jar")
|
||||||
|
MANIFEST = os.path.join(proj_dir, "MANIFEST.MF")
|
||||||
|
|
||||||
|
src_files = []
|
||||||
|
for path, dir_names, file_names in os.walk(src_dir):
|
||||||
|
file_paths = [os.path.join(path, x) for x in file_names]
|
||||||
|
src_files += file_paths
|
||||||
|
|
||||||
|
lib_files = [os.path.join(lib_dir, x) for x in os.listdir(lib_dir)]
|
||||||
|
|
||||||
|
shutil.rmtree(out_dir, True)
|
||||||
|
cmd = f"javac -d {out_dir} -encoding utf-8 -cp .;{';'.join(lib_files)} -sourcepath {src_dir} {' '.join(src_files)}"
|
||||||
|
print(cmd)
|
||||||
|
os.system(cmd)
|
||||||
|
|
||||||
|
shutil.copytree(res_dir, os.path.join(out_dir, "res"))
|
||||||
|
shutil.copytree(lib_dir, os.path.join(out_dir, "lib"))
|
||||||
|
|
||||||
|
|
||||||
|
cmd = f"cd {out_dir} && jar -cvfm {jar} {MANIFEST} *"
|
||||||
|
print(cmd)
|
||||||
|
os.system(cmd)
|
||||||
Binary file not shown.
Binary file not shown.
+23
@@ -0,0 +1,23 @@
|
|||||||
|
int a = 1;
|
||||||
|
int b =0;
|
||||||
|
int c;
|
||||||
|
char eq='=';
|
||||||
|
char ent = '\n';
|
||||||
|
char mul = 'x';
|
||||||
|
char blank = '_';
|
||||||
|
|
||||||
|
while(a<=9){
|
||||||
|
b=1;
|
||||||
|
while(b<a){
|
||||||
|
print b;
|
||||||
|
print mul;
|
||||||
|
print a;
|
||||||
|
|
||||||
|
print eq;
|
||||||
|
print c;
|
||||||
|
print blank;
|
||||||
|
b=b+1;
|
||||||
|
}
|
||||||
|
println ent;
|
||||||
|
a=a+1;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user