Esempio n. 1
0
bool IsBasicVar(SymbolItem &item,SymbolTable &table){
    bool rect=false;
    rect=(item.GetKind()== varsk || item.GetKind()== parask);
    rect=rect&&(item.GetType()== charst || item.GetType()== integerst);
    rect = rect ||(table.GetKind()== funcsk && table.GetName()==item.GetName() && TouchNextChar()!='(');
    return rect;
}
Esempio n. 2
0
bool CheckItem(string str,SymbolKind kind,SymbolType type,SymbolTable &table)
{
    SymbolItem* item = table.GetItem(str);
    if (item->GetKind()== parask && kind== varsk) return true;//if var is para then return true
    if (kind== varsk && table.GetName()==str && table.GetKind()== funcsk) return true;//if var is the name of this table, and current table is a function then return true.
    if (item->GetKind()!=kind) return false;
    if (item->GetType()!=type) return false;
    return true;
}
Esempio n. 3
0
void SubProgram(SymbolTable &table)
{
    if (symbol==CONSTTK) ConstDeclaration(table);
    if (symbol==VARTK) VarDeclaration(table);
    while (symbol==PROCETK || symbol==FUNCTK) {
        if (symbol==PROCETK) ProcDeClaration(table);
        else if (symbol==FUNCTK) FuncDeClaration(table);
    }
    if (symbol!=BEGINTK) ErrorHandler("SubProgram should begin with begin"); //Throw Error while define Subprogram, can not find begin tk.
    if (table.GetKind()==procsk) interResult<<"Proc ";
    if (table.GetKind()==funcsk) interResult<<"Func ";
    interResult<<table.GetName();
    for (int i=0;i!=ptable;++i) if ((&symbolTableList[i])==&table) {
        interResult<<' '<<i<<endl;
        break;
    }
    CompoundStatement(table);
    table.Push(table.GetName(), varsk);
    table.SetType(table.GetFuncType());
    table.FillBack();
}