#include "xcddraw.h" #include "lex.h" extern VertexObject *create_repetition_vertex(); extern VertexObject *create_terminal_vertex(); extern VertexObject *create_external_vertex(); extern VertexObject *create_param_vertex(); extern VertexObject *create_alternation_vertex(); extern VertexObject *create_construction_vertex(); extern "C" { extern token_kind yylex(); extern char yytext[YYLMAX]; extern int yylineno; extern int yyleng; extern FILE *yyin; extern FILE *yyout; } int fatal_parsing_error(char *m) { xm_print_message(m); XBell(XtDisplay(draw_area),0); return 0; } void ConstructionVertexStore::freeStore() { tempstore->freeStore(); } void AlternationVertexStore::freeStore() { tempstore->freeStore(); } void RepetitionVertexStore::freeStore() { tempstore->freeStore(); } void TerminalVertexStore::freeStore() { vstore->freeStore(); } void ParameterVertexStore::freeStore() { vstore->freeStore(); } void ExternalVertexStore::freeStore() { tempstore->freeStore(); } void UnboundVertexStore::freeStore() { vstore->freeStore(); } void NameSensitiveVertexStore::freeStore() { if (vertices) { vertices->freeStore(); delete vertices; vertices = NULL; } } void NameInsensitiveVertexStore::freeStore() { if (vertices) { vertices->freeStore(); delete vertices->get_objects(); vertices->set_objects(NULL); } } void NameSensitiveVertexList::freeStore() { elm->freeStore(); delete elm; elm = NULL; if (next) next->freeStore(); } void TemplateInstStore::freeStore() { instances->freeStore(); if (instances->get_objects()) delete instances->get_objects(); instances->set_objects(NULL); delete instances; } void NameSensitiveVertex::freeStore() { delete vertex_name; vertices->freeStore(); delete vertices; tempinststore->freeStore(); delete tempinststore; tempinststore = NULL; if (before) free(before); if (after) free(after); delete comments; if (outgoing_consedge_store->get_objects()) delete outgoing_consedge_store->get_objects(); outgoing_consedge_store->set_objects(NULL); if (outgoing_paredge_store->get_objects()) delete outgoing_paredge_store->get_objects(); outgoing_paredge_store->set_objects(NULL); } void VertexStore::freeStore() { localvertices->set_vertices(NULL); consvstore->freeStore(); altvstore->freeStore(); repvstore->freeStore(); termvstore->freeStore(); paravstore->freeStore(); extvstore->freeStore(); ubvstore->freeStore(); } void GraphicsObject::freeStore() { } void VertexObject::freeStore() { } void ConstructionVertex::freeStore() { } void ParameterVertex::freeStore() { delete this->get_name(); } void TerminalVertex::freeStore() { delete this->get_name(); } void GraphicsObjectList::freeStore() { delete elm; if (next) { next->freeStore(); } elm = NULL; } void ObjectStore::freeStore() { if (objects) { objects->freeStore(); delete objects; } objects = NULL; } void freeStore() { drawing_vertex = NULL; drawing_edge = NULL; selected_object = NULL; vertex_store->freeStore(); consedge_store->freeStore(); repedge_store->freeStore(); altedge_store->freeStore(); inhedge_store->freeStore(); paredge_store->freeStore(); parinstedge_store->freeStore(); } void GraphicsObject::fillinPE(ParameterEdge *e) { } void ParameterAssignmentList::fillinPE(ParameterEdge *e) { if (elm->get_formaledge()==NULL) elm->set_formaledge(e); else if (next) next->fillinPE(e); else { next = new ParameterAssignmentList(); next->set_elm(new ParameterAssignment()); next->set_prev(this); next->get_elm()->set_formaledge(e); } } void ParameterAssignmentStore::fillinPE(ParameterEdge *e) { if (assignments) assignments->fillinPE(e); else { assignments = new ParameterAssignmentList(); assignments->set_elm(new ParameterAssignment()); assignments->get_elm()->set_formaledge(e); } } void VertexObject::fillinPE(ParameterEdge *e) { parassignstore->fillinPE(e); } void GraphicsObjectList::fillinPE(ParameterEdge *e) { elm->fillinPE(e); if (next) next->fillinPE(e); } void ObjectStore::fillinPE(ParameterEdge *e) { if (objects) objects->fillinPE(e); } void TemplateInstStore::fillinPE(ParameterEdge *e) { instances->fillinPE(e); } void NameSensitiveVertex::fillinPE(ParameterEdge *e) { vertices->fillinPE(e); tempinststore->fillinPE(e); } void GraphicsObjectList::getEndVertex(long tid,VertexObject *&rv) { if (elm->get_id() == tid) rv = (VertexObject *)elm; else if (next) next->getEndVertex(tid,rv); } VertexObject *ObjectStore::getEndVertex(long tid,token_kind tk) { VertexObject *rv = NULL; if (objects) objects->getEndVertex(tid,rv); return rv; } VertexObject *NameInsensitiveVertexStore::getEndVertex(long tid,token_kind tk) { return vertices->getEndVertex(tid,tk); } VertexObject* TemplateInstStore::getEndVertex(long tid,token_kind tk) { return instances->getEndVertex(tid,tk); } void NameSensitiveVertex::getEndVertex(long tid,token_kind tk,VertexObject*&rv) { if (tk == CVI || tk == AVI || tk == RVI || tk == EVI) rv = tempinststore->getEndVertex(tid,tk); else rv = vertices->getEndVertex(tid,tk); } void NameSensitiveVertexList::getEndVertex(long tid,token_kind tk,VertexObject*&rv) { elm->getEndVertex(tid,tk,rv); if (rv) return; else if (next) next->getEndVertex(tid,tk,rv); } VertexObject * NameSensitiveVertexStore::getEndVertex(long tid,token_kind tk) { VertexObject *rv = NULL; if (vertices) vertices->getEndVertex(tid,tk,rv); return rv; } VertexObject *ConstructionVertexStore::getEndVertex(long tid,token_kind tk) { return tempstore->getEndVertex(tid,tk); } VertexObject *AlternationVertexStore::getEndVertex(long tid,token_kind tk) { return tempstore->getEndVertex(tid,tk); } VertexObject *RepetitionVertexStore::getEndVertex(long tid,token_kind tk) { return tempstore->getEndVertex(tid,tk); } VertexObject *ExternalVertexStore::getEndVertex(long tid,token_kind tk) { return tempstore->getEndVertex(tid,tk); } VertexObject *TerminalVertexStore::getEndVertex(long tid,token_kind tk) { return vstore->getEndVertex(tid,tk); } VertexObject *ParameterVertexStore::getEndVertex(long tid,token_kind tk) { return vstore->getEndVertex(tid,tk); } VertexObject *VertexStore::getEndVertex(long tid,token_kind tk) { switch (tk) { case CV: case CVI: return consvstore->getEndVertex(tid,tk); case AV: case AVI: return altvstore->getEndVertex(tid,tk); case RV: case RVI: return repvstore->getEndVertex(tid,tk); case TV: return termvstore->getEndVertex(tid,tk); case PV: return paravstore->getEndVertex(tid,tk); case EV: case EVI: return extvstore->getEndVertex(tid,tk); default: return NULL; } } int get_CARVertexInfo(long &id, char *&vn,int &nx,int &ny,int &bx, int &by, char *&vcomments, char*&bsyntax, char*&asyntax) { token_kind k; /* get id */ if (yylex() == NUMBER) id = atol(yytext); else return fatal_parsing_error("vertex id expected"); /* get name */ if (yylex() == NAME) { vn = new char[yyleng - 1]; strncpy(vn,yytext+1,yyleng-2); vn[yyleng-2] = '\0'; } else return fatal_parsing_error("vertex name exptected"); /* get x,y for name */ if (yylex() == NUMBER) nx = atoi(yytext); else return fatal_parsing_error("name's x-coordinate expected"); if (yylex() == NUMBER) ny = atoi(yytext); else return fatal_parsing_error("name's y-coordinate expected"); /* get x,y for box */ if (yylex() == NUMBER) bx = atoi(yytext); else return fatal_parsing_error("box' x-coordinate expected"); if (yylex() == NUMBER) by = atoi(yytext); else return fatal_parsing_error("box' y-coordinate expected"); if (yylex() == PC) { int clen; if (yylex() == NUMBER) clen = atoi(yytext); else return fatal_parsing_error("vertex' comment length expected"); vcomments = new char[clen +1]; int ci = 0; while ((k = yylex()) == TEXT) { sprintf(vcomments+ci,"%s\n",yytext+3); ci += yyleng - 2; } if (k != PC) return fatal_parsing_error("end of comments expected"); vcomments[ci] = '\0'; } else return fatal_parsing_error("vertex' comments expected"); if (yylex() == PB) { int blen; if (yylex() == NUMBER) blen = atoi(yytext); else return fatal_parsing_error("before comment length expected"); bsyntax = new char[blen +1]; int bi = 0; while ((k = yylex()) == TEXT) { sprintf(bsyntax+bi,"%s\n",yytext+3); bi += yyleng - 2; } if (k != PB) return fatal_parsing_error("end of comments expected"); bsyntax[bi] = '\0'; } else return fatal_parsing_error("vertex' before comments expected"); if (yylex() == PA) { int alen; if (yylex() == NUMBER) alen = atoi(yytext); else return fatal_parsing_error("after comment length expected"); asyntax = new char[alen +1]; int ai = 0; while ((k = yylex()) == TEXT) { sprintf(asyntax+ai,"%s\n",yytext+3); ai += yyleng - 2; } if (k != PA) return fatal_parsing_error("end of comments expected"); asyntax[ai] = '\0'; } else return fatal_parsing_error("vertex' after comments expected"); return 1; } int get_PETVertexInfo(long &id, char *&vn,int &nx,int &ny,int &bx, int &by, char *&vcomments) { token_kind k; /* get id */ if (yylex() == NUMBER) id = atol(yytext); else return fatal_parsing_error("vertex id expected"); /* get name */ if (yylex() == NAME) { vn = new char[yyleng - 1]; strncpy(vn,yytext+1,yyleng - 2); vn[yyleng-2] = '\0'; } else return fatal_parsing_error("vertex name exptected"); /* get x,y for name */ if (yylex() == NUMBER) nx = atoi(yytext); else return fatal_parsing_error("name's x-coordinate expected"); if (yylex() == NUMBER) ny = atoi(yytext); else return fatal_parsing_error("name's y-coordinate expected"); /* get x,y for box */ if (yylex() == NUMBER) bx = atoi(yytext); else return fatal_parsing_error("box' x-coordinate expected"); if (yylex() == NUMBER) by = atoi(yytext); else return fatal_parsing_error("box' y-coordinate expected"); if (yylex() == PC) { int clen; if (yylex() == NUMBER) clen = atoi(yytext); else return fatal_parsing_error("vertex' comment length expected"); vcomments = new char[clen +1]; int ci = 0; while ((k = yylex()) == TEXT) { sprintf(vcomments+ci,"%s\n",yytext+3); ci += yyleng - 2; } if (k != PC) return fatal_parsing_error("end of comments expected"); vcomments[ci] = '\0'; } else return fatal_parsing_error("vertex' comments expected"); return 1; } int isLegalEndVertexKind(token_kind k) { return ( k == CV || k == AV || k == EV || k == RV || k == TV || k == PV || k == CVI || k == AVI || k == EVI || k == RVI); } int readPS(FILE *fp) { enum token_kind k; yyout = fopen("/dev/null","w"); yyin = fp; VertexObject *current_primary; NameSensitiveVertex *current_subhome; while (k = yylex()) { switch(k) { case PCV: { long id; char *vn = NULL; int nx = 0; int ny = 0; int bx = 0; int by = 0; char *vcomments = NULL; char *bsyntax = NULL; char *asyntax = NULL; if (get_CARVertexInfo(id,vn,nx,ny,bx,by,vcomments,bsyntax,asyntax)) { current_primary = create_construction_vertex(); current_primary->set_xy(bx,by); current_primary->set_name(vn,nx,ny); current_primary->set_id(id); vertex_store->append(current_primary); current_subhome = current_primary->get_subhome(); current_subhome->get_comments()->set_comments(vcomments); current_subhome->set_before(bsyntax); current_subhome->set_after(asyntax); } else { freeStore(); return 0; } break; } case PAV: { long id; char *vn = NULL; int nx = 0; int ny = 0; int bx = 0; int by = 0; char *vcomments = NULL; char *bsyntax = NULL; char *asyntax = NULL; if (get_CARVertexInfo(id,vn,nx,ny,bx,by,vcomments,bsyntax,asyntax)) { current_primary = create_alternation_vertex(); current_primary->set_xy(bx,by); current_primary->set_name(vn,nx,ny); current_primary->set_id(id); vertex_store->append(current_primary); current_subhome = current_primary->get_subhome(); current_subhome->get_comments()->set_comments(vcomments); current_subhome->set_before(bsyntax); current_subhome->set_after(asyntax); } else { freeStore(); return 0; } break; } case PRV: { long id; char *vn = NULL; int nx = 0; int ny = 0; int bx = 0; int by = 0; char *vcomments = NULL; char *bsyntax = NULL; char *asyntax = NULL; if (get_CARVertexInfo(id,vn,nx,ny,bx,by,vcomments,bsyntax,asyntax)) { current_primary = create_repetition_vertex(); current_primary->set_xy(bx,by); current_primary->set_name(vn,nx,ny); current_primary->set_id(id); vertex_store->append(current_primary); current_subhome = current_primary->get_subhome(); current_subhome->get_comments()->set_comments(vcomments); current_subhome->set_before(bsyntax); current_subhome->set_after(asyntax); } else { freeStore(); return 0; } break; } case PTV: { long id; char *vn = NULL; int nx = 0; int ny = 0; int bx = 0; int by = 0; char *vcomments = NULL; if (get_PETVertexInfo(id,vn,nx,ny,bx,by,vcomments)) { current_primary = create_terminal_vertex(); current_primary->set_xy(bx,by); current_primary->set_name(vn,nx,ny); current_primary->set_id(id); vertex_store->append(current_primary); ((TerminalVertex*)current_primary) ->get_comments()->set_comments(vcomments); } else { freeStore(); return 0; } break; } case PEV: { long id; char *vn = NULL; int nx = 0; int ny = 0; int bx = 0; int by = 0; char *vcomments = NULL; if (get_PETVertexInfo(id,vn,nx,ny,bx,by,vcomments)) { current_primary = create_external_vertex(); current_primary->set_xy(bx,by); current_primary->set_name(vn,nx,ny); current_primary->set_id(id); vertex_store->append(current_primary); current_subhome = current_primary->get_subhome(); current_subhome->get_comments()->set_comments(vcomments); } else { freeStore(); return 0; } break; } case PPV: { long id; char *vn = NULL; int nx = 0; int ny = 0; int bx = 0; int by = 0; char *vcomments = NULL; if (get_PETVertexInfo(id,vn,nx,ny,bx,by,vcomments)) { current_primary = create_param_vertex(); current_primary->set_xy(bx,by); current_primary->set_name(vn,nx,ny); current_primary->set_id(id); vertex_store->append(current_primary); ((ParameterVertex*)current_primary)-> get_comments()->set_comments(vcomments); } else { freeStore(); return 0; } break; } case PSV: { long id; int nx,ny,bx,by; if (yylex()!=NUMBER) { return fatal_parsing_error("vertex' id expected"); } else { id = atol(yytext); } /* get x,y for name */ if (yylex() == NUMBER) nx = atoi(yytext); else return fatal_parsing_error("name's x-coordinate expected"); if (yylex() == NUMBER) ny = atoi(yytext); else return fatal_parsing_error("name's y-coordinate expected"); /* get x,y for box */ if (yylex() == NUMBER) bx = atoi(yytext); else return fatal_parsing_error("box' x-coordinate expected"); if (yylex() == NUMBER) by = atoi(yytext); else return fatal_parsing_error("box' y-coordinate expected"); if (current_primary) { VertexObject *sv; switch(current_primary->get_kind()) { case CONS_VERTEX: sv = create_construction_vertex(); break; case ALT_VERTEX: sv = create_alternation_vertex(); break; case REP_VERTEX: sv = create_repetition_vertex(); break; case EXT_VERTEX: sv = create_external_vertex(); break; default: { return fatal_parsing_error("fatal system error"); } } sv->set_primary_flag(NONPRIMARY); current_primary->set_primary_flag(PRIMARY_OF); sv->set_xy(bx,by); sv->set_name_x(nx); sv->set_name_y(ny); sv->set_id(id); sv->set_name(current_primary->get_name()); sv->set_subhome(current_primary->get_subhome()); sv->set_home(current_primary->get_home()); sv->set_is_template(1); delete sv->get_parassignstore(); sv->set_parassignstore(current_primary->get_parassignstore()); current_primary->get_home()->append(sv); } else { return fatal_parsing_error("wrong file format"); } break; } case PIV: { long id; int nx,ny,bx,by; if (yylex()!=NUMBER) { return fatal_parsing_error("vertex' id expected"); } else { id = atol(yytext); } /* get x,y for name */ if (yylex() == NUMBER) nx = atoi(yytext); else return fatal_parsing_error("name's x-coordinate expected"); if (yylex() == NUMBER) ny = atoi(yytext); else return fatal_parsing_error("name's y-coordinate expected"); /* get x,y for box */ if (yylex() == NUMBER) bx = atoi(yytext); else return fatal_parsing_error("box' x-coordinate expected"); if (yylex() == NUMBER) by = atoi(yytext); else return fatal_parsing_error("box' y-coordinate expected"); if (current_primary) { VertexObject *sv; switch(current_primary->get_kind()) { case CONS_VERTEX: sv = create_construction_vertex(); break; case ALT_VERTEX: sv = create_alternation_vertex(); break; case REP_VERTEX: sv = create_repetition_vertex(); break; case EXT_VERTEX: sv = create_external_vertex(); break; default: { return fatal_parsing_error("fatal system error"); } } sv->set_primary_flag(UNCLASSICFIED); sv->set_xy(bx,by); sv->set_name_x(nx); sv->set_name_y(ny); sv->set_id(id); sv->set_template_name(current_primary->get_name()); sv->set_home( current_primary->get_subhome() ->get_tempinststore()->get_instances()); sv->set_subhome(current_primary->get_subhome()); sv->set_is_template(0); current_primary->get_subhome() ->get_tempinststore()->append(sv); while (((k = yylex())!= PEAS) && (k != 0)) { if (k == PAS) { if (yylex()== NAME) { ParameterAssignment *na = new ParameterAssignment(); int vl = strlen(yytext)-2; if (vl) { char *nv = new char[vl+1]; strncpy(nv,yytext+1,vl); nv[vl] = '\0'; na->set_actual_val(nv); } k = yylex(); if (k == RO) na->set_flag(READONLY); else if (k == RW) na->set_flag(READWRITE); else return fatal_parsing_error( "read/write flag expected"); sv->get_parassignstore()->append_parassign(na); } else return fatal_parsing_error( "value for parameter expected"); } } if (k == 0) return fatal_parsing_error( "unexpected end of file"); } else { return fatal_parsing_error("wrong file format"); } break; } case PUC: { long id; int bx,by; if (yylex()!=NUMBER) { return fatal_parsing_error("vertex' id expected"); } else { id = atol(yytext); } /* get x,y for box */ if (yylex() == NUMBER) bx = atoi(yytext); else return fatal_parsing_error("box' x-coordinate expected"); if (yylex() == NUMBER) by = atoi(yytext); else return fatal_parsing_error("box' y-coordinate expected"); VertexObject *sv; sv = create_construction_vertex(); sv->set_primary_flag(UNKNOWN); sv->set_xy(bx,by); sv->set_name_x(0); sv->set_name_y(0); sv->set_id(id); sv->set_is_template(0); vertex_store->append(sv); break; } case PUA: { long id; int bx,by; if (yylex()!=NUMBER) { return fatal_parsing_error("vertex' id expected"); } else { id = atol(yytext); } /* get x,y for box */ if (yylex() == NUMBER) bx = atoi(yytext); else return fatal_parsing_error("box' x-coordinate expected"); if (yylex() == NUMBER) by = atoi(yytext); else return fatal_parsing_error("box' y-coordinate expected"); VertexObject *sv; sv = create_alternation_vertex(); sv->set_primary_flag(UNKNOWN); sv->set_xy(bx,by); sv->set_name_x(0); sv->set_name_y(0); sv->set_id(id); sv->set_is_template(0); vertex_store->append(sv); break; } case PUR: { long id; int bx,by; if (yylex()!=NUMBER) { return fatal_parsing_error("vertex' id expected"); } else { id = atol(yytext); } /* get x,y for box */ if (yylex() == NUMBER) bx = atoi(yytext); else return fatal_parsing_error("box' x-coordinate expected"); if (yylex() == NUMBER) by = atoi(yytext); else return fatal_parsing_error("box' y-coordinate expected"); VertexObject *sv; sv = create_repetition_vertex(); sv->set_primary_flag(UNKNOWN); sv->set_xy(bx,by); sv->set_name_x(0); sv->set_name_y(0); sv->set_id(id); sv->set_is_template(0); vertex_store->append(sv); break; } case PUE: { long id; int bx,by; if (yylex()!=NUMBER) { return fatal_parsing_error("vertex' id expected"); } else { id = atol(yytext); } /* get x,y for box */ if (yylex() == NUMBER) bx = atoi(yytext); else return fatal_parsing_error("box' x-coordinate expected"); if (yylex() == NUMBER) by = atoi(yytext); else return fatal_parsing_error("box' y-coordinate expected"); VertexObject *sv; sv = create_external_vertex(); sv->set_primary_flag(UNKNOWN); sv->set_xy(bx,by); sv->set_name_x(0); sv->set_name_y(0); sv->set_id(id); sv->set_is_template(0); vertex_store->append(sv); break; } case PPE: { /* parameter edge : instantiation edges are read first */ token_kind sk, tk; long sid,tid; if (!isLegalEndVertexKind(sk = yylex())) return fatal_parsing_error( "start vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "start vertex id expected"); sid = atol(yytext); if (!isLegalEndVertexKind(tk = yylex())) return fatal_parsing_error( "end vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "end vertex id expected"); tid = atol(yytext); if (yylex() != LBR) return fatal_parsing_error("\"[\" expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "number of points expected"); int npts = atoi(yytext)+1; PointObjectList *pts = NULL; PointObjectList *curpts; while (npts) { if (pts==NULL) { pts = new PointObjectList(); curpts = pts; } else { curpts->set_next(new PointObjectList()); curpts->get_next()->set_prev(curpts); curpts = curpts->get_next(); } curpts->set_elm(new PointObject()); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's x expected"); curpts->get_elm()->set_x(atoi(yytext)); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's y id expected"); curpts->get_elm()->set_y(atoi(yytext)); npts--; } if (yylex() != RBR) return fatal_parsing_error( "\"]\" expected"); if (yylex() != PC) return fatal_parsing_error("edge's comments expected"); int clen; if (yylex() != NUMBER) return fatal_parsing_error("comment length expected"); clen = atoi(yytext); char *comments = new char[clen +1]; int ci = 0; while ((k = yylex()) == TEXT) { sprintf(comments+ci,"%s\n",yytext+3); ci += yyleng - 2; } if (k != PC) return fatal_parsing_error("end of comments expected"); comments[ci] = '\0'; VertexObject *sv = vertex_store->getEndVertex(sid,sk); if (sv==NULL) { return fatal_parsing_error( "file corrupted"); } VertexObject *tv = vertex_store->getEndVertex(tid,tk); if (tv==NULL) { return fatal_parsing_error( "file corrupted"); } ParameterEdge *e = new ParameterEdge(); e->get_comments()->set_comments(comments); e->set_from_vertex(sv); e->set_to_vertex(tv); e->set_points(pts); tv->get_incoming_paredge_store()->append(e); sv->get_outgoing_paredge_store()->append(e); paredge_store->append(e); sv->get_subhome()->fillinPE(e); break; } case PRCE: { /* required construction edge */ token_kind sk, tk; int ex,ey; long sid,tid; char *asyntax,*bsyntax,*el; if (!isLegalEndVertexKind(sk = yylex())) return fatal_parsing_error( "start vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "start vertex id expected"); sid = atol(yytext); if (!isLegalEndVertexKind(tk = yylex())) return fatal_parsing_error( "end vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "end vertex id expected"); tid = atol(yytext); if (yylex() != LBR) return fatal_parsing_error("\"[\" expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "number of points expected"); int npts = atoi(yytext)+1; PointObjectList *pts = NULL; PointObjectList *curpts; while (npts) { if (pts==NULL) { pts = new PointObjectList(); curpts = pts; } else { curpts->set_next(new PointObjectList()); curpts->get_next()->set_prev(curpts); curpts = curpts->get_next(); } curpts->set_elm(new PointObject()); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's x expected"); curpts->get_elm()->set_x(atoi(yytext)); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's y id expected"); curpts->get_elm()->set_y(atoi(yytext)); npts--; } if (yylex() != RBR) return fatal_parsing_error( "\"]\" expected"); if (yylex() != PEL) return fatal_parsing_error("edge label expected"); if (yylex() == NAME) { el = new char[yyleng - 1]; strncpy(el,yytext+1,yyleng-2); el[yyleng-2] = '\0'; } else return fatal_parsing_error("vertex name exptected"); if (yylex() != NUMBER) return fatal_parsing_error("edge label's x expected"); ex = atoi(yytext); if (yylex() != NUMBER) return fatal_parsing_error("edge label's y expected"); ey = atoi(yytext); if (yylex() != PC) return fatal_parsing_error("edge's comments expected"); int clen; if (yylex() != NUMBER) return fatal_parsing_error("comment length expected"); clen = atoi(yytext); char *comments = new char[clen +1]; int ci = 0; while ((k = yylex()) == TEXT) { sprintf(comments+ci,"%s\n",yytext+3); ci += yyleng - 2; } if (k != PC) return fatal_parsing_error("end of comments expected"); comments[ci] = '\0'; if (yylex() == PB) { int blen; if (yylex() == NUMBER) blen = atoi(yytext); else return fatal_parsing_error("before comment length expected"); bsyntax = new char[blen +1]; int bi = 0; while ((k = yylex()) == TEXT) { sprintf(bsyntax+bi,"%s\n",yytext+3); bi += yyleng - 2; } if (k != PB) return fatal_parsing_error("end of comments expected"); bsyntax[bi] = '\0'; } else return fatal_parsing_error("vertex' before comments expected"); if (yylex() == PA) { int alen; if (yylex() == NUMBER) alen = atoi(yytext); else return fatal_parsing_error("after comment length expected"); asyntax = new char[alen +1]; int ai = 0; while ((k = yylex()) == TEXT) { sprintf(asyntax+ai,"%s\n",yytext+3); ai += yyleng - 2; } if (k != PA) return fatal_parsing_error("end of comments expected"); asyntax[ai] = '\0'; } else return fatal_parsing_error("edge's after comments expected"); VertexObject *sv = vertex_store->getEndVertex(sid,sk); if (sv==NULL) { return fatal_parsing_error( "file corrupted"); } VertexObject *tv = vertex_store->getEndVertex(tid,tk); if (tv==NULL) { return fatal_parsing_error( "file corrupted"); } ReqConstructionEdge *e = new ReqConstructionEdge(); e->get_comments()->set_comments(comments); e->get_edge_label()->set_val(el); e->get_edge_label()->set_x(ex); e->get_edge_label()->set_y(ey); e->set_before(bsyntax); e->set_after(asyntax); e->set_from_vertex(sv); e->set_to_vertex(tv); e->set_points(pts); tv->get_incoming_consedge_store()->append(e); sv->get_outgoing_consedge_store()->append(e); consedge_store->append(e); sv->get_subhome()->get_outgoing_consedge_store()->append(e); break; } case POCE: { /* optional construction edge */ token_kind sk, tk; int ex,ey; long sid,tid; char *asyntax,*bsyntax,*ibsyntax,*iasyntax,*el; if (!isLegalEndVertexKind(sk = yylex())) return fatal_parsing_error( "start vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "start vertex id expected"); sid = atol(yytext); if (!isLegalEndVertexKind(tk = yylex())) return fatal_parsing_error( "end vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "end vertex id expected"); tid = atol(yytext); if (yylex() != LBR) return fatal_parsing_error("\"[\" expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "number of points expected"); int npts = atoi(yytext)+1; PointObjectList *pts = NULL; PointObjectList *curpts; while (npts) { if (pts==NULL) { pts = new PointObjectList(); curpts = pts; } else { curpts->set_next(new PointObjectList()); curpts->get_next()->set_prev(curpts); curpts = curpts->get_next(); } curpts->set_elm(new PointObject()); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's x expected"); curpts->get_elm()->set_x(atoi(yytext)); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's y id expected"); curpts->get_elm()->set_y(atoi(yytext)); npts--; } if (yylex() != RBR) return fatal_parsing_error( "\"]\" expected"); if (yylex() != PEL) return fatal_parsing_error("edge label expected"); if (yylex() == NAME) { el = new char[yyleng - 1]; strncpy(el,yytext+1,yyleng-2); el[yyleng-2] = '\0'; } else return fatal_parsing_error("vertex name exptected"); if (yylex() != NUMBER) return fatal_parsing_error("edge label's x expected"); ex = atoi(yytext); if (yylex() != NUMBER) return fatal_parsing_error("edge label's y expected"); ey = atoi(yytext); if (yylex() != PC) return fatal_parsing_error("edge's comments expected"); int clen; if (yylex() != NUMBER) return fatal_parsing_error("comment length expected"); clen = atoi(yytext); char *comments = new char[clen +1]; int ci = 0; while ((k = yylex()) == TEXT) { sprintf(comments+ci,"%s\n",yytext+3); ci += yyleng - 2; } if (k != PC) return fatal_parsing_error("end of comments expected"); comments[ci] = '\0'; if (yylex() == PB) { int blen; if (yylex() == NUMBER) blen = atoi(yytext); else return fatal_parsing_error("before comment length expected"); bsyntax = new char[blen +1]; int bi = 0; while ((k = yylex()) == TEXT) { sprintf(bsyntax+bi,"%s\n",yytext+3); bi += yyleng - 2; } if (k != PB) return fatal_parsing_error("end of comments expected"); bsyntax[bi] = '\0'; } else return fatal_parsing_error("vertex' before comments expected"); if (yylex() == PA) { int alen; if (yylex() == NUMBER) alen = atoi(yytext); else return fatal_parsing_error("after comment length expected"); asyntax = new char[alen +1]; int ai = 0; while ((k = yylex()) == TEXT) { sprintf(asyntax+ai,"%s\n",yytext+3); ai += yyleng - 2; } if (k != PA) return fatal_parsing_error("end of comments expected"); asyntax[ai] = '\0'; } else return fatal_parsing_error("edge's after comments expected"); if (yylex() == PIB) { int iblen; if (yylex() == NUMBER) iblen = atoi(yytext); else return fatal_parsing_error("before comment length expected"); ibsyntax = new char[iblen +1]; int ibi = 0; while ((k = yylex()) == TEXT) { sprintf(ibsyntax+ibi,"%s\n",yytext+3); ibi += yyleng - 2; } if (k != PIB) return fatal_parsing_error("end of comments expected"); ibsyntax[ibi] = '\0'; } else return fatal_parsing_error("vertex' before comments expected"); if (yylex() == PIA) { int ialen; if (yylex() == NUMBER) ialen = atoi(yytext); else return fatal_parsing_error("after comment length expected"); iasyntax = new char[ialen +1]; int iai = 0; while ((k = yylex()) == TEXT) { sprintf(iasyntax+iai,"%s\n",yytext+3); iai += yyleng - 2; } if (k != PIA) return fatal_parsing_error("end of comments expected"); iasyntax[iai] = '\0'; } else return fatal_parsing_error("vertex' before comments expected"); VertexObject *sv = vertex_store->getEndVertex(sid,sk); if (sv==NULL) { return fatal_parsing_error( "file corrupted"); } VertexObject *tv = vertex_store->getEndVertex(tid,tk); if (tv==NULL) { return fatal_parsing_error( "file corrupted"); } OptConstructionEdge *e = new OptConstructionEdge(); e->get_comments()->set_comments(comments); e->get_edge_label()->set_val(el); e->get_edge_label()->set_x(ex); e->get_edge_label()->set_y(ey); e->set_before(bsyntax); e->set_after(asyntax); e->set_inbefore(ibsyntax); e->set_inafter(iasyntax); e->set_from_vertex(sv); e->set_to_vertex(tv); e->set_points(pts); tv->get_incoming_consedge_store()->append(e); sv->get_outgoing_consedge_store()->append(e); consedge_store->append(e); sv->get_subhome()->get_outgoing_consedge_store()->append(e); break; } case PRRE: { /* required repetition edge */ token_kind sk, tk; long sid,tid; if (!isLegalEndVertexKind(sk = yylex())) return fatal_parsing_error( "start vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "start vertex id expected"); sid = atol(yytext); if (!isLegalEndVertexKind(tk = yylex())) return fatal_parsing_error( "end vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "end vertex id expected"); tid = atol(yytext); if (yylex() != LBR) return fatal_parsing_error("\"[\" expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "number of points expected"); int npts = atoi(yytext)+1; PointObjectList *pts = NULL; PointObjectList *curpts; while (npts) { if (pts==NULL) { pts = new PointObjectList(); curpts = pts; } else { curpts->set_next(new PointObjectList()); curpts->get_next()->set_prev(curpts); curpts = curpts->get_next(); } curpts->set_elm(new PointObject()); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's x expected"); curpts->get_elm()->set_x(atoi(yytext)); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's y id expected"); curpts->get_elm()->set_y(atoi(yytext)); npts--; } if (yylex() != RBR) return fatal_parsing_error( "\"]\" expected"); if (yylex() != PC) return fatal_parsing_error("edge's comments expected"); int clen; if (yylex() != NUMBER) return fatal_parsing_error("comment length expected"); clen = atoi(yytext); char *comments = new char[clen +1]; int ci = 0; while ((k = yylex()) == TEXT) { sprintf(comments+ci,"%s\n",yytext+3); ci += yyleng - 2; } if (k != PC) return fatal_parsing_error("end of comments expected"); comments[ci] = '\0'; char *asyntax,*bsyntax,*osyntax; if (yylex() == PB) { int blen; if (yylex() == NUMBER) blen = atoi(yytext); else return fatal_parsing_error("before comment length expected"); bsyntax = new char[blen +1]; int bi = 0; while ((k = yylex()) == TEXT) { sprintf(bsyntax+bi,"%s\n",yytext+3); bi += yyleng - 2; } if (k != PB) return fatal_parsing_error("end of comments expected"); bsyntax[bi] = '\0'; } else return fatal_parsing_error("vertex' before comments expected"); if (yylex() == PA) { int alen; if (yylex() == NUMBER) alen = atoi(yytext); else return fatal_parsing_error("after comment length expected"); asyntax = new char[alen +1]; int ai = 0; while ((k = yylex()) == TEXT) { sprintf(asyntax+ai,"%s\n",yytext+3); ai += yyleng - 2; } if (k != PA) return fatal_parsing_error("end of comments expected"); asyntax[ai] = '\0'; } else return fatal_parsing_error("edge's after comments expected"); if (yylex() == POB) { int olen; if (yylex() == NUMBER) olen = atoi(yytext); else return fatal_parsing_error("before comment length expected"); osyntax = new char[olen +1]; int oi = 0; while ((k = yylex()) == TEXT) { sprintf(osyntax+oi,"%s\n",yytext+3); oi += yyleng - 2; } if (k != POB) return fatal_parsing_error("end of comments expected"); osyntax[oi] = '\0'; } else return fatal_parsing_error("vertex' before comments expected"); VertexObject *sv = vertex_store->getEndVertex(sid,sk); if (sv==NULL) { return fatal_parsing_error( "file corrupted"); } VertexObject *tv = vertex_store->getEndVertex(tid,tk); if (tv==NULL) { return fatal_parsing_error( "file corrupted"); } ReqRepetitionEdge *e = new ReqRepetitionEdge(); e->get_comments()->set_comments(comments); e->set_before(bsyntax); e->set_after(asyntax); e->set_outbefore(NULL); if (osyntax) free(osyntax); e->set_from_vertex(sv); e->set_to_vertex(tv); e->set_points(pts); tv->get_incoming_repedge_store()->append(e); sv->get_outgoing_repedge_store()->append(e); repedge_store->append(e); break; } case PORE: { /* optional repetition edge */ token_kind sk, tk; long sid,tid; if (!isLegalEndVertexKind(sk = yylex())) return fatal_parsing_error( "start vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "start vertex id expected"); sid = atol(yytext); if (!isLegalEndVertexKind(tk = yylex())) return fatal_parsing_error( "end vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "end vertex id expected"); tid = atol(yytext); if (yylex() != LBR) return fatal_parsing_error("\"[\" expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "number of points expected"); int npts = atoi(yytext)+1; PointObjectList *pts = NULL; PointObjectList *curpts; while (npts) { if (pts==NULL) { pts = new PointObjectList(); curpts = pts; } else { curpts->set_next(new PointObjectList()); curpts->get_next()->set_prev(curpts); curpts = curpts->get_next(); } curpts->set_elm(new PointObject()); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's x expected"); curpts->get_elm()->set_x(atoi(yytext)); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's y id expected"); curpts->get_elm()->set_y(atoi(yytext)); npts--; } if (yylex() != RBR) return fatal_parsing_error( "\"]\" expected"); if (yylex() != PC) return fatal_parsing_error("edge's comments expected"); int clen; if (yylex() != NUMBER) return fatal_parsing_error("comment length expected"); clen = atoi(yytext); char *comments = new char[clen +1]; int ci = 0; while ((k = yylex()) == TEXT) { sprintf(comments+ci,"%s\n",yytext+3); ci += yyleng - 2; } if (k != PC) return fatal_parsing_error("end of comments expected"); comments[ci] = '\0'; char *asyntax,*bsyntax; if (yylex() == PB) { int blen; if (yylex() == NUMBER) blen = atoi(yytext); else return fatal_parsing_error("before comment length expected"); bsyntax = new char[blen +1]; int bi = 0; while ((k = yylex()) == TEXT) { sprintf(bsyntax+bi,"%s\n",yytext+3); bi += yyleng - 2; } if (k != PB) return fatal_parsing_error("end of comments expected"); bsyntax[bi] = '\0'; } else return fatal_parsing_error("vertex' before comments expected"); if (yylex() == PA) { int alen; if (yylex() == NUMBER) alen = atoi(yytext); else return fatal_parsing_error("after comment length expected"); asyntax = new char[alen +1]; int ai = 0; while ((k = yylex()) == TEXT) { sprintf(asyntax+ai,"%s\n",yytext+3); ai += yyleng - 2; } if (k != PA) return fatal_parsing_error("end of comments expected"); asyntax[ai] = '\0'; } else return fatal_parsing_error("edge's after comments expected"); VertexObject *sv = vertex_store->getEndVertex(sid,sk); if (sv==NULL) { return fatal_parsing_error( "file corrupted"); } VertexObject *tv = vertex_store->getEndVertex(tid,tk); if (tv==NULL) { return fatal_parsing_error( "file corrupted"); } OptRepetitionEdge *e = new OptRepetitionEdge(); e->get_comments()->set_comments(comments); e->set_before(bsyntax); e->set_after(asyntax); e->set_from_vertex(sv); e->set_to_vertex(tv); e->set_points(pts); tv->get_incoming_repedge_store()->append(e); sv->get_outgoing_repedge_store()->append(e); repedge_store->append(e); break; } case PAE: { /* alternation edge */ token_kind sk, tk; long sid,tid; if (!isLegalEndVertexKind(sk = yylex())) return fatal_parsing_error( "start vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "start vertex id expected"); sid = atol(yytext); if (!isLegalEndVertexKind(tk = yylex())) return fatal_parsing_error( "end vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "end vertex id expected"); tid = atol(yytext); if (yylex() != LBR) return fatal_parsing_error("\"[\" expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "number of points expected"); int npts = atoi(yytext)+1; PointObjectList *pts = NULL; PointObjectList *curpts; while (npts) { if (pts==NULL) { pts = new PointObjectList(); curpts = pts; } else { curpts->set_next(new PointObjectList()); curpts->get_next()->set_prev(curpts); curpts = curpts->get_next(); } curpts->set_elm(new PointObject()); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's x expected"); curpts->get_elm()->set_x(atoi(yytext)); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's y id expected"); curpts->get_elm()->set_y(atoi(yytext)); npts--; } if (yylex() != RBR) return fatal_parsing_error( "\"]\" expected"); if (yylex() != PC) return fatal_parsing_error("edge's comments expected"); int clen; if (yylex() != NUMBER) return fatal_parsing_error("comment length expected"); clen = atoi(yytext); char *comments = new char[clen +1]; int ci = 0; while ((k = yylex()) == TEXT) { sprintf(comments+ci,"%s\n",yytext+3); ci += yyleng - 2; } if (k != PC) return fatal_parsing_error("end of comments expected"); comments[ci] = '\0'; VertexObject *sv = vertex_store->getEndVertex(sid,sk); if (sv==NULL) { return fatal_parsing_error( "file corrupted"); } VertexObject *tv = vertex_store->getEndVertex(tid,tk); if (tv==NULL) { return fatal_parsing_error( "file corrupted"); } AlternationEdge *e = new AlternationEdge(); e->get_comments()->set_comments(comments); e->set_from_vertex(sv); e->set_to_vertex(tv); e->set_points(pts); tv->get_incoming_altedge_store()->append(e); sv->get_outgoing_altedge_store()->append(e); altedge_store->append(e); break; } case PIE: { /* inheritance edge */ token_kind sk, tk; long sid,tid; if (!isLegalEndVertexKind(sk = yylex())) return fatal_parsing_error( "start vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "start vertex id expected"); sid = atol(yytext); if (!isLegalEndVertexKind(tk = yylex())) return fatal_parsing_error( "end vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "end vertex id expected"); tid = atol(yytext); if (yylex() != LBR) return fatal_parsing_error("\"[\" expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "number of points expected"); int npts = atoi(yytext)+1; PointObjectList *pts = NULL; PointObjectList *curpts; while (npts) { if (pts==NULL) { pts = new PointObjectList(); curpts = pts; } else { curpts->set_next(new PointObjectList()); curpts->get_next()->set_prev(curpts); curpts = curpts->get_next(); } curpts->set_elm(new PointObject()); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's x expected"); curpts->get_elm()->set_x(atoi(yytext)); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's y id expected"); curpts->get_elm()->set_y(atoi(yytext)); npts--; } if (yylex() != RBR) return fatal_parsing_error( "\"]\" expected"); if (yylex() != PC) return fatal_parsing_error("edge's comments expected"); int clen; if (yylex() != NUMBER) return fatal_parsing_error("comment length expected"); clen = atoi(yytext); char *comments = new char[clen +1]; int ci = 0; while ((k = yylex()) == TEXT) { sprintf(comments+ci,"%s\n",yytext+3); ci += yyleng - 2; } if (k != PC) return fatal_parsing_error("end of comments expected"); comments[ci] = '\0'; VertexObject *sv = vertex_store->getEndVertex(sid,sk); if (sv==NULL) { return fatal_parsing_error( "file corrupted"); } VertexObject *tv = vertex_store->getEndVertex(tid,tk); if (tv==NULL) { return fatal_parsing_error( "file corrupted"); } InheritanceEdge *e = new InheritanceEdge(); e->get_comments()->set_comments(comments); e->set_from_vertex(sv); e->set_to_vertex(tv); e->set_points(pts); tv->get_incoming_inhedge_store()->append(e); sv->get_outgoing_inhedge_store()->append(e); inhedge_store->append(e); break; } case PPIE: { /* instantiation edge */ token_kind sk, tk; long sid,tid; if (!isLegalEndVertexKind(sk = yylex())) return fatal_parsing_error( "start vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "start vertex id expected"); sid = atol(yytext); if (!isLegalEndVertexKind(tk = yylex())) return fatal_parsing_error( "end vertex kind expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "end vertex id expected"); tid = atol(yytext); if (yylex() != LBR) return fatal_parsing_error("\"[\" expected"); if ( yylex()!= NUMBER) return fatal_parsing_error( "number of points expected"); int npts = atoi(yytext)+1; PointObjectList *pts = NULL; PointObjectList *curpts; while (npts) { if (pts==NULL) { pts = new PointObjectList(); curpts = pts; } else { curpts->set_next(new PointObjectList()); curpts->get_next()->set_prev(curpts); curpts = curpts->get_next(); } curpts->set_elm(new PointObject()); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's x expected"); curpts->get_elm()->set_x(atoi(yytext)); if ( yylex()!= NUMBER) return fatal_parsing_error( "point's y id expected"); curpts->get_elm()->set_y(atoi(yytext)); npts--; } if (yylex() != RBR) return fatal_parsing_error( "\"]\" expected"); if (yylex() != PC) return fatal_parsing_error("edge's comments expected"); int clen; if (yylex() != NUMBER) return fatal_parsing_error("comment length expected"); clen = atoi(yytext); char *comments = new char[clen +1]; int ci = 0; while ((k = yylex()) == TEXT) { sprintf(comments+ci,"%s\n",yytext+3); ci += yyleng - 2; } if (k != PC) return fatal_parsing_error("end of comments expected"); comments[ci] = '\0'; VertexObject *sv = vertex_store->getEndVertex(sid,sk); if (sv==NULL) { return fatal_parsing_error( "file corrupted"); } VertexObject *tv = vertex_store->getEndVertex(tid,tk); if (tv==NULL) { return fatal_parsing_error( "file corrupted"); } ParameterInstEdge *e = new ParameterInstEdge(); e->get_comments()->set_comments(comments); e->set_from_vertex(sv); e->set_to_vertex(tv); e->set_points(pts); tv->get_incoming_parinstedge_store()->append(e); sv->get_outgoing_parinstedge_store()->append(e); parinstedge_store->append(e); break; } case PEND: { /* end of input */ return 1; } default: { break; } } } return 1; }