#include "semcheck.h" #include /*#include */ //for CC2 it is not neccesary.I dont know why extern Vertex_Comma_list * terminals; extern Term_Comma_list * foreignclasses; extern int finalresult; /* used for checking syntax */ //set by cycle-inherit-free int Ll1SetElement_Comma_list::contain(Ll1SetElement * asymbol) { if (this->number_of_parts()==0) return 0; Ll1SetElement_list_iterator next_sym(*this); Ll1SetElement_ each_sym; while (each_sym=next_sym()) if (each_sym->g_equal(asymbol)) return 1; return 0; } void Adjacency_Nlist::FSET_CLEAR_TREATED() { Adjacency_list_iterator nextrule(*this); Adjacency_ rule; while (rule = nextrule()) rule->rset_treated(NULL); } Cd_graph *Cd_graph::FIRSTSET() { if (terminals) { Vertex_list_iterator next(*terminals); Vertex_ each; while (each = next()) { Adjacency *adj = new Adjacency(); Construct_ns *cons_n = new Construct_ns(); Ll1SetElement_Comma_list*flist= new Ll1SetElement_Comma_list(); flist->append( new Ll1SetElement(NULL,NULL, new TClassTerminal((DemIdent *)each->get_vertex_name()), NULL)); cons_n->set_construct_ns(new Any_vertex_List()); adj->set_source(each); adj->set_ns(cons_n); adj->set_firstset(flist); adjacencies->append(adj); } } adjacencies->FSET_CLEAR_TREATED(); adjacencies->FIRSTSET(); return (this); } void Adjacency_Nlist::FIRSTSET() { Adjacency_list_iterator nextrule(*this); Adjacency_ rule; while (rule = nextrule()) rule->FIRSTSET(this); } // calculate first set for receiver Ll1SetElement_Comma_list *Adjacency::FIRSTSET(Adjacency_Nlist *adj_Nlist) { if (!firstset) firstset = ns->FIRSTSET(adj_Nlist); return ((Ll1SetElement_Comma_list *)firstset->g_copy()); } Ll1SetElement_Comma_list *Neighbors::FIRSTSET(Adjacency_Nlist *adj_Nlist) { return NULL; } Ll1SetElement_Comma_list *Alternat_ns::FIRSTSET(Adjacency_Nlist *adj_Nlist) { static TEpsilon *iepsi = new TEpsilon(); static Ll1SetElement *epsill1 = new Ll1SetElement(NULL, iepsi, NULL, NULL); Ll1SetElement_Comma_list *firstsetforalts; if (this->get_construct_ns()) { Ll1SetElement_Comma_list *firstsetforcommon = this->get_construct_ns()->FIRSTSET(adj_Nlist); if (firstsetforcommon->contain(epsill1)) { firstsetforalts = alternat_ns->FIRSTSET(adj_Nlist); if (!firstsetforalts->contain(epsill1)) firstsetforcommon = firstsetforcommon->remove(epsill1); firstsetforalts = firstsetforalts->join(firstsetforcommon); } else return firstsetforcommon; } else firstsetforalts = alternat_ns->FIRSTSET(adj_Nlist); return firstsetforalts; } Ll1SetElement_Comma_list *Term_Bar_list::FIRSTSET(Adjacency_Nlist *adj_Nlist) { Ll1SetElement_Comma_list *firstsetforeach; Ll1SetElement_Comma_list *firstsetforall = new Ll1SetElement_Comma_list(); Term_list_iterator nextalt(*this); Term_ alt; while (alt = nextalt()) { firstsetforeach = alt->FIRSTSET(adj_Nlist); firstsetforall = firstsetforall->join(firstsetforeach); } return firstsetforall; } Ll1SetElement_Comma_list *Term::FIRSTSET(Adjacency_Nlist *adj_Nlist) { Ll1SetElement_Comma_list *firstsetforterm = this->get_vertex()->FIRSTSET(adj_Nlist); return (Ll1SetElement_Comma_list *)firstsetforterm->g_copy(); } Ll1SetElement_Comma_list *Vertex::FIRSTSET(Adjacency_Nlist *adj_Nlist) { Ll1SetElement_Comma_list *firstset = new Ll1SetElement_Comma_list(); Ll1SetElement * classterminal; Adjacency *idrule = adj_Nlist->LL1_FIND_RULE(this); if (idrule==NULL) { cerr << toolname << ": error: on line " << this->get_vertex_name()->get_line_number() << " undefined class: '"; this->pp(cerr); cerr << "'\n" << endl; exit(-1); } Ll1SetElement_Comma_list *id_firstset = idrule->FIRSTSET(adj_Nlist); firstset = firstset->join(id_firstset); return firstset; } Adjacency * Adjacency_Nlist::LL1_FIND_RULE(Vertex * avertex) { Adjacency_list_iterator nextrule(*this); Adjacency_ rule; while (rule = nextrule()) if (rule->get_source()->g_equal(avertex)) return rule; return NULL; } Ll1SetElement_Comma_list *Construct_ns::FIRSTSET(Adjacency_Nlist *adj_Nlist) { return this->get_construct_ns()->FIRSTSET(adj_Nlist); } Ll1SetElement_Comma_list *Any_vertex_List::FIRSTSET(Adjacency_Nlist *adj_Nlist) { static TEpsilon *iepsi = new TEpsilon(); static Ll1SetElement *epsill1 = new Ll1SetElement(NULL, iepsi, NULL, NULL); Ll1SetElement_Comma_list *firstset = new Ll1SetElement_Comma_list(); Ll1SetElement_Comma_list *part_firstset; if (this->list_length()==0) { firstset->insert(epsill1); return firstset; } Any_vertex_list_iterator nextpart(*this); Any_vertex_ part; while (part = nextpart()) { part_firstset = part->FIRSTSET(adj_Nlist); firstset = firstset->join(part_firstset); if ((!part_firstset->contain(epsill1))&& (part_firstset->number_of_parts()>0)) { firstset = firstset->remove(epsill1); break; } } if (part_firstset->number_of_parts()==0) firstset->append(epsill1); return firstset; } Ll1SetElement_Comma_list *Any_vertex::FIRSTSET(Adjacency_Nlist *adj_Nlist) { static TEpsilon *iepsi = new TEpsilon(); static Ll1SetElement *epsill1 = new Ll1SetElement(NULL, iepsi, NULL, NULL); Ll1SetElement_Comma_list *firstset = new Ll1SetElement_Comma_list(); return firstset; } Ll1SetElement_Comma_list *Regular_syntax::FIRSTSET(Adjacency_Nlist *adj_Nlist) { return this->FIRSTSET(); } Ll1SetElement_Comma_list *Opt_labeled_term::FIRSTSET(Adjacency_Nlist *adj_Nlist) { return this->get_vertex()->FIRSTSET(adj_Nlist); } Ll1SetElement_Comma_list *Optional_term::FIRSTSET(Adjacency_Nlist *adj_Nlist) { static TEpsilon *iepsi = new TEpsilon(); static Ll1SetElement *epsill1 = new Ll1SetElement(NULL, iepsi, NULL, NULL); Ll1SetElement_Comma_list *firstset = opt->FIRSTSET(adj_Nlist); if (!firstset->contain(epsill1)) firstset->insert(epsill1); return firstset; } Ll1SetElement_Comma_list *Opt_labeled_term_Sandwich::FIRSTSET(Adjacency_Nlist *adj_Nlist) { static TEpsilon *iepsi = new TEpsilon(); static Ll1SetElement *epsill1 = new Ll1SetElement(NULL, iepsi, NULL, NULL); Ll1SetElement_Comma_list *firstset; firstset = first->FIRSTSET(); if (firstset->contain(epsill1)) { firstset = inner->FIRSTSET(adj_Nlist); if (firstset->contain(epsill1)) firstset = firstset->join(second->FIRSTSET()); } return firstset; } Ll1SetElement_Comma_list *Syntax_vertex_List::FIRSTSET() { static TEpsilon *iepsi = new TEpsilon(); static Ll1SetElement *epsill1 = new Ll1SetElement(NULL, iepsi, NULL, NULL); Ll1SetElement_Comma_list *firstset = new Ll1SetElement_Comma_list(); Syntax_vertex_list_iterator next_syn(*this); Syntax_vertex_ each_syn; while (each_syn=next_syn()) if (!(firstset = each_syn->FIRSTSET())->contain(epsill1)) return firstset; firstset->insert(epsill1); return firstset; } Ll1SetElement_Comma_list *Any_vertex::FIRSTSET() { cout << "\nCan not be here Ll1SetElement_Comma_list *Syntax_vertex_List::FIRSTSET()!" << endl; exit(-1); return NULL; /* keep compiler silent */ } Ll1SetElement_Comma_list *Syntax_vertex::FIRSTSET() { static TEpsilon *iepsi = new TEpsilon(); static Ll1SetElement *epsill1 = new Ll1SetElement(NULL, iepsi, NULL, NULL); Ll1SetElement_Comma_list *firstset = new Ll1SetElement_Comma_list(); firstset->insert(epsill1); return firstset; } Ll1SetElement_Comma_list *Regular_syntax::FIRSTSET() { static int checkflag = 0; Ll1SetElement *keyword = new Ll1SetElement(string, NULL, NULL, NULL); Ll1SetElement_Comma_list *firstset = new Ll1SetElement_Comma_list(); firstset->insert(keyword); char * syntax = string->get_val(); if (syntax && (checkflag ==0)) { if (strcmp(syntax,"(@")==0) { checkflag = 1; finalresult += PAREN_ATSIGN_ERROR; cerr << toolname << ": error: on line " << string->get_line_number() << " cannot use \"(@\" as concrete syntax.\n" << endl; } else if (strcmp(syntax,"\"")==0) { checkflag = 1; finalresult += PAREN_ATSIGN_ERROR; cerr << toolname << ": error: on line " << string->get_line_number() << " cannot use \" as concrete syntax.\n" << endl; } } return firstset ; } Ll1SetElement_Comma_list *Repetit_n::FIRSTSET(Adjacency_Nlist *adj_Nlist) { return sandwiched->FIRSTSET(adj_Nlist); } Ll1SetElement_Comma_list *Kernel_Sandwich::FIRSTSET(Adjacency_Nlist *adj_Nlist) { static TEpsilon *iepsi = new TEpsilon(); static Ll1SetElement *epsill1 = new Ll1SetElement(NULL, iepsi, NULL, NULL); Ll1SetElement_Comma_list *firstset; firstset = first->FIRSTSET(); if (firstset->contain(epsill1)) { firstset = inner->FIRSTSET(adj_Nlist); if (!inner->get_nonempty()) firstset = firstset->join(second->FIRSTSET()); } return firstset; } Ll1SetElement_Comma_list *Kernel::FIRSTSET(Adjacency_Nlist *adj_Nlist) { Ll1SetElement_Comma_list *firstset; if (nonempty) firstset = nonempty->FIRSTSET(adj_Nlist); else firstset = repeated->FIRSTSET(adj_Nlist); return firstset; } Ll1SetElement_Comma_list *Term_Sandwich::FIRSTSET(Adjacency_Nlist *adj_Nlist) { static TEpsilon *iepsi = new TEpsilon(); static Ll1SetElement *epsill1 = new Ll1SetElement(NULL, iepsi, NULL, NULL); Ll1SetElement_Comma_list *firstset; firstset = first->FIRSTSET(); if (firstset->contain(epsill1)) { firstset = inner->FIRSTSET(adj_Nlist); if (firstset->contain(epsill1)) firstset = firstset->join(second->FIRSTSET()); } return firstset; }