public override void InAFunctionFunctionDeclaration(AFunctionFunctionDeclaration node) { // Save current symbol table. _previousSymbolTables.AddFirst(_currentSymbolTable); // Build definitions for allowed types according to grammar. CS426 only allows int and string and float BasicTypeDefinition intType; intType = new BasicTypeDefinition(); intType.name = "int"; StringTypeDefinition stringType = new StringTypeDefinition(); stringType.name = "string"; BasicTypeDefinition floatType; floatType = new BasicTypeDefinition(); floatType.name = "float"; // Create and seed the symbol table. if (!_functionSymbolTable.ContainsKey("int")) { _functionSymbolTable.Add("int", intType); _functionSymbolTable.Add("string", stringType); _functionSymbolTable.Add("float", floatType); } }
public override void OutAFunctionFunctionDeclaration(AFunctionFunctionDeclaration node) { Definition def; String methodName = node.GetId().Text; // Ensure submethod name isn't used if (_functionSymbolTable.TryGetValue(methodName, out def)) { Console.WriteLine("[" + node.GetOpenpar().Line + "] : " + methodName + " is already declared."); // Build function definition and add to symbol table } else { def = new MethodDefinition(); def.name = node.GetId().Text; _functionSymbolTable.Add(methodName, def); } }