Target: Tree -> intermediate code
- 语言 python 3.6 + 虚拟环境
-
中间代码的定义和接口
- 基本形式:三地址码 模仿mips?
- 接口类型:
- 生成代码 (string)
- 算术型
- move型
- declaration型 (label,function,parameter)
- 函数返回
- 添加代码
- add code(string)
- 输出代码
- print()
- write(string path)
- 生成代码 (string)
- 全局变量管理 list codelist
-
数据结构
- node(不同类型的node)
- block
-
分析语法树生成初步的中间代码
- 全局变量
- function_pool//函数声明
- BlockStack
- 解析部分
- 文法分类(这里主要针对我们写的文法来一步步分类定义)
- 递归解析(每一层应有的中间代码生成)
- 一些辅助函数
- 各种get\set\find\create
- error()\print()提供可视化debug
- 难点
- block的定义(每个compoud_statement就算一个?)
- 函数(声明检查、类型检查、返回类型)
- 跳转语句(break,continue,return,goto)
- 数组(内存的申请、管理)
- 栈帧(参数传递、静态链、返回地址)
- 注意事项
- expression中的类型检查
- label的管理
- 默认有input(),print()函数
- 全局变量
-
优化中间代码
- 去除不必要的多余代码
- 待续