logical.java

来自「23种设计模式JAVA实现,很好很有用的东西.」· Java 代码 · 共 35 行

JAVA
35
字号
package inter;import lexer.*; import symbols.*;public class Logical extends Expr {   public Expr expr1, expr2;   Logical(Token tok, Expr x1, Expr x2) {      super(tok, null);                      // null type to start      expr1 = x1; expr2 = x2;      type = check(expr1.type, expr2.type);      if (type == null ) error("type error");   }   public Type check(Type p1, Type p2) {      if ( p1 == Type.Bool && p2 == Type.Bool ) return Type.Bool;      else return null;   }   public Expr gen() {      int f = newlabel(); int a = newlabel();      Temp temp = new Temp(type);      this.jumping(0,f);      emit(temp.toString() + " = true");      emit("goto L" + a);      emitlabel(f); emit(temp.toString() + " = false");      emitlabel(a);      return temp;   }   public String toString() {      return expr1.toString()+" "+op.toString()+" "+expr2.toString();   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?