Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/expr/ExParser.cpp
Go to the documentation of this file.
00001 
00002 
00003 #include <marsyas/expr/ExParser.h>
00004 #include <marsyas/expr/ExScanner.h>
00005 
00006 using namespace Marsyas;
00007 
00008 void ExParser::Get() {
00009   for (;;) {
00010     t = la;
00011     la = scanner->Scan();
00012     if (la->kind <= maxT) { ++errDist; break; }
00013 
00014     if (dummyToken != t) {
00015       dummyToken->kind = t->kind;
00016       dummyToken->pos = t->pos;
00017       dummyToken->col = t->col;
00018       dummyToken->line = t->line;
00019       dummyToken->next = NULL;
00020       coco_string_delete(dummyToken->val);
00021       dummyToken->val = coco_string_create(t->val);
00022       t = dummyToken;
00023     }
00024     la = t;
00025   }
00026 }
00027 
00028 void ExParser::Expect(int n) {
00029   if (la->kind==n) Get(); else { SynErr(n); }
00030 }
00031 
00032 void ExParser::ExpectWeak(int n, int follow) {
00033   if (la->kind == n) Get();
00034   else {
00035     SynErr(n);
00036     while (!StartOf(follow)) Get();
00037   }
00038 }
00039 
00040 bool ExParser::WeakSeparator(int n, int syFol, int repFol) {
00041   if (la->kind == n) {Get(); return true;}
00042   else if (StartOf(repFol)) {return false;}
00043   else {
00044     SynErr(n);
00045     while (!(StartOf(syFol) || StartOf(repFol) || StartOf(0))) {
00046       Get();
00047     }
00048     return StartOf(syFol);
00049   }
00050 }
00051 
00052 void ExParser::Alias(std::string& nm) {
00053   Expect(46);
00054   Name(nm);
00055 }
00056 
00057 void ExParser::Name(std::string& nm) {
00058   Expect(5);
00059   nm=t->val;
00060 }
00061 
00062 void ExParser::CName(std::string& nm) {
00063   Expect(6);
00064   nm=t->val;
00065 }
00066 
00067 void ExParser::AddOp(int& m) {
00068   if (la->kind == 23) {
00069     Get();
00070     m=OP_ADD;
00071   } else if (la->kind == 24) {
00072     Get();
00073     m=OP_SUB;
00074   } else SynErr(62);
00075 }
00076 
00077 void ExParser::MulOp(int& m) {
00078   if (la->kind == 25) {
00079     Get();
00080     m=OP_MUL;
00081   } else if (la->kind == 26) {
00082     Get();
00083     m=OP_DIV;
00084   } else if (la->kind == 27) {
00085     Get();
00086     m=OP_MOD;
00087   } else SynErr(63);
00088 }
00089 
00090 void ExParser::RelOp(int& m) {
00091   switch (la->kind) {
00092   case 34: {
00093     Get();
00094     m=OP_EQ;
00095     break;
00096   }
00097   case 35: {
00098     Get();
00099     m=OP_NE;
00100     break;
00101   }
00102   case 36: {
00103     Get();
00104     m=OP_GT;
00105     break;
00106   }
00107   case 37: {
00108     Get();
00109     m=OP_GE;
00110     break;
00111   }
00112   case 38: {
00113     Get();
00114     m=OP_LT;
00115     break;
00116   }
00117   case 39: {
00118     Get();
00119     m=OP_LE;
00120     break;
00121   }
00122   default: SynErr(64); break;
00123   }
00124 }
00125 
00126 void ExParser::LAsgnOp(int& type) {
00127   switch (la->kind) {
00128   case 14: {
00129     Get();
00130     type=OP_ADD;
00131     break;
00132   }
00133   case 15: {
00134     Get();
00135     type=OP_SUB;
00136     break;
00137   }
00138   case 16: {
00139     Get();
00140     type=OP_MUL;
00141     break;
00142   }
00143   case 17: {
00144     Get();
00145     type=OP_DIV;
00146     break;
00147   }
00148   case 18: {
00149     Get();
00150     type=OP_MOD;
00151     break;
00152   }
00153   case 22: {
00154     Get();
00155     type=OP_OR;
00156     break;
00157   }
00158   case 21: {
00159     Get();
00160     type=OP_AND;
00161     break;
00162   }
00163   default: SynErr(65); break;
00164   }
00165 }
00166 
00167 void ExParser::RAsgnOp(int& type) {
00168   switch (la->kind) {
00169   case 9: {
00170     Get();
00171     type=OP_ADD;
00172     break;
00173   }
00174   case 10: {
00175     Get();
00176     type=OP_SUB;
00177     break;
00178   }
00179   case 11: {
00180     Get();
00181     type=OP_MUL;
00182     break;
00183   }
00184   case 12: {
00185     Get();
00186     type=OP_DIV;
00187     break;
00188   }
00189   case 13: {
00190     Get();
00191     type=OP_MOD;
00192     break;
00193   }
00194   case 20: {
00195     Get();
00196     type=OP_OR;
00197     break;
00198   }
00199   case 19: {
00200     Get();
00201     type=OP_AND;
00202     break;
00203   }
00204   default: SynErr(66); break;
00205   }
00206 }
00207 
00208 void ExParser::Exprs(ExNode** u) {
00209   ExNode* v=NULL; if(fail)return;
00210   Task(u);
00211   if(fail)return;
00212   while (la->kind == 42) {
00213     Get();
00214     Task(&v);
00215     if(!fail)*u=expr_append(*u,v); else {delete *u; *u=NULL;}
00216   }
00217 }
00218 
00219 void ExParser::Task(ExNode** u) {
00220   if (fail) return;
00221   if (IsLAsgn()) {
00222     LAsgn(u);
00223   } else if (IsLink()) {
00224     Link(u);
00225   } else if (StartOf(1)) {
00226     RAsgn(u);
00227   } else SynErr(67);
00228 }
00229 
00230 void ExParser::LAsgn(ExNode** u) {
00231   int atype; std::string nm; std::string as; if (fail) return; bool seq=false; ExNode* idx=NULL;
00232   if (la->kind == 51) {
00233     Get();
00234     Expect(47);
00235     Name(nm);
00236     Expect(8);
00237     Condition(u);
00238     if(fail)return;
00239     if(nm=="opn")*u=new ExFun_StreamOutNVal(*u);
00240     else *u=do_property(NULL,"Stream."+nm,*u);
00241   } else if (la->kind == 5) {
00242     Name(nm);
00243     if (la->kind == 48) {
00244       Elem(idx);
00245       seq=true;
00246     }
00247     if (StartOf(2)) {
00248       LAsgnOp(atype);
00249       Condition(u);
00250       if(fail)return;
00251       if(!seq) *u=do_masgn(atype,false,nm,*u);
00252       else *u=do_msetelem(nm,idx,NULL,false,false,atype,*u);
00253     } else if (la->kind == 8) {
00254       Get();
00255       Condition(u);
00256       if(fail)return;
00257       if(!seq) *u=do_asgn(nm,*u);
00258       else *u=do_setelem(nm,idx,NULL,false,*u);
00259     } else SynErr(68);
00260   } else if (la->kind == 6) {
00261     CName(nm);
00262     if (StartOf(2)) {
00263       LAsgnOp(atype);
00264       Condition(u);
00265       if(fail)return; *u=do_cmasgn(atype,false,nm,*u);
00266     } else if (la->kind == 8) {
00267       Get();
00268       Condition(u);
00269       if(fail)return; *u=do_casgn(nm,*u);
00270     } else SynErr(69);
00271   } else if (la->kind == 46) {
00272     Alias(as);
00273     Expect(8);
00274     CName(nm);
00275     *u=do_alias(as,nm);
00276   } else SynErr(70);
00277 }
00278 
00279 void ExParser::Link(ExNode** u) {
00280   std::string nm1,nm2; if(fail)return;
00281   CName(nm1);
00282   if (la->kind == 32) {
00283     Get();
00284     CName(nm2);
00285     *u=do_link(nm2,nm1);
00286   } else if (la->kind == 31) {
00287     Get();
00288     CName(nm2);
00289     *u=do_link(nm1,nm2);
00290   } else SynErr(71);
00291 }
00292 
00293 void ExParser::RAsgn(ExNode** u) {
00294   int atype; std::string nm; std::string as; if(fail)return;
00295   if (IsCNameRAsgnAlias()) {
00296     CName(nm);
00297     Expect(7);
00298     Alias(as);
00299     *u=do_alias(as,nm);
00300   } else if (StartOf(1)) {
00301     Condition(u);
00302     if(fail)return;
00303     if (StartOf(3)) {
00304       if (la->kind == 7) {
00305         Get();
00306         if (la->kind == 51) {
00307           Get();
00308           Expect(47);
00309           Name(nm);
00310           if(fail)return;
00311           if(nm=="opn")*u=new ExFun_StreamOutNVal(*u);
00312           else *u=do_property(NULL,"Stream."+nm,*u);
00313         } else if (la->kind == 5) {
00314           Name(nm);
00315           if (la->kind == 48) {
00316             ExNode* idx=NULL;
00317             Elem(idx);
00318             *u=do_setelem(nm,idx,NULL,false,*u); return;
00319           }
00320           *u=do_asgn(nm,*u);
00321         } else if (la->kind == 6) {
00322           CName(nm);
00323           *u=do_casgn(nm,*u);
00324         } else SynErr(72);
00325       } else {
00326         RAsgnOp(atype);
00327         if (la->kind == 5) {
00328           Name(nm);
00329           if (la->kind == 48) {
00330             ExNode* idx=NULL;
00331             Elem(idx);
00332             *u=do_msetelem(nm,idx,NULL,false,true,atype,*u); return;
00333           }
00334           *u=do_masgn(atype,true,nm,*u);
00335         } else if (la->kind == 6) {
00336           CName(nm);
00337           *u=do_cmasgn(atype,true,nm,*u);
00338         } else SynErr(73);
00339       }
00340     }
00341   } else SynErr(74);
00342 }
00343 
00344 void ExParser::Condition(ExNode** u) {
00345   ExNode* v=NULL; bool neg=false; if (fail) return;
00346   if (la->kind == 33) {
00347     Get();
00348     neg=true;
00349   }
00350   CondTerm(u);
00351   if (fail) return; if (neg) { *u=do_bool_negate(*u); if (fail) return; }
00352   while (la->kind == 41) {
00353     Get();
00354     CondTerm(&v);
00355     if (!fail) *u=do_condop(OP_OR,*u,v); else {delete*u; *u=NULL;}
00356   }
00357 }
00358 
00359 void ExParser::CondTerm(ExNode** u) {
00360   ExNode* v=NULL; if (fail) return;
00361   CondFact(u);
00362   if (fail) return;
00363   while (la->kind == 40) {
00364     Get();
00365     CondFact(&v);
00366     if (!fail) *u=do_condop(OP_AND,*u,v); else {delete*u; *u=NULL;}
00367   }
00368 }
00369 
00370 void ExParser::CondFact(ExNode** u) {
00371   int m=0; ExNode* v=NULL; if (fail) return;
00372   Expr(u);
00373   if (fail) return;
00374   while (StartOf(4)) {
00375     RelOp(m);
00376     Expr(&v);
00377     if (!fail) *u=do_relop(m,*u,v); else {delete*u; *u=NULL;}
00378   }
00379 }
00380 
00381 void ExParser::Expr(ExNode** u) {
00382   int m=0; ExNode* v=NULL; bool neg=false; if (fail) return;
00383   if (la->kind == 24) {
00384     Get();
00385     neg=true;
00386   }
00387   Term(u);
00388   if(fail)return; if (neg) { *u=do_num_negate(*u); if (fail) return; }
00389   while (la->kind == 23 || la->kind == 24) {
00390     AddOp(m);
00391     Term(&v);
00392     if (!fail) *u=do_addop(m,*u,v); else {delete*u; *u=NULL;}
00393   }
00394 }
00395 
00396 void ExParser::Term(ExNode** u) {
00397   int m=0; ExNode* v=NULL; if (fail) return;
00398   Property(u);
00399   if (fail) return;
00400   while (la->kind == 25 || la->kind == 26 || la->kind == 27) {
00401     MulOp(m);
00402     Property(&v);
00403     if (!fail) *u=do_mulop(m,*u,v); else {delete*u; *u=NULL;}
00404   }
00405 }
00406 
00407 void ExParser::Property(ExNode** u) {
00408   std::string l=""; std::string n; ExNode* ps=NULL;
00409   Factor(l,u);
00410   if (fail) return;
00411   while (la->kind == 47) {
00412     Get();
00413     Name(n);
00414     if (la->kind == 29) {
00415       Get();
00416       if (StartOf(5)) {
00417         Exprs(&ps);
00418       }
00419       Expect(30);
00420     }
00421     if(!fail) {*u=do_property(*u,l+n,ps); l="";} else {delete*u; *u=NULL;}
00422   }
00423 }
00424 
00425 void ExParser::Factor(std::string& l, ExNode** u) {
00426   std::string nm; if (fail) return;
00427   switch (la->kind) {
00428   case 52: {
00429     Get();
00430     *u=new ExNode(true);
00431     break;
00432   }
00433   case 53: {
00434     Get();
00435     *u=new ExNode(false);
00436     break;
00437   }
00438   case 4: {
00439     Get();
00440     *u=new ExNode(t->val[1]=='t');
00441     break;
00442   }
00443   case 1: {
00444     Get();
00445     *u=new ExNode(atol(t->val));
00446     break;
00447   }
00448   case 2: {
00449     Get();
00450     *u=new ExNode((mrs_real)atof(t->val));
00451     break;
00452   }
00453   case 29: {
00454     Get();
00455     Condition(u);
00456     Expect(30);
00457     break;
00458   }
00459   case 3: case 5: case 6: case 43: case 45: case 48: {
00460     Sequence(l,u);
00461     break;
00462   }
00463   default: SynErr(75); break;
00464   }
00465 }
00466 
00467 void ExParser::ListElems(ExNode** u) {
00468   ExNode* v=NULL; std::string type;
00469   Condition(u);
00470   while (la->kind == 42) {
00471     Get();
00472     Condition(&v);
00473     if(!fail)*u=list_append(*u,v);
00474   }
00475 }
00476 
00477 void ExParser::Sequence(std::string& l, ExNode** u) {
00478   FactorB(l,u);
00479   if(fail)return;
00480   while (la->kind == 48) {
00481     ElemAccess(u);
00482     if(fail)return;
00483   }
00484 }
00485 
00486 void ExParser::ElemAccess(ExNode** u) {
00487   ExNode* lidx=NULL; ExNode* ridx=NULL; bool is_range=false; std::string nm;
00488   Expect(48);
00489   if (la->kind == 1 || la->kind == 5) {
00490     if (la->kind == 1) {
00491       Get();
00492       lidx=new ExNode((mrs_natural)atoi(t->val));
00493     } else {
00494       Name(nm);
00495       lidx=do_name(false,nm,NULL); if(fail)return;
00496     }
00497     if (la->kind == 50) {
00498       Get();
00499       is_range=true;
00500       if (la->kind == 1 || la->kind == 5) {
00501         if (la->kind == 1) {
00502           Get();
00503           ridx=new ExNode((mrs_natural)atoi(t->val));
00504         } else {
00505           Name(nm);
00506           ridx=do_name(false,nm,NULL); if(fail) {lidx->deref(); return;}
00507         }
00508       }
00509     }
00510   } else if (la->kind == 50) {
00511     Get();
00512     if (la->kind == 1) {
00513       Get();
00514       is_range=true; ridx=new ExNode((mrs_natural)atoi(t->val));
00515     } else if (la->kind == 5) {
00516       Name(nm);
00517       ridx=do_name(false,nm,NULL); if(fail)return;
00518     } else SynErr(76);
00519   } else SynErr(77);
00520   Expect(49);
00521   *u=do_getelem(*u,lidx,ridx,is_range);
00522 }
00523 
00524 void ExParser::FactorB(std::string& l, ExNode** u) {
00525   std::string nm; ExNode* ps=NULL; if (fail) return;
00526   switch (la->kind) {
00527   case 5: {
00528     Name(nm);
00529     bool f=false;
00530     if (la->kind == 29) {
00531       Get();
00532       f=true;
00533       if (StartOf(5)) {
00534         Exprs(&ps);
00535       }
00536       Expect(30);
00537     }
00538     if (fail) return;
00539     if (getKind(nm)==T_LIB) { l=nm+"."; *u=NULL; }
00540     else *u=do_name(f,nm,ps);
00541 
00542     break;
00543   }
00544   case 6: {
00545     CName(nm);
00546     *u=do_getctrl(nm);
00547     break;
00548   }
00549   case 48: {
00550     Get();
00551     bool mt=true;
00552     if (StartOf(1)) {
00553       ListElems(&ps);
00554       mt=false;
00555     }
00556     Expect(49);
00557     if(fail)return; *u=do_list(mt,ps);
00558     break;
00559   }
00560   case 3: {
00561     Get();
00562     *u=new ExNode(prep_string(t->val));
00563     break;
00564   }
00565   case 45: {
00566     Get();
00567     ExNode* c=NULL; ExNode* ts=NULL; ExNode* es=NULL;
00568     Condition(&c);
00569     if(fail)return;
00570     Expect(50);
00571     Exprs(&ts);
00572     if(fail) {if(c)c->deref(); return;}
00573     Expect(50);
00574     Exprs(&es);
00575     if(fail) {if(c)c->deref(); if(ts)ts->deref(); return;}
00576     Expect(44);
00577     *u=do_conditional(c,ts,es);
00578     break;
00579   }
00580   case 43: {
00581     Get();
00582     int m=0; std::string var_nm; bool in=false; std::string ary_nm; std::string tp;
00583     if (la->kind == 54) {
00584       Get();
00585       m=1;
00586     } else if (la->kind == 55) {
00587       Get();
00588       m=2;
00589     } else if (la->kind == 56) {
00590       Get();
00591       m=3;
00592     } else if (la->kind == 57) {
00593       Get();
00594       m=4;
00595     } else SynErr(78);
00596     Name(var_nm);
00597     if (la->kind == 58) {
00598       Get();
00599       in=true;
00600     }
00601     if (la->kind == 50) {
00602       Get();
00603       if(!in) {
00604         MRSWARN("ExParser::Unexpected : in iterator declaration");
00605         fail=true;
00606       }
00607       else if (m==2) ary_nm="in";
00608       else *u=do_name(false,"in",NULL);
00609 
00610     } else if (m==2) {
00611       Name(ary_nm);
00612       Expect(50);
00613     } else if (StartOf(1)) {
00614       Condition(u);
00615       Expect(50);
00616     } else SynErr(79);
00617     if(fail)return;
00618     tp=(m==2) ? tp=getElemType(ary_nm) : (*u)->getElemType();
00619     // need to insert var nm into symbol table so it
00620     // can be used in the expression
00621     symbol_table.block_open();
00622     ExVal v=ExValTyped(T_VAR,tp);
00623     symbol_table.setValue(v,var_nm);
00624     Exprs(&ps);
00625     Expect(44);
00626     if(fail) {
00627       if(*u) {(*u)->deref(); *u=NULL;}
00628     } else *u=do_iter(m,var_nm,ary_nm,*u,ps);
00629     symbol_table.block_close();
00630     break;
00631   }
00632   default: SynErr(80); break;
00633   }
00634 }
00635 
00636 void ExParser::Elem(ExNode*& idx) {
00637   std::string nm;
00638   Expect(48);
00639   if (la->kind == 1) {
00640     Get();
00641     idx=new ExNode((mrs_natural)atoi(t->val));
00642   } else if (la->kind == 5) {
00643     Name(nm);
00644     idx=do_name(false,nm,NULL);
00645   } else SynErr(81);
00646   Expect(49);
00647 }
00648 
00649 void ExParser::Use() {
00650   std::string nm; if(fail)return;
00651   Expect(59);
00652   Name(nm);
00653   symbol_table.import(nm);
00654   Expect(42);
00655 }
00656 
00657 void ExParser::Load() {
00658   std::string nm; if(fail)return;
00659   Expect(60);
00660   Name(nm);
00661   Expect(42);
00662 }
00663 
00664 void ExParser::UL() {
00665   if (la->kind == 59) {
00666     Use();
00667   } else if (la->kind == 60) {
00668     Load();
00669   } else SynErr(82);
00670 }
00671 
00672 void ExParser::Neil() {
00673   tree=NULL; std::string nm;
00674   while (la->kind == 59 || la->kind == 60) {
00675     UL();
00676   }
00677   Exprs(&tree);
00678   if(fail) { delete tree; tree=NULL; }
00679 }
00680 
00681 
00682 
00683 void ExParser::Parse() {
00684   t = NULL; fail=false;
00685   la = dummyToken = new Token();
00686   la->val = coco_string_create("Dummy Token");
00687   Get();
00688   Neil();
00689 
00690   if (!fail)
00691     Expect(0);
00692   delete dummyToken;
00693 }
00694 void ExParser::Parse(Scheduler* v, MarSystem* m, ExRecord* est)
00695 {
00696   scheduler_=v;
00697   marsystem_=m;
00698   symbol_table.addTable(est);
00699   Parse();
00700 }
00701 ExParser::ExParser(TmTimer** t, ExScanner *scanner) {
00702   _EOF = 0;
00703   _tnatural = 1;
00704   _treal = 2;
00705   _tstr = 3;
00706   _tbool = 4;
00707   _tname = 5;
00708   _cname = 6;
00709   _rasgn = 7;
00710   _lasgn = 8;
00711   _addrasgn = 9;
00712   _subrasgn = 10;
00713   _mulrasgn = 11;
00714   _divrasgn = 12;
00715   _modrasgn = 13;
00716   _addlasgn = 14;
00717   _sublasgn = 15;
00718   _mullasgn = 16;
00719   _divlasgn = 17;
00720   _modlasgn = 18;
00721   _andrasgn = 19;
00722   _orrasgn = 20;
00723   _andlasgn = 21;
00724   _orlasgn = 22;
00725   _addop = 23;
00726   _subop = 24;
00727   _mulop = 25;
00728   _divop = 26;
00729   _modop = 27;
00730   _power = 28;
00731   _lbrkt = 29;
00732   _rbrkt = 30;
00733   _rlink = 31;
00734   _llink = 32;
00735   _notop = 33;
00736   _eqop = 34;
00737   _neop = 35;
00738   _gtop = 36;
00739   _geop = 37;
00740   _ltop = 38;
00741   _leop = 39;
00742   _andop = 40;
00743   _orop = 41;
00744   _exprbrk = 42;
00745   _blkstart = 43;
00746   _blkend = 44;
00747   _ifblk = 45;
00748   _atsym = 46;
00749   _propsep = 47;
00750   _lsbrkt = 48;
00751   _rsbrkt = 49;
00752   _colon = 50;
00753   _streamlib = 51;
00754   maxT = 61;
00755 
00756   timer_=t;
00757   minErrDist = 2; fail=false;
00758   errDist = minErrDist;
00759   this->scanner = scanner;
00760   Init();
00761 }
00762 
00763 bool ExParser::StartOf(int s) {
00764   const bool T = true;
00765   const bool x = false;
00766 
00767   static bool set[6][63] = {
00768     {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
00769     {x,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,T,x,x, T,x,x,x, T,T,x,x, x,x,x,x, x,x,x},
00770     {x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
00771     {x,x,x,x, x,x,x,T, x,T,T,T, T,T,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
00772     {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x},
00773     {x,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,T,T,x, T,x,x,T, T,T,x,x, x,x,x,x, x,x,x}
00774   };
00775 
00776 
00777 
00778   return set[s][la->kind];
00779 }
00780 
00781 ExParser::~ExParser() {
00782 //    delete library;
00783 }
00784 void ExParser::SynErr(int n) {
00785   char* s;
00786   switch (n) {
00787   case 0: s = coco_string_create("EOF expected"); break;
00788   case 1: s = coco_string_create("tnatural expected"); break;
00789   case 2: s = coco_string_create("treal expected"); break;
00790   case 3: s = coco_string_create("tstr expected"); break;
00791   case 4: s = coco_string_create("tbool expected"); break;
00792   case 5: s = coco_string_create("tname expected"); break;
00793   case 6: s = coco_string_create("cname expected"); break;
00794   case 7: s = coco_string_create("rasgn expected"); break;
00795   case 8: s = coco_string_create("lasgn expected"); break;
00796   case 9: s = coco_string_create("addrasgn expected"); break;
00797   case 10: s = coco_string_create("subrasgn expected"); break;
00798   case 11: s = coco_string_create("mulrasgn expected"); break;
00799   case 12: s = coco_string_create("divrasgn expected"); break;
00800   case 13: s = coco_string_create("modrasgn expected"); break;
00801   case 14: s = coco_string_create("addlasgn expected"); break;
00802   case 15: s = coco_string_create("sublasgn expected"); break;
00803   case 16: s = coco_string_create("mullasgn expected"); break;
00804   case 17: s = coco_string_create("divlasgn expected"); break;
00805   case 18: s = coco_string_create("modlasgn expected"); break;
00806   case 19: s = coco_string_create("andrasgn expected"); break;
00807   case 20: s = coco_string_create("orrasgn expected"); break;
00808   case 21: s = coco_string_create("andlasgn expected"); break;
00809   case 22: s = coco_string_create("orlasgn expected"); break;
00810   case 23: s = coco_string_create("addop expected"); break;
00811   case 24: s = coco_string_create("subop expected"); break;
00812   case 25: s = coco_string_create("mulop expected"); break;
00813   case 26: s = coco_string_create("divop expected"); break;
00814   case 27: s = coco_string_create("modop expected"); break;
00815   case 28: s = coco_string_create("power expected"); break;
00816   case 29: s = coco_string_create("lbrkt expected"); break;
00817   case 30: s = coco_string_create("rbrkt expected"); break;
00818   case 31: s = coco_string_create("rlink expected"); break;
00819   case 32: s = coco_string_create("llink expected"); break;
00820   case 33: s = coco_string_create("notop expected"); break;
00821   case 34: s = coco_string_create("eqop expected"); break;
00822   case 35: s = coco_string_create("neop expected"); break;
00823   case 36: s = coco_string_create("gtop expected"); break;
00824   case 37: s = coco_string_create("geop expected"); break;
00825   case 38: s = coco_string_create("ltop expected"); break;
00826   case 39: s = coco_string_create("leop expected"); break;
00827   case 40: s = coco_string_create("andop expected"); break;
00828   case 41: s = coco_string_create("orop expected"); break;
00829   case 42: s = coco_string_create("exprbrk expected"); break;
00830   case 43: s = coco_string_create("blkstart expected"); break;
00831   case 44: s = coco_string_create("blkend expected"); break;
00832   case 45: s = coco_string_create("ifblk expected"); break;
00833   case 46: s = coco_string_create("atsym expected"); break;
00834   case 47: s = coco_string_create("propsep expected"); break;
00835   case 48: s = coco_string_create("lsbrkt expected"); break;
00836   case 49: s = coco_string_create("rsbrkt expected"); break;
00837   case 50: s = coco_string_create("colon expected"); break;
00838   case 51: s = coco_string_create("streamlib expected"); break;
00839   case 52: s = coco_string_create("\"true\" expected"); break;
00840   case 53: s = coco_string_create("\"false\" expected"); break;
00841   case 54: s = coco_string_create("\"map\" expected"); break;
00842   case 55: s = coco_string_create("\"iter\" expected"); break;
00843   case 56: s = coco_string_create("\"for\" expected"); break;
00844   case 57: s = coco_string_create("\"rfor\" expected"); break;
00845   case 58: s = coco_string_create("\"in\" expected"); break;
00846   case 59: s = coco_string_create("\"use\" expected"); break;
00847   case 60: s = coco_string_create("\"load\" expected"); break;
00848   case 61: s = coco_string_create("??? expected"); break;
00849   case 62: s = coco_string_create("invalid AddOp"); break;
00850   case 63: s = coco_string_create("invalid MulOp"); break;
00851   case 64: s = coco_string_create("invalid RelOp"); break;
00852   case 65: s = coco_string_create("invalid LAsgnOp"); break;
00853   case 66: s = coco_string_create("invalid RAsgnOp"); break;
00854   case 67: s = coco_string_create("invalid Task"); break;
00855   case 68: s = coco_string_create("invalid LAsgn"); break;
00856   case 69: s = coco_string_create("invalid LAsgn"); break;
00857   case 70: s = coco_string_create("invalid LAsgn"); break;
00858   case 71: s = coco_string_create("invalid Link"); break;
00859   case 72: s = coco_string_create("invalid RAsgn"); break;
00860   case 73: s = coco_string_create("invalid RAsgn"); break;
00861   case 74: s = coco_string_create("invalid RAsgn"); break;
00862   case 75: s = coco_string_create("invalid Factor"); break;
00863   case 76: s = coco_string_create("invalid ElemAccess"); break;
00864   case 77: s = coco_string_create("invalid ElemAccess"); break;
00865   case 78: s = coco_string_create("invalid FactorB"); break;
00866   case 79: s = coco_string_create("invalid FactorB"); break;
00867   case 80: s = coco_string_create("invalid FactorB"); break;
00868   case 81: s = coco_string_create("invalid Elem"); break;
00869   case 82: s = coco_string_create("invalid UL"); break;
00870 
00871   default:
00872   {
00873     char format[20];
00874     coco_sprintf(format, 20, "error %d", n);
00875     s = coco_string_create(format);
00876   }
00877   break;
00878   }
00879   MRSWARN("ExParser: Syntax error - line " +ltos(la->line)+ " col " +ltos(la->col)+ ": " +s);
00880 //  printf("ExParser: Syntax error - line %d col %d: %s\n", la->line, la->col, s);
00881   coco_string_delete(s);
00882   fail=true;
00883 }
00884 void ExParser::SemErr(char* msg) {
00885   (void) msg;
00886   MRSWARN("ExParser: Semantic error - line " +ltos(la->line)+ " col " +ltos(la->col)+ ": " +msg);
00887 //  printf("ExParser: Semantic error - line %d col %d: %s\n", t->line, t->col, msg);
00888   fail=true;
00889 }
00890 
00891