📄 symbol.java
字号:
package jeex.tiny;
import java.util.*;
/**
* Attributes of an identifier are hold in a symbol.
*/
class Symbol {
/**
* Memory address of this identifier.
*/
int address;
/**
* Identifier name this symbol corespondent to.
*/
String name;
/**
* Only can be created in enter().
*/
private Symbol(String name,int address) {
this.name = name;
this.address = address;
}
public String toString() {
return name + ":" + address;
}
/**
* Create a symbol and put the symbol into symbol table.
* @param name - name of identifier
*/
static Symbol enter(String name) {
Symbol s = new Symbol(name,offset++);
symtab.put(name,s);
return s;
}
/**
* Returns a defined symbol. If not defined, return null.
* @param name - name of identifier
*/
static Symbol get(String name) {
return (Symbol)symtab.get(name);
}
/**
* Returns true if the name is entered in the symbol table.
*/
static boolean isDefined(String name) {
return symtab.containsKey(name);
}
/**
* Symbol table.
*/
static Map symtab = new HashMap();
/**
* Next created symbol's address, updated when a new symbol created in enter().
*/
static int offset = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -