⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_muldiv.java

📁 中山大学编译原理课程的一个实验
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package symbols;import exceptions.DividedByZeroException;import exceptions.MissingOperandException;import exceptions.TypeMismatchedException;import java.util.ArrayList;/** * * @author Beeven */public class T_MULDIV extends Terminal implements TerminalReduce{    public Expr reduce(ArrayList<Expr> stack) throws TypeMismatchedException, DividedByZeroException, MissingOperandException {        int post=stack.size()-1;        Expr a =stack.get(post-2);        Expr o = stack.get(post-1);        Expr b = stack.get(post);        if((b.type==Type.muldiv)) throw new MissingOperandException();        if(!(a instanceof ArithExpr)|| !(b instanceof ArithExpr))            throw new TypeMismatchedException();        ArithExpr ae;        if(o.tag==Tag.MULTIPLY)            ae=new ArithExpr(((ArithExpr)a).value * ((ArithExpr)b).value);        else if(((ArithExpr)b).value==0)            throw new DividedByZeroException();        else            ae=new ArithExpr(((ArithExpr)a).value / ((ArithExpr)b).value);        stack.remove(post);        stack.remove(post-1);        stack.remove(post-2);        stack.add(ae);        return ae;    }}

⌨️ 快捷键说明

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