コード例 #1
0
 public override void Visit(ListReferencing n)
 {
     n.id.accept(this);
     foreach (AST item in n.index)
     {
         item.accept(this);
     }
 }
コード例 #2
0
ファイル: TypeCheckerUnitTest.cs プロジェクト: mkju19/P4
        public void ListReferencingUnitTest()
        {
            try {
                ListReferencing listReferencing = new ListReferencing(new SymReferencing("testList"), new List <AST>()
                {
                    new Expression("-", new IntConst("1"), new IntConst("1")), new IntConst("1")
                });
                TypeChecker typeChecker = new TypeChecker();
                AST.SymbolTable =
                    new Dictionary <Tuple <string, string>, int>()
                {
                    { new Tuple <string, string>("1", "testList"), 664 }
                };
                listReferencing.accept(typeChecker);

                int actual   = listReferencing.type;
                int expected = AST.STRING;
                Assert.IsTrue(actual == expected, "DotReferencing faild");
            } finally {
                AST.SymbolTable.Clear();
            }
        }
コード例 #3
0
ファイル: TypeChecker.cs プロジェクト: mkju19/P4
        public override void Visit(ListReferencing n)
        {
            n.id.accept(this);
            int            inum = 0;
            string         type = n.id.type.ToString();
            SymReferencing sym  = n.id as SymReferencing;

            if (type.Length < n.index.Count)
            {
                Error($"too many index dereferences in {sym.id}");
            }
            foreach (AST item in n.index)
            {
                item.accept(this);
                if (item.type != AST.INTTYPE)
                {
                    Error($"{sym.id}'s {inum} index is not of type int");
                }
                inum++;
                type = type.Remove(0, 1);
            }
            n.type = int.Parse(type);
        }
コード例 #4
0
 public override void Visit(ListReferencing n)
 {
     //throw new NotImplementedException();
 }