Exemple #1
0
        public override ASTNode VisitCase([NotNull] CoolParser.CaseContext context)
        {
            CaseNode node = new CaseNode(context)
            {
                ExpressionCase = Visit(context.expression(0)) as ExpressionNode
            };

            var formals     = context.formal().Select(x => Visit(x)).ToList();
            var expressions = context.expression().Skip(1).Select(x => Visit(x)).ToList();

            for (int i = 0; i < formals.Count; ++i)
            {
                node.Branches.Add((formals[i] as FormalNode, expressions[i] as ExpressionNode));
            }

            return(node);
        }
        public override ASTNode VisitCase([NotNull] CoolParser.CaseContext context)
        {
            var caseNode = new CaseNode(context.Start.Line, context.Start.Column)
            {
                Cases = new List <AttributeNode>()
            };

            caseNode.Sentence = Visit(context.expr(0)) as ExpressionNode;

            var formals = (from f in context.formal() select Visit(f) as FormalNode).ToList();
            var dexprs  = (from de in context.expr().Skip(1) select Visit(de) as ExpressionNode).ToList();

            for (int i = 0; i < formals.Count; i++)
            {
                caseNode.Cases.Add(
                    new AttributeNode(formals[i].Line, formals[i].Column)
                {
                    Formal = formals[i],
                    DessignateExpression = dexprs[i]
                });
            }

            return(caseNode);
        }
 /// <summary>
 /// Visit a parse tree produced by the <c>case</c>
 /// labeled alternative in <see cref="CoolParser.expr"/>.
 /// <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 VisitCase([NotNull] CoolParser.CaseContext context)
 {
     return(VisitChildren(context));
 }
Exemple #4
0
 /// <summary>
 /// Exit a parse tree produced by the <c>case</c>
 /// labeled alternative in <see cref="CoolParser.expr"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitCase([NotNull] CoolParser.CaseContext context)
 {
 }