void visit(ast::some_matcher& m) { if ( do_memo && is_lexical(m.m) ) { out << "parser::memoize_some(" << ++max_memo_id << ", "; } else { out << "parser::some("; } m.m->accept(this); out << ")"; }
// see if we have a lexical variable // move down the stack but stop before we // reach the global frame (is not included) bool has_lexical(const string& key) const { auto cur = this; while (cur->is_lexical()) { if (cur->has_local(key)) return true; cur = cur->parent_; } return false; }
// see if we have a lexical we could update // either update already existing lexical value // or if flag is set, we create one if no lexical found void set_lexical(const string& key, T val) { auto cur = this; while (cur->is_lexical()) { if (cur->has_local(key)) { cur->set_local(key, val); return; } cur = cur->parent_; } set_local(key, val); }
void Environment<T>::set_lexical(const std::string& key, T val) { auto cur = this; bool shadow = false; while (cur->is_lexical() || shadow) { if (cur->has_local(key)) { cur->set_local(key, val); return; } shadow = cur->is_shadow(); cur = cur->parent_; } set_local(key, val); }