/// <summary> /// Adds the current name-symbol pair to the corresponding dictionary. /// </summary> /// <param name="name">the symbol name</param> /// <param name="theSymbol">the symbol value</param> public void Add(string name, Symbol theSymbol) { switch (theSymbol.Category) { case symbolCategory.Cmethod: Symbol tempSymbol; if (!theMethodTable.TryGetValue(name, out tempSymbol)) theMethodTable.Add(name, theSymbol); else { MethodSymbol typedSymbol = tempSymbol as MethodSymbol; MethodSymbol parameteredSymbol = theSymbol as MethodSymbol; List<SymbolType> theParameteredList = parameteredSymbol.Parameters.ElementAt(0); if (!typedSymbol.checkParameterList(theParameteredList)) typedSymbol.addParameterList(theParameteredList); else throw new Exception("Redeclared identifier " + name + " on symbol declaration" + Environment.NewLine); } break; case symbolCategory.CstructDecl: theStructDeclTable.Add(name, theSymbol); break; default: theVariableTable.Add(name, theSymbol); break; } }
/// <summary> /// Adds a symbol to the current scope symbol table /// </summary> /// <param name="id">The new symbol id</param> /// <param name="x">The new symbol instance</param> public void AddSymbol(string id, Symbol x) { currentScope.Add(id, x); }
public override void ExitSingle_varDeclaration(DecafParser.Single_varDeclarationContext context) { SymbolType theType = getNodeType(context.varType()); Symbol theSymbolRepresentation; if (theType != SymbolType.TstructImpl) theSymbolRepresentation = new Symbol(theType); else theSymbolRepresentation = getNodeSymbol(context.varType()); theScopeManager.AddSymbol(context.Id().GetText(), theSymbolRepresentation); }
public void setNodeSymbol(IParseTree node, Symbol value) { nodeSymbols.Put(node, value); }
public override void ExitSingle_parameterDeclaration(DecafParser.Single_parameterDeclarationContext context) { SymbolType theParameterType = getNodeType(context.parameterType()); Symbol theSymbolRepresentation = new Symbol(theParameterType); KeyValuePair<string, Symbol> theKeyValuePairRepresentaion = new KeyValuePair<string, Symbol>(context.Id().GetText(), theSymbolRepresentation); theScopeManager.AddSymbol(theKeyValuePairRepresentaion); parameterList.Add(theParameterType); setNodeSymbolTableEntry(context, theKeyValuePairRepresentaion); setNodeType(context, theParameterType); }