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 handleUserDefinedTypeVariableReference(string variableName, object functionStackObject) { UserDefinedTypeVariableReference tempRef = (UserDefinedTypeVariableReference)functionStackObject; string objectName = tempRef.ObjectName; VariableNode objectVariable = new VariableNode(objectName); UserDefinedTypeVariableDeclNode parent = null; if (symbolTable.doesChildExistAtScope(objectVariable)) { Node localVar = symbolTable.getNode(objectVariable); if (localVar is VariableNode) { VariableNode localVariableNode = (VariableNode)localVar; if (localVariableNode.Parent is UserDefinedTypeVariableDeclNode) { parent = (UserDefinedTypeVariableDeclNode)localVariableNode.Parent; } } } if (parent == null) { throw new Exception(string.Format("The user defined variable {0} does not have an accessible parent", variableName)); } string className = parent.UserDefinedVariableTypeName; if (declaredClasses.ContainsKey(className)) { UserDefinedTypeNode userDefinedTypeNode = declaredClasses[className]; if (!userDefinedTypeNode.AllVariableNames.Contains(variableName)) { addError("the object [ " + className + "] does not have a varible [" + variableName + "] defined as part of its instance"); } VariableNode tempVariableNode = new VariableNode(variableName); if (!symbolTable.doesChildExistInHash(parent, tempVariableNode)) { symbolTable.addChild(tempVariableNode); } } }
/* * @Override * public Node visitLogicalOrExpression(JuliarParser.LogicalOrExpressionContext ctx) { * return super.visitLogicalOrExpression(ctx); * } */ public override Node visitUserDefinedTypeVariableDecl(JuliarParser.UserDefinedTypeVariableDeclContext ctx) { UserDefinedTypeVariableDeclNode node = new UserDefinedTypeVariableDeclNode(); return(iterateWithTryCatch(ctx, node)); }
public override Node visitVariable(JuliarParser.VariableContext ctx) { Node iteratorNode; try { string variableName = ""; if (ctx.ID() != null) { variableName = ctx.ID().Text; } VariableNode variableNode = new VariableNode(variableName); if (variableNode == null) { throw new Exception("unable to create a variable"); } object[] funcStackArray = funcContextStack.ToArray(); int length = funcStackArray.Length - 1; int index = length; for (; index >= 0; index--) { if (funcStackArray[index] is VariableDeclarationNode) { // We are creating the variable and adding it to the symbol table. // This will automatically throw an exception if creating a symbol with // same name at same scope. symbolTable.addChild(variableNode); break; } if (funcStackArray[index] is UserDefinedTypeNode) { Debug.Assert(true, "should not hit this"); // TODO // user defined variables will need to be looked up in the class / variable map. break; } if (funcStackArray[index] is UserDefinedTypeVariableDeclNode) { UserDefinedTypeVariableDeclNode temp = (UserDefinedTypeVariableDeclNode)funcStackArray[index]; variableNode.Parent = temp; if (!symbolTable.doesChildExistAtScope(variableNode)) { symbolTable.addChild(variableNode); } break; } if (funcStackArray[index] is UserDefinedTypeVariableReference) { handleUserDefinedTypeVariableReference(variableName, funcStackArray[index]); break; } if (!symbolTable.doesChildExistAtScope(variableNode)) { addError("The variable [" + variableName + "] is not declared at the scope"); } } iteratorNode = iterateWrapper(ctx, this, variableNode); } catch (Exception ex) { throw ex; } return(iteratorNode); }