Make the grammer test work again by updating grammer and parser to use the new adt syntax - I also messed up commenting out one of the cout lines making lambdas not work.
This commit is contained in:
@@ -555,7 +555,7 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
|
|||||||
auto statement = transform(getNode("statement", children), scope, types, false, templateTypeReplacements); // definitly do not limit this statement to functions
|
auto statement = transform(getNode("statement", children), scope, types, false, templateTypeReplacements); // definitly do not limit this statement to functions
|
||||||
if (name == "lambda")
|
if (name == "lambda")
|
||||||
newNode->getDataRef()->closedVariables = findVariablesToClose(newNode, statement, scope);
|
newNode->getDataRef()->closedVariables = findVariablesToClose(newNode, statement, scope);
|
||||||
for (auto i : newNode->getDataRef()->closedVariables)
|
//for (auto i : newNode->getDataRef()->closedVariables)
|
||||||
//std::cout << "OK, CLOSED: " << i->getDataRef()->toString() << std::endl;
|
//std::cout << "OK, CLOSED: " << i->getDataRef()->toString() << std::endl;
|
||||||
newNode->addChild(statement);
|
newNode->addChild(statement);
|
||||||
//std::cout << "finished function" << functionName << std::endl;
|
//std::cout << "finished function" << functionName << std::endl;
|
||||||
|
|||||||
@@ -512,14 +512,24 @@ obj action {
|
|||||||
return act == other.act && state_or_rule == other.state_or_rule && rule_position == other.rule_position
|
return act == other.act && state_or_rule == other.state_or_rule && rule_position == other.rule_position
|
||||||
}
|
}
|
||||||
fun print() {
|
fun print() {
|
||||||
if (act == action_type::push)
|
match (act) {
|
||||||
|
action_type::push()
|
||||||
io::print("push ")
|
io::print("push ")
|
||||||
else if (act == action_type::reduce)
|
action_type::reduce()
|
||||||
io::print("reduce ")
|
io::print("reduce ")
|
||||||
else if (act == action_type::accept)
|
action_type::accept()
|
||||||
io::print("accept ")
|
io::print("accept ")
|
||||||
else if (act == action_type::reject)
|
action_type::reject()
|
||||||
io::print("reject ")
|
io::print("reject ")
|
||||||
|
}
|
||||||
|
/*if (act == action_type::push)*/
|
||||||
|
/*io::print("push ")*/
|
||||||
|
/*else if (act == action_type::reduce)*/
|
||||||
|
/*io::print("reduce ")*/
|
||||||
|
/*else if (act == action_type::accept)*/
|
||||||
|
/*io::print("accept ")*/
|
||||||
|
/*else if (act == action_type::reject)*/
|
||||||
|
/*io::print("reject ")*/
|
||||||
io::print(state_or_rule)
|
io::print(state_or_rule)
|
||||||
io::print(" ")
|
io::print(" ")
|
||||||
io::print(rule_position)
|
io::print(rule_position)
|
||||||
@@ -566,25 +576,25 @@ obj table (Object, Serializable) {
|
|||||||
expand_to(from_state)
|
expand_to(from_state)
|
||||||
var cleaned_symbol = clean_symbol(on_symbol)
|
var cleaned_symbol = clean_symbol(on_symbol)
|
||||||
if (items[from_state].contains_key(cleaned_symbol))
|
if (items[from_state].contains_key(cleaned_symbol))
|
||||||
items[from_state][cleaned_symbol].addEnd(action(action_type::push, to_state))
|
items[from_state][cleaned_symbol].addEnd(action(action_type::push(), to_state))
|
||||||
else
|
else
|
||||||
items[from_state].set(cleaned_symbol, vector::vector(action(action_type::push, to_state)))
|
items[from_state].set(cleaned_symbol, vector::vector(action(action_type::push(), to_state)))
|
||||||
}
|
}
|
||||||
fun add_reduce(from_state: int, on_symbol: ref symbol::symbol, by_rule_no: int, rule_position: int) {
|
fun add_reduce(from_state: int, on_symbol: ref symbol::symbol, by_rule_no: int, rule_position: int) {
|
||||||
expand_to(from_state)
|
expand_to(from_state)
|
||||||
var cleaned_symbol = clean_symbol(on_symbol)
|
var cleaned_symbol = clean_symbol(on_symbol)
|
||||||
if (items[from_state].contains_key(cleaned_symbol))
|
if (items[from_state].contains_key(cleaned_symbol))
|
||||||
items[from_state][cleaned_symbol].addEnd(action(action_type::reduce, by_rule_no, rule_position))
|
items[from_state][cleaned_symbol].addEnd(action(action_type::reduce(), by_rule_no, rule_position))
|
||||||
else
|
else
|
||||||
items[from_state].set(cleaned_symbol, vector::vector(action(action_type::reduce, by_rule_no, rule_position)))
|
items[from_state].set(cleaned_symbol, vector::vector(action(action_type::reduce(), by_rule_no, rule_position)))
|
||||||
}
|
}
|
||||||
fun add_accept(from_state: int, on_symbol: ref symbol::symbol) {
|
fun add_accept(from_state: int, on_symbol: ref symbol::symbol) {
|
||||||
expand_to(from_state)
|
expand_to(from_state)
|
||||||
var cleaned_symbol = clean_symbol(on_symbol)
|
var cleaned_symbol = clean_symbol(on_symbol)
|
||||||
if (items[from_state].contains_key(cleaned_symbol))
|
if (items[from_state].contains_key(cleaned_symbol))
|
||||||
items[from_state][cleaned_symbol].addEnd(action(action_type::accept, 0))
|
items[from_state][cleaned_symbol].addEnd(action(action_type::accept(), 0))
|
||||||
else
|
else
|
||||||
items[from_state].set(cleaned_symbol, vector::vector(action(action_type::accept, 0)))
|
items[from_state].set(cleaned_symbol, vector::vector(action(action_type::accept(), 0)))
|
||||||
}
|
}
|
||||||
fun get(state: int, on_symbol: symbol::symbol): vector::vector<action> {
|
fun get(state: int, on_symbol: symbol::symbol): vector::vector<action> {
|
||||||
var cleaned_symbol = clean_symbol(on_symbol)
|
var cleaned_symbol = clean_symbol(on_symbol)
|
||||||
@@ -593,17 +603,17 @@ obj table (Object, Serializable) {
|
|||||||
fun get_shift(state: int, on_symbol: symbol::symbol): action {
|
fun get_shift(state: int, on_symbol: symbol::symbol): action {
|
||||||
var actions = get(state, on_symbol)
|
var actions = get(state, on_symbol)
|
||||||
for (var i = 0; i < actions.size; i++;)
|
for (var i = 0; i < actions.size; i++;)
|
||||||
if (actions[i].act == action_type::push)
|
if (actions[i].act == action_type::push())
|
||||||
return actions[i]
|
return actions[i]
|
||||||
io::println("tried to get a shift when none existed")
|
io::println("tried to get a shift when none existed")
|
||||||
io::print("for state ")
|
io::print("for state ")
|
||||||
io::print(state)
|
io::print(state)
|
||||||
io::print(" and symbol ")
|
io::print(" and symbol ")
|
||||||
io::println(on_symbol.to_string())
|
io::println(on_symbol.to_string())
|
||||||
return action(action_type::invalid,-1)
|
return action(action_type::invalid(),-1)
|
||||||
}
|
}
|
||||||
fun get_reduces(state: int, on_symbol: symbol::symbol): vector::vector<action> {
|
fun get_reduces(state: int, on_symbol: symbol::symbol): vector::vector<action> {
|
||||||
return get(state, on_symbol).filter(fun(act: action):bool { return act.act == action_type::reduce; })
|
return get(state, on_symbol).filter(fun(act: action):bool { return act.act == action_type::reduce(); })
|
||||||
}
|
}
|
||||||
fun print_string() {
|
fun print_string() {
|
||||||
/*return string::string("woo a table of size: ") + items.size*/
|
/*return string::string("woo a table of size: ") + items.size*/
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ obj parser (Object) {
|
|||||||
// if the zero state contains any reductions for state 0 and eof, then
|
// if the zero state contains any reductions for state 0 and eof, then
|
||||||
// it must be reducing to the goal state
|
// it must be reducing to the goal state
|
||||||
println("checking the bidness")
|
println("checking the bidness")
|
||||||
if (inputStr == "" && gram.parse_table.get(0, eof_symbol()).contains(action(action_type::reduce, 0))) {
|
if (inputStr == "" && gram.parse_table.get(0, eof_symbol()).contains(action(action_type::reduce(), 0))) {
|
||||||
println("Accept on no input for ")
|
println("Accept on no input for ")
|
||||||
println(name)
|
println(name)
|
||||||
return new<tree<symbol>>()->construct(null_symbol())
|
return new<tree<symbol>>()->construct(null_symbol())
|
||||||
@@ -92,11 +92,11 @@ obj parser (Object) {
|
|||||||
gram.parse_table.get(0, input[0]).for_each(fun(act: action) {
|
gram.parse_table.get(0, input[0]).for_each(fun(act: action) {
|
||||||
println("for each action")
|
println("for each action")
|
||||||
act.print()
|
act.print()
|
||||||
if (act.act == action_type::push)
|
if (act.act == action_type::push())
|
||||||
to_shift.push(make_pair(v0, act.state_or_rule))
|
to_shift.push(make_pair(v0, act.state_or_rule))
|
||||||
/*else if (act.act == reduce && fully_reduces_to_null(gram.rules[act.state_or_rule])) {*/
|
/*else if (act.act == reduce && fully_reduces_to_null(gram.rules[act.state_or_rule])) {*/
|
||||||
else if (act.act == action_type::reduce && act.rule_position == 0) {
|
else if (act.act == action_type::reduce() && act.rule_position == 0) {
|
||||||
print("act == reduce && == 0 Adding reduction from state: ")
|
print("act == reduce() && == 0 Adding reduction from state: ")
|
||||||
println(v0->data)
|
println(v0->data)
|
||||||
to_reduce.push(reduction(v0, gram.rules[act.state_or_rule].lhs, 0, null_symbol_tree, null_symbol_tree))
|
to_reduce.push(reduction(v0, gram.rules[act.state_or_rule].lhs, 0, null_symbol_tree, null_symbol_tree))
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ obj parser (Object) {
|
|||||||
gram.parse_table.get(shift_to, input[i]).for_each(fun(act: action) {
|
gram.parse_table.get(shift_to, input[i]).for_each(fun(act: action) {
|
||||||
var reduce_rule = gram.rules[act.state_or_rule]
|
var reduce_rule = gram.rules[act.state_or_rule]
|
||||||
/*if (act.act == reduce && !fully_reduces_to_null(reduce_rule)) {*/
|
/*if (act.act == reduce && !fully_reduces_to_null(reduce_rule)) {*/
|
||||||
if (act.act == action_type::reduce && act.rule_position != 0) {
|
if (act.act == action_type::reduce() && act.rule_position != 0) {
|
||||||
to_reduce.push(reduction(curr_reached, reduce_rule.lhs,
|
to_reduce.push(reduction(curr_reached, reduce_rule.lhs,
|
||||||
act.rule_position,
|
act.rule_position,
|
||||||
get_nullable_parts(reduce_rule),
|
get_nullable_parts(reduce_rule),
|
||||||
@@ -213,7 +213,7 @@ obj parser (Object) {
|
|||||||
gss.add_to_frontier(i, shift_to_node)
|
gss.add_to_frontier(i, shift_to_node)
|
||||||
gss.add_edge(shift_to_node, curr_reached, new_label)
|
gss.add_edge(shift_to_node, curr_reached, new_label)
|
||||||
gram.parse_table.get(shift_to, input[i]).for_each(fun(act: action) {
|
gram.parse_table.get(shift_to, input[i]).for_each(fun(act: action) {
|
||||||
if (act.act == action_type::push) {
|
if (act.act == action_type::push()) {
|
||||||
to_shift.push(make_pair(shift_to_node, act.state_or_rule))
|
to_shift.push(make_pair(shift_to_node, act.state_or_rule))
|
||||||
} else {
|
} else {
|
||||||
var action_rule = gram.rules[act.state_or_rule]
|
var action_rule = gram.rules[act.state_or_rule]
|
||||||
@@ -278,7 +278,7 @@ obj parser (Object) {
|
|||||||
println("post add edger")
|
println("post add edger")
|
||||||
gram.parse_table.get(shift.second, input[i+1]).for_each(fun(action: action) {
|
gram.parse_table.get(shift.second, input[i+1]).for_each(fun(action: action) {
|
||||||
println("looking at an action")
|
println("looking at an action")
|
||||||
if (action.act == action_type::push) {
|
if (action.act == action_type::push()) {
|
||||||
println("is push")
|
println("is push")
|
||||||
next_shifts.push(make_pair(shift_to_node, action.state_or_rule))
|
next_shifts.push(make_pair(shift_to_node, action.state_or_rule))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ obj regexState (Object) {
|
|||||||
fun destruct():void {
|
fun destruct():void {
|
||||||
next_states.destruct()
|
next_states.destruct()
|
||||||
}
|
}
|
||||||
fun match(input: char): vector::vector<*regexState> {
|
fun match_char(input: char): vector::vector<*regexState> {
|
||||||
return next_states.filter(fun(it:*regexState):bool { return it->character == input; })
|
return next_states.filter(fun(it:*regexState):bool { return it->character == input; })
|
||||||
}
|
}
|
||||||
fun is_end():bool {
|
fun is_end():bool {
|
||||||
@@ -190,8 +190,8 @@ obj regex (Object, Serializable) {
|
|||||||
return longest
|
return longest
|
||||||
if (next.any_true(fun(state: *regexState):bool { return state->is_end(); }))
|
if (next.any_true(fun(state: *regexState):bool { return state->is_end(); }))
|
||||||
longest = i
|
longest = i
|
||||||
//next = next.flatten_map<*regexState>(fun(state: *regexState): vector::vector<*regexState> { return state->match(to_match[i]); })
|
//next = next.flatten_map<*regexState>(fun(state: *regexState): vector::vector<*regexState> { return state->match_char(to_match[i]); })
|
||||||
next = next.flatten_map(fun(state: *regexState): vector::vector<*regexState> { return state->match(to_match[i]); })
|
next = next.flatten_map(fun(state: *regexState): vector::vector<*regexState> { return state->match_char(to_match[i]); })
|
||||||
}
|
}
|
||||||
if (next.any_true(fun(state: *regexState):bool { return state->is_end(); }))
|
if (next.any_true(fun(state: *regexState):bool { return state->is_end(); }))
|
||||||
return to_match.length()
|
return to_match.length()
|
||||||
|
|||||||
Reference in New Issue
Block a user