Hmm, I'm not sure if I explained myself correctly in this post which is why I'm getting zero response - let me try to explain a bit more clearly .

I've been referencing Anthony A. Aaby's book: Compiler Construction using Flex and Bison at the following link:

I am at the point in my compiler creation at which I need to modify my parser file (.y file) to both install and generate code/labels for the grammar (pg. 38 in Aaby's book) for the subset the Pascal language... but, I'm confused as to how to go about it. More specifically, I don't understand WHEN to "install" identifiers, generate code, or, as Aaby put it, "content_check" identifiers in the grammar. I tried starting on doing my calls to install and gen_code, but I doubt I'm doing it correctly...

Install, gen_code(), and context_check() are all methods described by Mr. Aaby which:
1. Place a symbol into the symbol table
2. Generate the code for a particular terminal symbol (I think!)
and
3. Check whether a particular symbol exists in the symbol table... (or something to that effect).

Here are the methods I've written (basically based off of Aaby's methods) to install, generate code, and check the context of symbols of the grammar:

Code: c
install( char *sym_name )
{
        symrec *s;
 
        s = lookup( sym_name );
        if(s == 0)
                s = insert(sym_name);
        else
        {
                errors++;
                printf( "%s is already defined\n", sym_name );
        }
}
 
context_check( enum code_ops operation, char *sym_name )
{
        symrec *identifier;
 
        identifier = lookup( sym_name );
 
        if( identifier == 0 )
        {
                errors++;
                printf( "%s", sym_name );
                printf( "%s\n", " is an undeclared identifier." );
        }
        else
                gen_code( operation, identifer->offset );
}
/* Generates code at the current offset */
void gen_code( enum code_ops operation, int arg )
{
        code[code_offset].op = operation;
        code[code_offset++].arg = arg;
}

Where insert and lookup() are methods in my symbol table header file that inserts a new symbol and looks up a symbol name in the symbol table (respectively).

Attached is my .y file and the grammar for the subset of Pascal that I'll be creating the compiler for.

Hopefully, I've explained myself well enough.

P.S I wasn't able to post the link to Aaby's book, but if you wish to view it simply search for: Compiler Construction using Flex/Bison
Attached Files
File Type: txt pascalScanner.txt (3.4 KB, 52 views)
File Type: txt pasclParser.txt (6.0 KB, 55 views)
File Type: txt symtab.txt (3.9 KB, 60 views)
File Type: txt stackmMachine.txt (4.3 KB, 52 views)
File Type: txt PascalGrammar.txt (2.3 KB, 53 views)