// Assign
        public override ASTNode VisitAssignStmt(CLUBSParser.AssignStmtContext context)
        {
            AssignmentNode node = new AssignmentNode(new SourcePosition(context.start));

            node.Left  = Visit(context.left) as ExpressionNode;
            node.Right = Visit(context.right) as ExpressionNode;

            return(node);
        }
Example #2
0
        // Assignment
        public override TypeNode Visit(AssignmentNode node, object obj)
        {
            TypeNode leftType  = Visit(node.Left);
            TypeNode rightType = Visit(node.Right, leftType);

            // If left and right types are not the same, log error
            if (leftType != rightType)
            {
                ErrorLogger.LogError(new IncompatibleTypesError(leftType, rightType, node.Right.SourcePosition));
                return(new ErrorTypeNode(node.SourcePosition));
            }

            return(null);
        }
Example #3
0
 public abstract T Visit(AssignmentNode node, object obj);
Example #4
0
        // Assignment
        public override string Visit(AssignmentNode node, object obj)
        {
            IdentifiableNode id = node.Left as IdentifiableNode;

            return($"{Visit(node.Left, id.Id)} = {Visit(node.Right, id.Id)};\n");
        }