setelem.java
来自「用java实现的编译器. 包括语法分析」· Java 代码 · 共 29 行
JAVA
29 行
package inter;import lexer.*;import symbols.*;public class SetElem extends Stmt { public Id array; public Expr index; public Expr expr; public SetElem(Access x, Expr y) { array = x.array; index = x; expr = y; if(check(x.type, expr.type) == null) error("type error"); } public Type check(Type p1, Type p2) { if(p1 instanceof Array || p2 instanceof Array) return null; else if (p1 == p2) return p2; else if (Type.numeric(p1) && Type.numeric(p2)) return p2; else return null; } public void gen(int b, int a) { String s1 = index.reduce().toString(); String s2 = expr.reduce().toString(); emit(array.toString() + "[" + s1 + "] = " + s2); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?