Esempio n. 1
0
        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);
        }
 /// <summary>
 /// Visit a parse tree produced by <see cref="CoolParser.property"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitProperty([NotNull] CoolParser.PropertyContext context)
 {
     return(VisitChildren(context));
 }
Esempio n. 4
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="CoolParser.property"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitProperty([NotNull] CoolParser.PropertyContext context)
 {
 }