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

📄 quaternion.java.svn-base

📁 北航编译原理课程设计成果——一个扩充的C0文法编译器
💻 SVN-BASE
字号:
package cn.edu.buaa.scse.liyi.compile.types;

import cn.edu.buaa.scse.liyi.compile.tools.Lex;
import cn.edu.buaa.scse.liyi.compile.tools.Yacc;

/**
 * 
 * @author liyi
 */
public class Quaternion
{
	private int operator;				//操作符
	private String operend1;			//操作数1
	private String operend2;			//操作数2
	private String result;				//结果
	
	/**
	 * 四元式类构造方法
	 * @param operator
	 * @param operend1
	 * @param operend2
	 * @param result
	 */
	public Quaternion(int operator,String operend1,String operend2,String result)
	{
		this.operend1=operend1;
		this.operend2=operend2;
		this.operator=operator;
		this.result=result;
	}
	
	/**
	 * 四元式类构造方法
	 * @param quater
	 */
	public Quaternion(Quaternion quater)
	{
		this.operator=quater.getOperator();
		this.operend1=quater.getOperend1();
		this.operend2=quater.getOperend2();
		this.result=quater.getResult();	
	}
	
	public void setOperator(int operator)
	{
		this.operator=operator;
	}
	public void setOperend1(String operend1)
	{
		this.operend1=operend1;
	}
	public void setOperend2(String operend2)
	{
		this.operend2=operend2;
	}
	public void setResult(String result)
	{
		this.result=result;
	}
	
	public int getOperator()
	{
		return this.operator;
	}
	public String getOperend1()
	{
		return this.operend1;
	}
	public String getOperend2()
	{
		return this.operend2;
	}
	public String getResult()
	{
		return this.result;
	}
	
	/**
	 * 判断两个四元式是否等价
	 * @param quater
	 * @return
	 */
	public boolean equivalents(Quaternion quater)
	{
		if(this.operator==quater.getOperator())
		{
			if(this.operend1.equals(quater.getOperend1())&&this.operend2.equals(quater.getOperend2()))
				return true;
			else if(this.operator==Yacc.ADD||this.operator==Yacc.MUL)
			{
				if(this.operend1.equals(quater.getOperend2())&&this.operend2.equals(quater.getOperend1()))
					return true;
			}
			return false;
		}
		return false;
	}
	
	/**
	 * 输出显示
	 * @Override
	 */
    public String toString()
    {
		String ss=new String();
		String cc=new String();
		if(this.operator==Yacc.ADD)
		{
			ss="ADD";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.SUB)
		{
			ss="SUB";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.MUL)
		{
			ss="MUL";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.DIV)
		{
			ss="DIV";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.CONDITION)
		{
			ss="condition";
			if(Integer.parseInt(this.operend1)==Lex.G)
			{
				cc="G";
			}
			else if(Integer.parseInt(this.operend1)==Lex.L)
			{
				cc="L";
			}
			else if(Integer.parseInt(this.operend1)==Lex.GE)
			{
				cc="GE";
			}
			else if(Integer.parseInt(this.operend1)==Lex.LE)
			{
				cc="LE";
			}
			else if(Integer.parseInt(this.operend1)==Lex.NE)
			{
				cc="NE";
			}
			else if(Integer.parseInt(this.operend1)==Lex.EE)
			{
				cc="EE";
			}
		}
		else if(this.operator==Yacc.MOV)
		{
			ss="MOV";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.STAMP)
		{
			ss="STAMP";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.J)
		{
			ss="J";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.JFALSE)
		{
			ss="JFALSE";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.PRINTF)
		{
			ss="PRINTF";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.CMP)
		{
			ss="CMP";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.PUSHPARA)
		{
			ss="PUSHPARA";
			cc=this.operend1;
		}
		else if(this.operator==Yacc.CALL)
		{
			ss="CALL";
			cc=this.operend1;
		}
		else if(this.operator==14)
		{
			ss="SCANF";
			cc=this.operend1;
		}
		else if(this.operator==15)
		{
			ss="RETURN";
			cc=this.operend1;
		}
		return (ss+"\t"+cc+"\t"+this.operend2+"\t"+this.result);
	}
	
}

⌨️ 快捷键说明

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