/*
    analyzing each parameter put them into symbol table
    if two parameters have same id then report an error
    0 or 1 indicates val or ref
*/
void analyze_pram(Param param, char* procName, int paramNum)
{
    char* varName = param->id;
    if(param->kind==VAL)
    {
        if(addDecl(procName, varName, param->type, slotNum,0, paramNum)==0)
        {
            printf("duplicate parameter of %s in proc %s. \n", 
                varName, procName);
            errorNum++;
        }
        else
            slotNum++;
    }
    else if(param->kind==REF)
    {
        if(addDecl(procName, varName, param->type, slotNum,1,paramNum)==0)
        {
            printf("duplicate parameter of %s in proc %s. \n", 
                varName, procName);
            errorNum++;
        }
        else
            slotNum++;
    }
}
/*
    analyzing each declaration, if the variable has not 
    been declared then put it into symbol table,
    else report an error
    for array, calculate the size and dimension
    if the size is -1, report an error
*/
void analyze_decl(Decl decl, char* procName)
{
    char* varName = decl->id;
    if(!decl->intervals)
    {
        if(addDecl(procName, varName, decl->type, slotNum,0,-1)==0)
        {
            printf("duplicate declaration of %s in line %d. \n", 
                                        varName, decl->lineno);
            errorNum++;
        }
        else
            slotNum++;
    }
    else if(decl->intervals)
    {
        int size = getArrSize(decl->intervals);
        int dimension = getArrDimension(decl->intervals);
        if(size == -1)
        {
            printf("lower bound greater than higher bound.\n");
            errorNum++;
        }
        else if(addArray(procName, varName, decl->type, slotNum,
                           size, dimension, decl->intervals)==0)
        {
            printf("duplicate declaration of %s in line %d. \n",
                                          varName, decl->lineno);
            errorNum++;
        }
        else
            slotNum = slotNum + size;
    }
}
示例#3
0
文件: stemnt.cpp 项目: grypp/yaccgen
void
DeclStemnt::addDecls(Decl *decls)
{
    Decl    *decl = decls;

    while (decls != NULL)
    {
        decls = decls->next;
        decl->next = NULL;
        //std::cout << "Decl is: ";
        //decl->print(std::cout,true);
        //std::cout << std::endl;
        addDecl(decl);
        decl = decls;
    }
}