Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compilation errors under g++

Status
Not open for further replies.

solled

Programmer
Nov 3, 2003
6
US
Hi, I get a lot of compilation errors on the following code. It appears that the compiler thinks much of the code to be in the global scope when in fact they are in functions. I seem to have the backets set up properly, so I dont see why this is happening.

Thanks for any help.

ERRORS

g++ -c SymTabMgr.C
SymTabMgr.C:17: syntax error before `*' token
SymTabMgr.C:24: parse error before `for'
SymTabMgr.C:24: syntax error before `<=' token
SymTabMgr.C:24: syntax error before `++' token
SymTabMgr.C:26: syntax error before `.' token
SymTabMgr.C:27: syntax error before `++' token
SymTabMgr.C:28: ISO C++ forbids declaration of `x' with no type
SymTabMgr.C:28: conflicting types for `int x'
SymTabMgr.C:20: previous declaration as `size_t x'
SymTabMgr.C:28: `table' was not declared in this scope
SymTabMgr.C:28: `name' was not declared in this scope
SymTabMgr.C:29: parse error before `if'
SymTabMgr.C:33: syntax error before `<=' token
SymTabMgr.C:33: syntax error before `++' token
SymTabMgr.C:35: syntax error before `.' token
SymTabMgr.C:41: syntax error before `*' token
SymTabMgr.C:54: syntax error before `*' token
SymTabMgr.C:61: syntax error before `(' token
SymTabMgr.C:64: redefinition of `SymTabEntry*entry'
SymTabMgr.C:23: `SymTabEntry*entry' previously declared here
SymTabMgr.C:65: redefinition of `int x'
SymTabMgr.C:28: `int x' previously defined here
SymTabMgr.C:66: ISO C++ forbids declaration of `x' with no type
SymTabMgr.C:66: redefinition of `int x'
SymTabMgr.C:65: `int x' previously declared here
SymTabMgr.C:66: `table' was not declared in this scope
SymTabMgr.C:66: `se' was not declared in this scope
SymTabMgr.C:67: parse error before `if'
SymTabMgr.C:69: syntax error before `.' token
SymTabMgr.C:79: syntax error before `.' token
SymTabMgr.C:85: syntax error before `(' token
SymTabMgr.C:89: ISO C++ forbids declaration of `currentScopeDef' with no type
SymTabMgr.C:89: invalid use of member `SymTabMgr::scopeList'
SymTabMgr.C:89: invalid use of member `SymTabMgr::sCount'
SymTabMgr.C:94: parse error before `if'
SymTabMgr.C:103: syntax error before `.' token
SymTabMgr.C:104: syntax error before `++' token
SymTabMgr.C:105: invalid use of member `SymTabMgr::sCount'
SymTabMgr.C:105: ISO C++ forbids declaration of `scopeList' with no type
SymTabMgr.C:105: `se' was not declared in this scope
SymTabMgr.C:105: assignment (not initialization) in declaration
SymTabMgr.C:106: parse error before `return'
SymTabMgr.C:110: syntax error before `(' token
SymTabMgr.C:114: invalid use of member `SymTabMgr::sCount'
SymTabMgr.C:114: ISO C++ forbids declaration of `scopeList' with no type
SymTabMgr.C:114: assignment (not initialization) in declaration
SymTabMgr.C:115: syntax error before `--' token
SymTabMgr.C:122: syntax error before `*' token
SymTabMgr.C:125: syntax error before `.' token

CODE:

#include "SymTabMgr.h"
#include "SymTabEntry.h"

SymTabMgr::SymTabMgr(size_t size)
{
mainStack = new SymTabStack(400);
tempStack = new SymTabStack(400);

sCount = 1;
SymTabEntry *entry = new SymTabEntry
"Global", GLOBAL, UNKNOWN_VISIB);
scopeList[sCount] = entry;
SymTab *table = new SymTab();
//SymTab *table = st;
mainStack->push(table);
}

SymTabMgr::SymTabEntry* lookUp(const string& name)
{
SymTab* table;
size_t x;
int i;
int pushCount = 0;
SymTabEntry* entry;
for(i = 1; i<= sCount; i++){
table = mainStack.pop();
tempStack.push(table);
pushCount++;
x = table->count(name);
if (x == 1){
entry = *table[name]; break;
}
for (i=1; i<=pushCount; i++){
table = tempStack.pop();
mainStack.push(table);
}
}
return entry;
}

SymTabMgr::SymTabEntry* lookUp(const string& name1,
const string& name2)
{
SymTabEntry * entry = new SymTabEntry();
//
// int i;
// entry = lookUp(name);
// //search for class name in the scopeNames array
// for( i = 0; i<= sCount; i++){
// if(strcmp(
//
return entry;
}

SymTabMgr::SymTabEntry* lookUp(const string& name1, const string& name2, const string& name3)
{
SymTabEntry * entry = new SymTabEntry();
return entry;
}


SymTabMgr::SymTabErr enter(SymTabEntry* se)
{
SymTab *table = mainStack.pop();
SymTabEntry *entry;
int x;
x = table->count(se->name);
if (x == 0){
*table[se->name] = se; //add se to the hash map
mainStack.push(table);
return SYMTAB_OK;
}
else{
entry = *table[se->name];
if(entry->kind() == se->kind()){
mainStack.push(table);
return DUPLICATE_SYM;
}else{
*table[se->name] = se;
mainStack.push(table);
return SYMTAB_OK;
}
}
}

SymTabMgr::SymTabErr enterScope(SymTabEntry* se)
{
SymTabEntry * currentScopeDef;
//get the current scope info from the scopeList
currentScopeDef = scopeList[sCount];

//really we have to examine the current scope and make sure that (a) you're not entering
//a class within a function or class (b) a pkg within a pkg/class/fun.

if( se->kind() != MEMBER_FUN )
if( se->kind() == currentScopeDef -> kind())
//this means we are enter a class(pkg) within a class(pkg)-->NOT OK
return INVALID_SCOPE;
//try to enter a package within a CLASS--> dont think this can happen in the first place
//if( se->kind() == PACKAGE && currentScopeDef->kind() == CLASS)
// return INVALID_SCOPE;

SymTab *newSymbolTable = new SymTab();
mainStack.push(newSymbolTable);
sCount++;
scopeList[sCount] = se;
return SYMTAB_OK;
}


SymTabMgr::SymTabErr leaveScope()
{
if(sCount >1){ //make sure we are not trying to leave the global scope
SymTab *removedTable = mainStack.pop();
scopeList[sCount] = "";
sCount--;
//delete *removedTable;
return SYMTAB_OK;
}else
return INVALID_SCOPE;
}

SymTabMgr::SymTabEntry* currentScope()
{
SymTabEntry *table = mainStack.pop();
mainStack.push(table);
return table;
}
 
Please use the [tt][ignore]
Code:
[/ignore][/tt]
tags when posting code.

> SymTabMgr::SymTabEntry* lookUp(const string& name)
This looks like a mangled attempt at both class names.
Post both your classes so we can see the member functions and the relationship between them

For example I think this may be
Code:
SymTabEntry* SymTabMgr::lookUp(const string& name)
    {
        SymTab* table;
        size_t x;
        int i;
        int pushCount = 0;
        SymTabEntry* entry;
        for(i = 1; i<= sCount; i++){
            table = mainStack.pop();
            tempStack.push(table);
            pushCount++;
            x = table->count(name);
            if (x == 1){
                entry = *table[name];                 break;
            }
            for (i=1; i<=pushCount; i++){
                table = tempStack.pop();
                mainStack.push(table);
            }
        }    
        return entry;
    }
It's return_type classname::memberfunctionname ( parameterlist );

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top