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"); } }
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("[]"); } }
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(); } }
private string ListType(ListDcl node) { return($"{GetType(node)}{GetType(node.listType)}"); }
public override void Visit(ListDcl n) { n.type = AST.LIST; n.listType.accept(this); }
public override void Visit(ListDcl n) { n.listType.accept(this); }
public override void Visit(ListDcl n) { emit($"List<"); n.listType.accept(this); emit($"> {n.id} "); }