Beispiel #1
0
        //private Node s;

        public CaseNode(CoolParser.CaseExpContext context, Node s) : base(s.Childs)
        {
            this.context = context;

            //this.s = s;
            this.Expresion  = context.expresion(0);
            this.IDs        = context.ID();
            this.Types      = context.TYPE();
            this.Expresions = context.expresion();
        }
        public override object VisitCaseExp([NotNull] CoolParser.CaseExpContext context)
        {
            Expression        mainExp = (Expression)Visit(context.expresion()[0]);
            List <Identifier> ids     = new List <Identifier>();

            for (int i = 0; i < context.ID().Length; i++)
            {
                Expression ithExp  = (Expression)Visit(context.expresion()[i]);
                Type       ithType = null;
                if (p.Types.ContainsKey(context.TYPE()[i].GetText()))
                {
                    ithType = p.Types[context.TYPE()[i].GetText()];
                }
                else
                {
                    ithType = new Type(context.TYPE()[i].GetText(), "Object", new Coord(-1, -1));
                }

                Identifier ithId = new Identifier(context.ID()[i].GetText(), ithExp, ithType, GetCoord(context));
                ids.Add(ithId);
            }

            return(new Case(mainExp, ids, GetCoord(context)));
        }