public virtual Node getNode(Node child) { Node returnNode = null; if (child is VariableNode) { Deque <string> tempScope = new ArrayDeque <string>(); tempScope.push(currentScope.pop()); while (!currentScope.Empty) { if (child is VariableNode) { SymbolTableNode node = scopeHash[currentScope.peek()]; //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: Optional <Node> nodeS = node.children.stream().filter(f => f is VariableNode).filter(f => ((VariableNode)f).variableName.Equals(((VariableNode)child).variableName)).findFirst(); returnNode = nodeS.orElse(null); } else if (child is UserDefinedTypeNode) { SymbolTableNode node = scopeHash[currentScope.peek()]; //JAVA TO C# CONVERTER TODO TASK: Java lambdas satisfy functional interfaces, while .NET lambdas satisfy delegates - change the appropriate interface to a delegate: Optional <Node> nodeS2 = node.children.stream().filter(f => f is UserDefinedTypeNode).filter(f => ((UserDefinedTypeNode)f).TypeName.Equals(((UserDefinedTypeNode)child).TypeName)).findFirst(); returnNode = nodeS2.orElse(null); } if (returnNode != null) { break; } while (!tempScope.Empty) { currentScope.push(tempScope.pop()); } } } if (returnNode == null) { throw new IllegalStateException("unable to find variable -" + ((VariableNode)child).variableName + "in scope for reassignment"); } return(returnNode); }
public virtual void addLevel(string level) { SymbolTableNode node = new SymbolTableNode(this); node.levelNode = level; if (scopeHash.ContainsKey(level)) { visitor.addError(string.format(IDENTIFIERTXT, level)); } else { currentScope.push(level); scopeHash[level] = node; } }
public virtual bool doesChildExistInHash(UserDefinedTypeVariableDeclNode parent, Node child) { SymbolTableNode t = scopeHash[parent.UserDefinedVariableTypeName]; if (t != null) { foreach (Node childNode in t.children) { if (((VariableNode)childNode).variableName.Equals(((VariableNode)child).variableName)) { return(true); } } } return(false); }
private void addChildVariable(VariableNode child) { SymbolTableNode node = scopeHash[currentScope.peek()]; int count = 0; foreach (Node childNode in node.children) { if (child.variableName.Equals(((VariableNode)childNode).variableName)) { count++; } } if (count > 0) { visitor.addError(string.format(IDENTIFIERTXT, child.variableName)); return; } scopeHash[currentScope.peek()].Children.Add(child); }