programming labs in se courses
what it supports:
- define valiable and assignment
- if-else
- for, while and break-continue
- function
- a little bytecode vm like python
a little example:
/*
a little program language
*/
int main(){
string name := "cxk"; //声明语句
int age := 20;
double score := 23.5E+2;
printf("name: ");
printf(name);
printf("age: ");
printf(age);
printf("score: ");
printf(score);
//判断语句
if(age <= 22){
printf("you are young!");
}else{
printf("you are old!");
}
//循环语句
printf("******************************");
printf("使用for循环计算 10*(1-100) 的值:");
int sum1 := 0;
for(int i:=0; i<10; i:= i+1){
for(int j:=1; j<=100; j := j+1){
sum1 := sum1 + j;
}
}
printf(sum1);
//while循环
printf("******************************");
printf("使用while循环计算值小于50的斐波那契数列:");
int first := 0;
int second := first + 1;
while(second <= 50){
printf(second);
int temp := second;
second := temp + first;
first := temp;
}
printf("test function:");
int a := add(1, 2);
int b := square(0, 2);
printf(square(a, b));
}
int add(int a, int b){
return a+b;
}
//平方
int square(int a, int b){
return add(a*a, b*b);
}
how to use
- cd ProgrammingLabs/compiler/CompilerAPIVersion/
- java -jar compiler.jar filepath
- just open the CompilerDisplay/ file with IDEA and run it.
- open http://127.0.0.1:8080