Meaning of insert() semantic function in attribute grammar

109 Views Asked by At

I am currently trying to draw the attribute flow for this attribute grammar.

decl → ID decl tail
 decl.t := decl tail.t  
 decl tail.in tab := insert (decl.in tab, ID.n, decl tail.t)  
 decl.out tab := decl tail.out tab  

decl tail → , decl
 decl tail.t := decl.t  
 decl.in tab := decl tail.in tab  
 decl tail.out tab := decl.out tab  

decl tail → : ID ;
 decl tail.t := ID.n  
 decl tail.out tab := decl tail.in tab  

But I do not understand what insert (decl.in tab, ID.n, decl tail.t) means.
My first assumption was it would be something similar to the insert() function in Python.
But as far as I know, Python's insert() takes two parameters, but in this attribute grammar it takes three parameters decl.in tab, ID.n, decl tail.t so my original assumption is clearly wrong here.
I am quite new to compiler designs and I have a hard time figuring out the meanings of some semantic functions I've never seen before. (e.g ReduceTo())

What does this insert (decl.in tab, ID.n, decl tail.t) mean?
Is there a list of semantic functions like this that I need to know or memorize?

1

There are 1 best solutions below

0
On

At a guess, the intent is to add the declared variable with the specified type into a symbol table ("tab").

For the purposes of analysing attribute flow, you don't really need to know what insert does, however. You only need to know that it requires certain values (its arguments), so those attributes must be available in order to compute the attribute assigned from the return value of the function.

There are no predefined semantic functions for attribute grammars, so you don't need to worry about memorizing a list of them. The particular semantic functions used in a particular attribute grammar application will be specified by that application itself.