Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Guyutongxue/Compiler_Principles

Repository files navigation

sysyc 《编译原理》实践部分

测试

https://pku-minic.github.io/online-doc/#/misc-app-ref/environment

拉取 Docker 镜像

docker pull maxxing/compiler-dev

启动 Docker 容器

docker run -it --rm -v $(pwd):/root/compiler maxxing/compiler-dev bash

在容器内的 Shell 中,键入测试命令。如:

autotest -w wd /root/compiler -riscv

扩展语法

  • 函数声明;
  • 赋值表达式(返回左值);逗号表达式;
  • 指针;取地址;解地址;
  • 字符字面量,仅可见字符和 '\n'

例:

void swap(int* a, int* b);

int main() {
  int a = 42, b = 56;

  swap(&a, &b);

  putint(a), putch(' ');
  putint(b), putch('\n');
  return 0;
}

void swap(int* a, int* b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}
void change_arr(int (*arr)[3]) {
  (*arr)[0] = 1;
  (*arr)[1] = 2;
  (*arr)[2] = 3;
}

int main() {
  int arr[3];
  arr[0] = arr[1] = arr[2] = 4;
  change_arr(&arr);
  putint(arr[0]), putint(arr[1]), putint(arr[2]);
  putch('\n');
  return 0;
}

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Languages