96 lines
2.9 KiB
Plaintext
96 lines
2.9 KiB
Plaintext
import string
|
|
import serialize
|
|
import vector
|
|
import util
|
|
|
|
fun null_symbol(): symbol {
|
|
var toRet.construct(string::string("$NULL$"), false, string::string("$NULL$")): symbol
|
|
return toRet
|
|
}
|
|
fun eof_symbol(): symbol {
|
|
var toRet.construct(string::string("$EOF$"), false, string::string("$EOF$")): symbol
|
|
return toRet
|
|
}
|
|
fun invalid_symbol(): symbol {
|
|
var toRet.construct(string::string("$INVALID$"), false, string::string("$INVALID$")): symbol
|
|
return toRet
|
|
}
|
|
|
|
fun symbol(nameIn: *char, terminalIn: bool): symbol {
|
|
var toRet.construct(string::string(nameIn), terminalIn, string::string("no_value")): symbol
|
|
return toRet
|
|
}
|
|
|
|
fun symbol(nameIn: string::string, terminalIn: bool): symbol {
|
|
var toRet.construct(nameIn, terminalIn, string::string("no_value")): symbol
|
|
return toRet
|
|
}
|
|
|
|
fun symbol(nameIn: *char, terminalIn: bool, dataIn: *char): symbol {
|
|
var toRet.construct(string::string(nameIn), terminalIn, string::string(dataIn)): symbol
|
|
return toRet
|
|
}
|
|
|
|
fun symbol(nameIn: string::string, terminalIn: bool, dataIn: string::string): symbol {
|
|
var toRet.construct(nameIn, terminalIn, dataIn): symbol
|
|
return toRet
|
|
}
|
|
|
|
obj symbol (Object, Serializable) {
|
|
var data: string::string
|
|
var name: string::string
|
|
var terminal: bool
|
|
|
|
fun construct(): *symbol {
|
|
data.construct()
|
|
name.construct()
|
|
return this
|
|
}
|
|
fun construct(nameIn: string::string, terminalIn: bool, dataIn: string::string): *symbol {
|
|
name.construct(nameIn)
|
|
terminal = terminalIn
|
|
data.construct(dataIn)
|
|
return this
|
|
}
|
|
fun destruct() {
|
|
data.destruct()
|
|
name.destruct()
|
|
}
|
|
fun copy_construct(old: *symbol) {
|
|
data.copy_construct(&old->data)
|
|
name.copy_construct(&old->name)
|
|
terminal = old->terminal
|
|
}
|
|
fun operator=(old: ref symbol) {
|
|
destruct()
|
|
copy_construct(&old)
|
|
}
|
|
fun serialize(): vector::vector<char> {
|
|
return serialize::serialize(data) + serialize::serialize(name) + serialize::serialize(terminal)
|
|
}
|
|
fun unserialize(it: ref vector::vector<char>, pos: int): int {
|
|
/*construct()*/
|
|
/*util::unpack(data, pos) = serialize::unserialize<string::string>(it, pos)*/
|
|
/*util::unpack(name, pos) = serialize::unserialize<string::string>(it, pos)*/
|
|
pos = data.unserialize(it, pos)
|
|
pos = name.unserialize(it, pos)
|
|
util::unpack(terminal, pos) = serialize::unserialize<bool>(it, pos)
|
|
return pos
|
|
}
|
|
fun operator==(other: ref symbol): bool {
|
|
return data == other.data && name == other.name && terminal == other.terminal;
|
|
}
|
|
fun operator!=(other: ref symbol): bool {
|
|
return !(*this == other);
|
|
}
|
|
fun to_string(): string::string {
|
|
var terminalString: *char
|
|
if (terminal)
|
|
terminalString = "true"
|
|
else
|
|
terminalString = "false"
|
|
return name + ": " + data + " " + terminalString
|
|
}
|
|
}
|
|
|