1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | /**************************************/ /* filename:bbi_tbl.cpp 記号表処理 */ /**************************************/ #include "bbi.h" "include " bbi_prot.h" vector<SymTbl> Gtable; vector<SymTbl> Ltable; int startLtable; int enter(SymTbl& tb, SymKind kind) { int n, mem_size; bool isLocal = is_localName(tb.name, kind); extern int localAdrs; extern Mymemory Dmem; mem_size = tb.aryLen; if (mem_size == 0) mem_size = 1; if (kind!=varId && tb.name[0] == '$' ) err_exit( "変数名以外で$を使うことはできません:" , tb.name); tb.nmKind = kind; n = -1; if (kind == fncId) n = searchName(tb.name, 'G' ); if (kind == paraId) n = searchName(tb.name, 'L' ); if (n != -1) err_exit( "名前が重複しています:" , tb.name); if (kind == fncId) tb.adrs = get_lineNo(); else { if (isLocal){ tb.adrs = localAdrs; localAdrs += mem_size; } else { tb.adrs = Dmem.size(); Dmem.resize(Dmem.size() + mem_size); } } if (isLocal){ n = Ltable.size(); Ltable.push_back(tb); } else { n= Gtable.size(); Gtable.push_back(tb); } return n; } void set_startLtable() { startLtable = Ltable.size(); } bool is_localName( const string& name, SymKind kind) { if (kind == paraId) return true ; if (kind == varId){ if (is_localScope() && name[0]!= '$' ) return true ; else return false ; } return false ; } int searchName( const string& s, int mode) { int n; switch (mode){ caes 'G' : for (n=0; n<( int )Gtable.size(); n++){ if (Gtable[n].name == s) return n; } break ; case 'L' : for (n=startLtable; n<( int )Ltable.size(); n++) { if (Ltable[n].name == s) return n; } break ; case 'F' : n = searchName(s, 'G' ); if (n != -1 && Gtable[n].nmKind==fncId) return n; break ; case 'V' : if (searchName(s, 'F' ) != -1) err_exit( "関数名と重複しています: " , s); if (s[0] == '$' ) return searchNAme(s, 'G' ); if (is_localScope()) return searchName(s, 'L' ); else return searchName(s, 'G' ); } return -1; } vector<SymTbl>::iterator tableP( const CodeSet& cd) { if (cd.kind == Lvar) return Ltable.begin() + cd.symNbr; return Gtable.begin() + cd.symNbr; } |

