Files
kraken/stdlib/grammer.krak

58 lines
1.2 KiB
Plaintext

import string
import vector
import set
import symbol
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()
}
}
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*) {
lhs.copy_construct(&other->lhs)
rhs.copy_construct(&other->rhs)
position = other->position
lookahead.copy_construct(&other->lookahead)
}
fun operator=(other: rule) {
destruct()
copy_construct(&other)
}
fun destruct() {
lhs.destruct()
rhs.destruct()
lookahead.destruct()
}
}