2015-06-30 02:40:46 -04:00
|
|
|
import string
|
|
|
|
|
import vector
|
|
|
|
|
import set
|
|
|
|
|
import symbol
|
2015-07-03 18:34:46 -04:00
|
|
|
import regex
|
|
|
|
|
|
|
|
|
|
obj grammer (Object) {
|
|
|
|
|
var rules: vector::vector<rule>
|
|
|
|
|
var regexs: set::set<regex>
|
|
|
|
|
|
|
|
|
|
fun construct(): grammer* {
|
|
|
|
|
rules.construct()
|
|
|
|
|
regexs.construct()
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: grammer*) {
|
|
|
|
|
rules.copy_construct(&old->rules)
|
|
|
|
|
regexs.copy_construct(&old->regexs)
|
|
|
|
|
}
|
|
|
|
|
fun operator=(other: grammer) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun destruct() {
|
|
|
|
|
rules.destruct()
|
|
|
|
|
regexs.destruct()
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-30 02:40:46 -04:00
|
|
|
|
|
|
|
|
obj rule (Object) {
|
|
|
|
|
var lhs: symbol::symbol
|
|
|
|
|
var rhs: vector::vector<symbol::symbol>
|
|
|
|
|
var position: int
|
|
|
|
|
var lookahead: set::set<symbol::symbol>
|
|
|
|
|
|
|
|
|
|
fun construct(): rule* {
|
|
|
|
|
lhs.construct()
|
|
|
|
|
rhs.construct()
|
|
|
|
|
position = 0
|
|
|
|
|
lookahead.construct()
|
|
|
|
|
}
|
|
|
|
|
fun copy_construct(old: rule*) {
|
2015-07-03 18:34:46 -04:00
|
|
|
lhs.copy_construct(&other->lhs)
|
|
|
|
|
rhs.copy_construct(&other->rhs)
|
|
|
|
|
position = other->position
|
|
|
|
|
lookahead.copy_construct(&other->lookahead)
|
2015-06-30 02:40:46 -04:00
|
|
|
}
|
|
|
|
|
fun operator=(other: rule) {
|
|
|
|
|
destruct()
|
|
|
|
|
copy_construct(&other)
|
|
|
|
|
}
|
|
|
|
|
fun destruct() {
|
|
|
|
|
lhs.destruct()
|
|
|
|
|
rhs.destruct()
|
|
|
|
|
lookahead.destruct()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|