Example #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;
}
Example #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;
}
Example #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();
}
Example #4
0
void AssignStatement(SymbolTable &table)
{
    Emit tmp;
    tmp.SetTP( assignet);
    if (symbol!=IDEN) ErrorHandler("Assign should have iden to be assigned");//Error assign should have iden
    SymbolItem* item = table.GetItem(token);
    if (item==NULL && token!=table.GetName()) ErrorHandler("iden not exist while assign");//Error iden not exist;
    if (IsBasicVar(*item, table)) tmp.SetD1(token);
    else if (IsArrayVar(*item)) tmp.SetD1(GetArrayOffset(table));
    else ;//Error This must be somthing I don't expect.
    GetNextSym();
    if (symbol!=ASSIGN) ErrorHandler("assign must have :=") ;//Error should be assign
    GetNextSym();
    tmp.SetS1(Expression(table));
    tmp.emitResult();
}