/// <summary> /// Checks the static semantic constraints of an AssignNode. /// </summary> /// <returns>An ISemanticCheckValue.</returns> /// <param name="node">Node.</param> public ISemanticCheckValue VisitAssignNode(AssignNode node) { // Check that the id property in this AssignNode is ok. IProperty property = getVariableProperty(node); // if the property was voidProperty, return at this point, // an error has been reported already if (property == voidProperty) { return(voidProperty); } VariableIdNode idNode = node.IDNode; // check that the id variable is declared checkPropertyDeclared(idNode, property, true); // check that the id property we should be assigning to is not constant // at this point of its lifecycle (i.e. not a current block's control variable) if (property.Constant) { analyzer.notifyError(new IllegalAssignmentError(node)); } // evaluate the type of this property IProperty evaluated = node.Accept(this.typeChecker).asProperty(); // check the type of the expression in the assign node matches the one in the symbol table if (!checkPropertyType(property, evaluated.GetTokenType())) { analyzer.notifyError(new IllegalTypeError(idNode)); } return(voidProperty); }
/// <summary> /// Visits the IO read node. /// </summary> /// <returns>An ISemanticCheckValue.</returns> /// <param name="node">Node.</param> public ISemanticCheckValue VisitIOReadNode(IOReadNode node) { // read an input string input = reader.readLine(); // select the first word of the input input = input.Split(new[] { ' ', '\t', '\n' })[0]; // set the input to the ioreadnode's assignment AssignNode assignNode = node.AssignNode; setAssignValue(input, assignNode); // execute the assign node assignNode.Accept(this); return(voidProperty); }