ahpalmerUNR / c_compiler

c compiler for UNR Compilers CS 660
1 stars 0 forks source link

Symbol Table #3

Open ahpalmerUNR opened 5 years ago

natasha-audrey commented 5 years ago

Issues I notice so far in the table relate to inserting/looking up immediately when we see an identifier in the lexer.

Some code I am going to work on fixing (in order of priority):

int a;
int foo(int a) {
// Expected: shadow variable warning
// Actual: Conflicts with variable in current scope
// Notably the param is put in level 0 but it should be in level 1, and then push it into level 2
}
int foo();
int foo() {
}
struct s {
    int a;
} s; // states a redeclaration
int a[5] = {1,2,3,4,5}; // Technically no error, though we push and pop the table for no reason.
natasha-audrey commented 5 years ago

We are going to need to add functionality to our symbol table to distinguish between variables and functions. I am working on that right now.

ahpalmerUNR commented 5 years ago

We should also have some sort of ability to determine enum, typeDef, and struct, since these are treated slightly differently than normal variables.

natasha-audrey commented 5 years ago

I will be making the lexer make a node, which the parser inserts into the symbol table since it will be a lot easier to fix this way

natasha-audrey commented 5 years ago

Mostly finished the symbol table :smiley:

Still a couple of bugs with insertion (mostly with popping), but it is working a bit better now. Added

    // Vector containing the types of the node
    vector<nodeDataType> types;
    // Contains the params of node (if it is a function)
    vector<vector<nodeDataType>> params;

to keep check of parameters. Need to add some semantic checking if the parameters don't line up

natasha-audrey commented 5 years ago

Not touching the symbol table now to work more on AST nodes. It's mostly working (though there's still some stuff to work through with variables that are pretty important to fix) Edit: Jk I forgot \0 wasn't in yytext. Should be working now.

natasha-audrey commented 5 years ago

Per discussion: add a function to insert into symbol table at level 0. If global variable seen, add to global scope. (Optional) Static variables need to be global lifetime but function scope. Dot operators are something to consider later as we look forward.

natasha-audrey commented 5 years ago

I am going to move everything out of declaration and external_declaration into direct_declarator

natasha-audrey commented 5 years ago

Alright I have everything moved into direct declarator. Going to fix parameters tomorrow and then work on the different namespaces for the symbol table with ntype. Need to make it so we look up functions instead of blindly inserting as well.

ahpalmerUNR commented 5 years ago

dumping the symbol table doesn't work. Can you look at this. I am trying to figure out why a segfault is happening when we pop.

Andrew

On Mon, Nov 26, 2018 at 10:08 PM Nathan Yocum notifications@github.com wrote:

Alright I have everything moved into direct declarator. Going to fix parameters tomorrow and then work on the different namespaces for the symbol table with ntype. Need to make it so we look up functions instead of blindly inserting as well.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ahpalmerUNR/c_compiler/issues/3#issuecomment-441937009, or mute the thread https://github.com/notifications/unsubscribe-auth/AfkgwVy7OptitKVLuVKs8-4E5Ly7OLiKks5uzNbIgaJpZM4X9xSf .

ahpalmerUNR commented 5 years ago

fixed seg fault. Caused because the $3 and $4 weren't updated in last compound statement production.

natasha-audrey commented 5 years ago

Work needed:


AST Symbol Table: