编译原理——赋值语句与简单表达式(十一)

来源:互联网 发布:未找到数据库服务器 编辑:程序博客网 时间:2024/05/16 08:11

常数表。

ConstantTable.java:

package per.eyuan.util;public class ConstantTable {Constant table[]=new Constant[20];//标识符表,存放Constant对象实例int count=0;//Constant表中含有的Constant实例个数public ConstantTable() {super();init();}public void init(){for(int i=0;i<table.length;i++)table[i]=new Constant();}public int getCount(){return count;}public Constant getConstant(int index){//获取Constant表中指定索引的Constant实例return table[index];}public void addConstant(String val){table[count].value=val;table[count].index=count;count++;}public void addConstant(String ty,String val){table[count].type=ty;table[count].value=val;table[count].index=count;count++;}public Constant[] getAllConstant(){//获取所有的(有效)IdConstant acon[]=new Constant[count];for(int i=0;i<count;i++)acon[i]=table[i];return acon;}}


 

原创粉丝点击