//--------------------------------------------------------------------- //subprogram_head->FUNCTION ID subprogram_parameters COLON standard_type SEMICOLON //1. Traverse the list of variable symbols to create list of parameters //2. Create a function symbol using the list of parameters created in step 1. //3. Insert the function symbol into the symbol table. //4. Create a new locality. //5. Insert the variable symbols into the symbol table. //--------------------------------------------------------------------- SubprogramSymbol* subprogram_head(string id,List<VariableSymbol*>* VL,Typ* RT) { Subprogram* PL=ParameterList(VL,RT); FunctionSymbol* F=new FunctionSymbol(id,PL,ST.LexicalLevel()); ST.Insert(F); ST.NewLocality(); InsertVariables(VL); return F; }
//--------------------------------------------------------------------- //subprogram_head->PROCEDURE ID subprogram_parameters SEMICOLON //1. Traverse the list of variable symbols to create list of parameters //2. Create a procedure symbol using the list of parameters created in step 1. //3. Insert the procedure symbol into the symbol table. //4. Create a new locality. //5. Insert the variable symbols into the symbol table. //--------------------------------------------------------------------- SubprogramSymbol* subprogram_head(string id,List<VariableSymbol*>* VL) { Subprogram* PL=ParameterList(VL,ST.TVoid()); ProcedureSymbol* P=new ProcedureSymbol(id,PL,ST.LexicalLevel()); ST.Insert(P); ST.NewLocality(); InsertVariables(VL); return P; }
//--------------------------------------------------------------------- //--------------------------------------------------------------------- SubprogramSymbol* program_head(string id) { List<VariableSymbol*>* VL=new List<VariableSymbol*>; Subprogram* PL=ParameterList(VL,ST.TVoid()); ProcedureSymbol* P=new ProcedureSymbol(id,PL,0); ST.Insert(P); ST.NewLocality(); return P; }