예제 #1
0
파일: LetNode.cs 프로젝트: maxblu/coolc
        //private Node s;

        public LetNode(CoolParser.LetExpContext context, Node s) : base(s.Childs)
        {
            this.context = context;
            IDs          = new List <IToken>();
            Types        = new List <IToken>();
            Exprs        = new List <CoolParser.ExpresionContext>();

            for (int i = 0; i < context.newvar().Length; i++)
            {
                IDs.Add(context.newvar()[i].id);
                Types.Add(context.newvar()[i].t);
                Exprs.Add(context.newvar()[i].e);
            }
            //IDs = new ITerminalNode[context];
            //Types = context.TYPE();
            //Exprs = context.expresion();
            Symbols = new Dictionary <string, ClassNode>();

            for (int i = 0; i < IDs.Count; i++)
            {
                var g = Types[i].Text;
                //SymbolTable.Classes[Types[i].GetText()] = new ClassNode(g, null);
                Symbols[IDs[i].Text] = SymbolTable.Classes[Types[i].Text];
                //SymbolTable.Symbols.Push(Symbols);
            }
        }
        public override object VisitLetExp([NotNull] CoolParser.LetExpContext context)
        {
            Coord c = GetCoord(context);

            List <Identifier> letInits = new List <Identifier>();

            //for (int i = 0; i < context.ID().Length; i++)
            //{
            //	Type idType = new Type(context.TYPE()[i].GetText(), null, null);
            //	if (p.Types.ContainsKey(context.TYPE()[i].GetText()))
            //	{
            //		idType = p.Types[context.TYPE()[i].GetText()];
            //	}
            //	Expression exp = null;
            //	if (i<context.ASSIGN().Length)
            //		 exp = (Expression)Visit(context.expresion()[i]);

            //	Identifier id = new Identifier(context.ID()[i].GetText(), exp, idType, new Coord(context.Depth(), context.getAltNumber()));
            //	letInits.Add(id);
            //	//Shady ...
            //	// ANTLR  stores in context the def in grammar for Let:
            //	//LET ID COLON TYPE(ASSIGN expresion)? (COMMA ID COLON TYPE(ASSIGN expresion) ? )*IN expresion			#letExp
            //	// as:
            //	// an array of IDs,array of COLON, array of ASSIGN, array of expressions
            //	// so im not sure if the lengths of these are equal since you theoretically can skip the assign part of any identifier and just declare it, so in that case i would not know if the ith assign correponds to the ith ID, is that so?, need to check
            //	//Console.WriteLine();
            //	//if(context.expresion[i])
            //}
            foreach (var x in context.newvar())
            {
                if (x.e != null)
                {
                    letInits.Add(new Identifier(x.id.Text, (Expression)Visit(x.e), new Type(x.t.Text, null, null), GetCoord(context)));
                }
                else
                {
                    letInits.Add(new Identifier(x.id.Text, null, new Type(x.t.Text, null, null), GetCoord(context)));
                }
            }
            var new_body = (Expression)Visit(context.body);

            //Expression body = (Expression)Visit(context.expresion()[0]);
            //context.

            return(new Let(letInits, new_body, GetCoord(context)));
        }
예제 #3
0
파일: TypeVisitor.cs 프로젝트: maxblu/coolc
        public override Node VisitLetExp([NotNull] CoolParser.LetExpContext context)
        {
            var s = VisitChildren(context);

            return(new LetNode(context, s));
        }
예제 #4
0
 public override object VisitLetExp([NotNull] CoolParser.LetExpContext context)
 {
     VisitExpr(context);
     return(VisitChildren(context));
 }
예제 #5
0
 /// <summary>
 /// Exit a parse tree produced by the <c>letExp</c>
 /// labeled alternative in <see cref="CoolParser.expresion"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitLetExp([NotNull] CoolParser.LetExpContext context)
 {
 }
 /// <summary>
 /// Visit a parse tree produced by the <c>letExp</c>
 /// labeled alternative in <see cref="CoolParser.expresion"/>.
 /// <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 VisitLetExp([NotNull] CoolParser.LetExpContext context)
 {
     return(VisitChildren(context));
 }
예제 #7
0
 public override bool VisitLetExp([NotNull] CoolParser.LetExpContext context)
 {
     return(VisitChildren(context));
 }