some more work on the first set. I think it might actually be right now

This commit is contained in:
Nathan Braswell
2015-07-16 23:32:27 -04:00
parent 51adf491fa
commit f431b0305a
3 changed files with 11 additions and 8 deletions

View File

@@ -143,7 +143,9 @@ obj grammer (Object) {
for (var i = 0; i < rhs.size; i++;) {
var lookahead = first_set_map[rhs[i]]
if (lookahead.contains(symbol::null_symbol())) {
lookahead.remove(symbol::null_symbol())
// remove the null if this is not the last in the rule
if (i != rhs.size-1)
lookahead.remove(symbol::null_symbol())
toRet.add(lookahead)
} else {
toRet.add(lookahead)

View File

@@ -3,8 +3,9 @@ a = b ;
b = "c":named_c ;
b = c "d":dname ;
c = "a" | d ;
d = e post_null post_non_null ;
d = e post_null post_non_null inherit_null ;
inherit_null = e | post_non_null ;
e = f | ;
f = ;
post_null = "hi"
post_non_null = "bye"
post_null = "hi" ;
post_non_null = "bye" ;

View File

@@ -7,9 +7,9 @@ import symbol:*
fun main():int {
/*var a = load_grammer(read_file(string("../krakenGrammer.kgm")))*/
var a = load_grammer(read_file(string("../krakenGrammer.kgm")))
/*var a = load_grammer(read_file(string("grammer.kgm")))*/
var a = load_grammer(read_file(string("grammer2.kgm")))
/*var a = load_grammer(read_file(string("grammer2.kgm")))*/
println(a.to_string())
var doFirstSet = fun() {
a.calculate_first_set()
@@ -39,10 +39,10 @@ fun main():int {
var lex = lexer(a.terminals)
/*lex.set_input(read_file(string("test_grammer.krak")))*/
lex.set_input(read_file(string("test_grammer.krak")))
/*lex.set_input(string("ccdahas spacedhas*/
/*returndaaaaaaaaaaaaaa"))*/
lex.set_input(string("hibyed"))
/*lex.set_input(string("hibyed"))*/
println("woo lexing:")
range(8).for_each(fun(i: int) { println(lex.next().to_string()); } )
/*range(80).for_each(fun(i: int) { println(lex.next().to_string()); } )*/