moving computers. Parser still not quite right

This commit is contained in:
Nathan Braswell
2015-08-12 17:41:26 -04:00
parent 58ab3e311f
commit 8321b35a03
2 changed files with 21 additions and 3 deletions

View File

@@ -287,15 +287,32 @@ obj parser (Object) {
} else {
if (!are_packed(parent->children)) {
// ambiguity inner
var sub_parent = new<tree<symbol>>()->construct(symbol("AmbiguityInner", true))
set_packed(sub_parent, true)
sub_parent->children.add_all(parent->children)
parent->children.clear()
parent->children.add(sub_parent)
}
// ambiguity outer
var next_sub_parent = new<tree<symbol>>()->construct(symbol("AmbiguityOuter", true))
set_packed(next_sub_parent, true)
parent->children.add(next_sub_parent)
next_sub_parent->children.add_all(children)
}
}
fun belongs_to_family(node: *tree<symbol>, nodes: vector<*tree<symbol>>): bool {
return false
var family_count = 0
node->children.for_each(fun(child: *tree<symbol>) {
if (nodes.contains(child))
family_count++
})
return family_count == nodes.size
}
fun are_packed(nodes: vector<*tree<symbol>>): bool {
return true
return nodes.any_true(fun(it: *tree<symbol>):bool { return packed_map.contains_key(it) && packed_map[it]; })
}
fun set_packed(node: *tree<symbol>, packed: bool) {
packed_map.set(node, packed)
}
fun fully_reduces_to_null(r: ref rule): bool {
return r.position == 0 && gram.first_vector(r.rhs).contains(null_symbol())

View File

@@ -52,7 +52,8 @@ fun main():int {
println(a.to_string())
a.calculate_state_automaton()
var parse.construct(a): parser
var result = parse.parse_input(string("fun main():int { return 0; }"), string("fun name"))
var result = parse.parse_input(string("inport a;"), string("fun name"))
/*var result = parse.parse_input(string("fun main():int { return 0; }"), string("fun name"))*/
/*var result = parse.parse_input(string("ad"), string("fun name"))*/
/*var result = parse.parse_input(string("hibyed"), string("fun name"))*/
/*var result = parse.parse_input(string("hmmhmm"), string("fun name"))*/