#include #include "grammar.hh" bool (*constraint[MAXCONSTRS])(int head, int dep); int chk_type(const char* s, int lineno) // SIDE EFECTS! { if(Role::index(s)>0) return 1; fprintf(stderr,"%8d: Invalid type '%s'. Line ignored.\n",lineno,s); return 0; } int chk_cat(const char* s, int lineno) { if(Cat::index(s)>0) return 1; fprintf(stderr,"%8d: Invalid category '%s'. Line ignored.\n",lineno,s); return 0; } void Grammar::add_category(const char* s) { Cat::add(s); if(Cat::count()>cats_sz) { cats_sz += 16; connect.resize(cats_sz); for(int i=0; itypes_sz) { types_sz += 16; lt.resize(types_sz); gt.resize(types_sz); } } void Grammar::set_lt(Role s, Role t) { lt[s].set(t); gt[t].set(s); if(s==0||(int)t==0) return; else { for(int i=0; i=2) { add_category(arg1); } else if(strcmp(key,"ROLE")==0 && fields>=2) { add_type(arg1); } else if(strcmp(key,"SGL")==0 && fields>=2) { if(chk_type(arg1,lineno)) set_sgl(arg1); } else if(strcmp(key,"LEFT")==0 && fields>=2) { if(chk_type(arg1,lineno)) set_left(arg1); } else if(strcmp(key,"RIGHT")==0 && fields>=2) { if(chk_type(arg1,lineno)) set_right(arg1); } else if(strcmp(key,"REQ")==0 && fields>=3) { if(chk_cat(arg1,lineno) + chk_type(arg2,lineno) == 2) set_obl(arg1,arg2); } else if(strcmp(key,"LINK")==0 && fields>=4) { if(chk_cat(arg1,lineno) + chk_cat(arg2,lineno) + chk_type(arg3,lineno) == 3) set_connect(arg1,arg2,arg3); } else fprintf(stderr,"Invalid line %d. Ignored.\n", lineno); } // compute_gt(); return true; } void Grammar::write(FILE* f) { for(Cat i=1; i