public override ASTNode VisitProperty([NotNull] CoolParser.PropertyContext context) { AttributeNode node = new AttributeNode(context) { Formal = Visit(context.formal()) as FormalNode }; if (context.expression() != null) { node.AssignExp = Visit(context.expression()) as ExpressionNode; } else if (node.Formal.Type.Text == "Int") { node.AssignExp = new IntNode(context, "0"); } else if (node.Formal.Type.Text == "Bool") { node.AssignExp = new BoolNode(context, "false"); } else if (node.Formal.Type.Text == "String") { node.AssignExp = new StringNode(context, ""); } else { node.AssignExp = new VoidNode(node.Formal.Type.Text); } return(node); }
public override ASTNode VisitProperty([NotNull] CoolParser.PropertyContext context) { var attributeNode = new AttributeNode(context); attributeNode.Formal = Visit(context.formal()) as FormalNode; if (context.expr() != null) { attributeNode.DessignateExpression = Visit(context.expr()) as ExpressionNode; } else { if (attributeNode.Formal.Type.Text == "Int") { attributeNode.DessignateExpression = new IntegerNode(context.formal().Start.Line, context.formal().Start.Column) { Value = 0 } } ; else if (attributeNode.Formal.Type.Text == "Bool") { attributeNode.DessignateExpression = new BoolNode(context.formal().Start.Line, context.formal().Start.Column) { Value = false } } ; else if (attributeNode.Formal.Type.Text == "String") { attributeNode.DessignateExpression = new StringNode(context.formal().Start.Line, context.formal().Start.Column) { Value = "" } } ; else { attributeNode.DessignateExpression = new VoidNode(attributeNode.Formal.Type.Text); } } return(attributeNode); }