Example #1
0
void FuncHeader(SymbolTable &table)
{
    if (symbol!=FUNCTK) ErrorHandler("func should begin with function");//Error symbol should be func
    GetNextSym();
    if (symbol!=IDEN) ErrorHandler("function should have iden as name");//Error function should have iden
    symbolTableList[ptable].ReInitial(table.GetLevel()+1,&table,token, funcsk);
    ptable++;
    table.Push(token,  funcsk);
    GetNextSym();
    if (symbol!=LPARENT) ErrorHandler("function define should have ( ");//Error function should have (
    int num=0;
    GetNextSym();
    if (symbol!=RPARENT) num=GetParaList(symbolTableList[ptable-1]);
    symbolTableList[ptable-1].SetParaNum(num);
    if (symbol!=RPARENT) ErrorHandler("function defien should have )");//Error function should have )
    GetNextSym();
    if (symbol!=COLON) ErrorHandler("function define should have :");//Error fcuntion should have return value
    GetNextSym();
    if (symbol==INTTK) table.SetType( integerst);
    else if (symbol==CHARTK) {
        table.SetType( charst);
        symbolTableList[ptable-1].SetFuncType(charst);
    }
    else ;//Error function should have return value;
    table.SetValue(num);
    table.FillBack();
    GetNextSym();
    if (symbol!=SEMICN) ErrorHandler("function define should have integer or char as type");//Error function should end with ;
    GetNextSym();
}
Example #2
0
void ProcHeader(SymbolTable &table)
{
    if (symbol!=PROCETK) ErrorHandler("Proc should begin with procedure");//Error procedure should begin with procedure
    GetNextSym();
    if (symbol!=IDEN) ErrorHandler("procedue should have iden as name");//Error procedure should have iden
    symbolTableList[ptable].ReInitial(table.GetLevel()+1,&table,token, procsk);
    ptable++;
    table.Push(token,  procsk);
    GetNextSym();
    if (symbol!=LPARENT) ErrorHandler("proc define should have (");//Error procedure should have (
    int num=0;//The number of para
    GetNextSym();
    if (symbol!=RPARENT) num=GetParaList(symbolTableList[ptable-1]);
    symbolTableList[ptable-1].SetParaNum(num);
    table.SetTypeValue( integerst, num);
    table.FillBack();
    if (symbol!=RPARENT) ErrorHandler("Proc define should have )") ;//Error procedure should have )
    GetNextSym();
    if (symbol!=SEMICN) ErrorHandler("Proc head def should end with ;");//Error Procedure should end with ;
    GetNextSym();
}