Exemple #1
0
        public override void Visit(ListDcl n)
        {
            string type = AST.LIST.ToString();

            type += n.listType is ListDcl?ListType(n.listType as ListDcl) : ListType(n.listType);

            if (!KeyValExists(n.id))
            {
                AST.SymbolTable.Add(GetKeyVal(n.id), int.Parse(type));
            }
            else
            {
                error("variable " + n.id + " is already declared");
            }
        }
Exemple #2
0
        public override void Visit(ListDcl n)
        {
            int depth = 0;
            AST sT    = n;

            while (sT is ListDcl)
            {
                depth++;
                ListDcl listDcl = sT as ListDcl;
                sT = listDcl.listType;
            }
            sT.accept(this);
            emit($"{n.id}");
            for (int i = 0; i < depth; i++)
            {
                emit("[]");
            }
        }
Exemple #3
0
        public void ListDclUnitTest()
        {
            try {
                ListDcl            listDcl            = new ListDcl("testList", new ListDcl(new StringDcl()));
                SymbolTableFilling symbolTableFilling = new SymbolTableFilling();
                listDcl.accept(symbolTableFilling);

                Dictionary <Tuple <string, string>, int> actual = AST.SymbolTable;

                Dictionary <Tuple <string, string>, int> expected =
                    new Dictionary <Tuple <string, string>, int>()
                {
                    { new Tuple <string, string>("1", "testList"), 664 }
                };

                Assert.IsTrue(ObjectCompare(actual, expected), "List Dcl faild");
            } finally {
                AST.SymbolTable.Clear();
            }
        }
Exemple #4
0
 private string ListType(ListDcl node)
 {
     return($"{GetType(node)}{GetType(node.listType)}");
 }
Exemple #5
0
 public override void Visit(ListDcl n)
 {
     n.type = AST.LIST;
     n.listType.accept(this);
 }
Exemple #6
0
 public override void Visit(ListDcl n)
 {
     n.listType.accept(this);
 }
Exemple #7
0
 public override void Visit(ListDcl n)
 {
     emit($"List<");
     n.listType.accept(this);
     emit($"> {n.id} ");
 }